Hi Paul. Thanks for your reply. I've looked at the XSD tool, looks handy... but I don't see any obvious way of populating my CustomerList with Customers - is this the part which I write or am I missing something?
I shall continue tinkering :) Cheers, Ben On 10/10/06, Paul van Brenk <[EMAIL PROTECTED]> wrote:
You don't want to return datasets/datatables from webservices ever. (Lot of good resources available why not.) You can use the xsd.exe command line tool to generate a .cs (or .vb) file containing the custom class as specified by the xsd and return that from your webmethod. The .Net framework will handle the conversion to and from xml for that class. Paul -----Original Message----- From: Discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Ben Joyce Sent: Tuesday, October 10, 2006 13:15 To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM Subject: [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 < and > respectively) sigh - it's a bit of a nightmare! Any ideas or advice would really be appreciated. Cheers, Ben =================================== This list is hosted by DevelopMentor(r) http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentor(r) 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