XmlDocument Web method returns type XmlNode

J

John Bailo

I developed a web method that returns type XmlDocument.

But a client calling the web method will only accept the return value as
datatype XmlNode.

Why?
 
J

James Flynn

Could be that the client doesn't want the entire xmlDocument.
Change the return type to xmlNode

Then, take your existing xmlDocument and add the following to be returned:
xmlDocument.SelectSingleNode(XPath Expression Goes Here)
 
J

John Bailo

James said:
Could be that the client doesn't want the entire xmlDocument.
Change the return type to xmlNode

Then, take your existing xmlDocument and add the following to be returned:
xmlDocument.SelectSingleNode(XPath Expression Goes Here)

Yes, I can read it via workarounds.

It just disturbs me that an explicitly typed complex return type
XmlDocument is translated to a completely different type when creating
the web reference in the client (!)
 
D

Dan Rogers

Hi John,

In general, if you really want to return raw XML to the client, as opposed
to normal classes or .NET based native data types, try and use XmlNode as
the return type when coding an ASP.NET webMethod. The reason is that the
return data comes from the first element child from the SOAP:Body element -
and thus won't be a complete document. If you really want to make a pure
XML document based interface, use simple ASP and the DOM, instead of
ASP.Net. This is the case when you want to include processing instructions
that point to XSLT, etc). Otherwise, if you are simply on the
green-diamond slopes and wanting to return plain old XML, just use XmlNode
instead of the DOM. You can still use the DOM to build your response, and
then peel off the node you want to return (you can only return one!).

Hope this helps,

Dan Rogers
Microsoft Corporation

--------------------
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top