how to return xml document from a web service

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • R.A.

    how to return xml document from a web service

    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.writexm l (...) 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



  • Dan  Bass

    #2
    Re: how to return xml document from a web service

    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.


    "R.A." <temp@hotmail.c om> wrote in message
    news:uutjofj0EH A.1400@TK2MSFTN GP11.phx.gbl...[color=blue]
    > 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.writexm l (...) 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
    >
    >
    >[/color]


    Comment

    Working...