how to return xml document from a web service

R

R.A.

Hi,

I have an web service method that accept an xml document and returns a
different xml document.

Based on the input xml I fill a dataset with information from a database.
If the dataset has rows then I need to return those rows to the consumer.
I can't tell if the consumer of the web service will use .Net or maybe java.
1) If the web service method returns a Dataset then the consumer will get
information on the Dataset. What if the consumer has no knowledge what a
Dataset is at all (for example jave)? I know that the datase is returned in
xml represantation - but how will the consumer deal with the data to extract
the rows returned by the dataset?
2) For resone explained in section 1, I chose to return an xml document.
When I use the dataset.writexml (...) it writes only thetables rows
information and doesn't write the xml header. Am I to use XmlDocument to
construct the xml and write to it the datase and then send it as a string
back to the consumer? How can I tell the consumer where is the xsd for this
xml document?
3) How do I pass an XmlDocument to a web service method?

Which of the following will best fit the web service consumer?

XmlDocument webservice method (XmlDocument my xml)
XmlDocument webservice method (string my xml)
Dataset webservice method (Dataset my xml)
Dataset webservice method (string my xml)
string webservice method (XmlDocument my xml)
string webservice method (string my xml)


Thanks
 
D

Dan Bass

From my brief experience with Web Services I'd use:


[WebMethod]
public string MyMethod ( string xmlString )
{
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.LoadXml( xmlString );
}
catch ( Exception ex )
{
// return error here in XML?
}

//
//
// do your XML'ly things here
//
//

return xmlDoc.OuterXml;
}


Be aware though that this will HtmlEncode your string because you're passing
it out in SOAP Xml so ensure the clients have a way of knowing to decode it
back.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top