Take a look at WSCF -
http://www.thinktecture.com/Resources/Software/WSContractFirst/default.html.
I believe it's exactly what you are looking for.  It will take your XSDs,
convert them into classes, create the desired Request/Response, etc.

Cristian Sturek
Principal SOA Architect
http://www.xwebservices.com
http://www.soahub.com

-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Ben Joyce
Sent: Tuesday, October 10, 2006 4:15 AM
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: SPAM-LOW: [ADVANCED-DOTNET] Web services, DataSets and making use
of XSDs...

Hi all.

I'm just getting in to some XSD programming and could do with some
advice.  This is quite a lengthy email for which I apologise in
advance.

I've been asked to create a webservice with some methods, one of which
is to resturn some customer data.

I am at the point where I would usually return my data like this:

dstDataset.Tables(0).WriteXml(Response.OutputStream)

Then the calling code would pick apart the response.

However, I am now required to send a response something like this...
which i believe is based on an XSD:

<?xml version="1.0" encoding="ISO-8859-1"?>
<CustomerFindResponse
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:noNamespaceSchemaLocation="FindCustomer_response_OK.xsd">
        <Return>true</Return>
        <CustomerList>
                <Customer>
                        <Dealer></Dealer>
                        <TitleCode>5</TitleCode>
                        <Initials>A</Initials>
                        <CustomerNo>0</CustomerNo>
                        <Customertype>P</Customertype>
                        <Foren>ANDREW JAMES</Foren>
                        <Surn>PALMER</Surn>
                        <Company></Company>
                        <AddLine1></AddLine1>
                        <AddLine2>HASLINGTON</AddLine2>
                        <AddLine3></AddLine3>
                        <AddPosttown>Crewe</AddPosttown>
                        <PostCode></PostCode>
                        <HouseNumber>35</HouseNumber>
                </Customer>
                <Customer>
                        <Dealer></Dealer>
                        <TitleCode>3</TitleCode>
                        <Initials>A</Initials>
                        <CustomerNo>0</CustomerNo>
                        <Customertype>P</Customertype>
                        <Foren>ANDREW JAMES</Foren>
                        <Surn>PALMER</Surn>
                        <Company></Company>
                        <AddLine1></AddLine1>
                        <AddLine2>HASLINGTON</AddLine2>
                        <AddLine3></AddLine3>
                        <AddPosttown>Crewe</AddPosttown>
                        <PostCode></PostCode>
                        <HouseNumber>35</HouseNumber>
                </Customer>
        </CustomerList>
</CustomerFindResponse>

And the accompanying XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
elementFormDefault="qualified">
  <xs:element name="CustomerFindResponse">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="Return"/>
        <xs:element ref="CustomerList"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="Return" type="xs:boolean"/>
  <xs:element name="CustomerList">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" ref="Customer"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="Customer">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="Dealer"/>
        <xs:element ref="TitleCode"/>
        <xs:element ref="Initials"/>
        <xs:element ref="CustomerNo"/>
        <xs:element ref="Customertype"/>
        <xs:element ref="Foren"/>
        <xs:element ref="Surn"/>
        <xs:element ref="Company"/>
        <xs:element ref="AddLine1"/>
        <xs:element ref="AddLine2"/>
        <xs:element ref="AddLine3"/>
        <xs:element ref="AddPosttown"/>
        <xs:element ref="PostCode"/>
        <xs:element ref="HouseNumber"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="Dealer" type="xs:integer"/>
  <xs:element name="TitleCode" type="xs:integer"/>
  <xs:element name="Initials" type="xs:string"/>
  <xs:element name="CustomerNo" type="xs:integer"/>
  <xs:element name="Customertype" type="xs:string"/>
  <xs:element name="Foren" type="xs:string"/>
  <xs:element name="Surn" type="xs:string"/>
  <xs:element name="Company" type="xs:string"/>
  <xs:element name="AddLine1" type="xs:string"/>
  <xs:element name="AddLine2" type="xs:string"/>
  <xs:element name="AddLine3" type="xs:string"/>
  <xs:element name="AddPosttown" type="xs:string"/>
  <xs:element name="PostCode" type="xs:string"/>
  <xs:element name="HouseNumber" type="xs:string"/>
</xs:schema>

My question is this: how do I use the XSD file in my code to create an
XML document based on the schema?  I believe once i have created such
an entity i could manually walk the dataset and create new XML nodes.
Is this the right way to do it?  Am I even on the right track?

My cheap and nasty alternative is to return the data like this:

strXML = "<CustomerFindResponse
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"";
xsi:noNamespaceSchemaLocation=""FindCustomer_response_OK.xsd"">"
strXML += "<Return>true</Return>"
dstDataset.Tables(0).TableName = "Customer"
Dim strData As String = dstDataset.GetXml()
strXML += strData
strXML += "</CustomerFindResponse>"

Return strXML

But this involves a degree of hard-coding and whatsmore the returned
XML is escaped (the < and > appear as &lt; and &gt; respectively)

sigh - it's a bit of a nightmare!

Any ideas or advice would really be appreciated.

Cheers,

Ben

===================================
This list is hosted by DevelopMentorR  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to