Returning a XML from webservice

  • Thread starter Thread starter Ronchese
  • Start date Start date
R

Ronchese

Helllo.

I need to return a XML from my WebService, but I'm not getting the result as
a XML. I mean, instead of receiveing a tag (<xyy></xyz>), I'm receiving it
encoded (with &lt; or &gt;).

There is some right way to return the correct XML from my WebService?


Just for example, the WebMethod looks like it:

<WebMethod()> _
Public Function GetSomeXml(ID as Integer) As String
'the code builds a XML string from a Xml.XmlDocument object
'...
'...
End Function
 
Your actually returning a string - not XML, it will be encoded as a strings
are.

Try returning an XML document instead

[WebMethod]
public XmlDocument GetSomeXml(ID as Integer){
XmlDocument myDom = new XmlDocument();
// load some XML ...
return myDom;
}

Return this into an xmlNode and it wont be encoded and you can navigate it
with XPath and convert it to an unecoded string if you wish

localhost.Service1 proxy = new localhost.Service1();
XmlNode xml = proxy.GetSomeXml(22);

--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
http://www.johntimney.com/blog
 
Back
Top