Help! My WebService method doen't return XmlDocument objects

V

Valmir

I've built a web service that has a method which should return XmlDocument
object's.

The problem is: in the client, inspecting the web service reference in
Object Browser, it always says that it returns an XmlNode.

The portion of the code where I try to assign the return call of this method
to an XmlDocument object gives me a message saying that is not possible to
convert to XmlNode from XmlDocument.

Am I forgetting something? Is there something I need to put in directives or
else instructing the client that a method will return an XmlDocument object?

The XmlDocument is created as following

[WebMethod]
public XmlDocument myMethod()
{
string buffer = "<root><blahblahblah></blahblahblah></root>"
xmlDocument objXmlDocument

objXmlDocument.LoadXml(buffer)

return objXmlDocument
}

Thanks in advance
 
C

Chris Botha

Valmir, very few system objects can be returned directly by Web Services
and an XmlDocument is not one of them.
What I did was to return a string, the InnerXml of the XmlDocument, and on
the client side construct a StringReader with the incoming string as value,
then construct an XmlDocument and call the Load of the XmlDocument with the
StringReader as parm, something like:
Dim sss As StringReader = New StringReader(IncomingText)
MyXmlDoc.Load(sss)
 
X

xiko tripa

Chris,

would you mind to inform me or give me some url or white paper about
which datatypes and objects a web service method can return?

thanks in advance

Valmir

Chris Botha said:
Valmir, very few system objects can be returned directly by Web Services
and an XmlDocument is not one of them.
What I did was to return a string, the InnerXml of the XmlDocument, and on
the client side construct a StringReader with the incoming string as value,
then construct an XmlDocument and call the Load of the XmlDocument with the
StringReader as parm, something like:
Dim sss As StringReader = New StringReader(IncomingText)
MyXmlDoc.Load(sss)

Valmir said:
I've built a web service that has a method which should return XmlDocument
object's.

The problem is: in the client, inspecting the web service reference in
Object Browser, it always says that it returns an XmlNode.

The portion of the code where I try to assign the return call of this method
to an XmlDocument object gives me a message saying that is not possible to
convert to XmlNode from XmlDocument.

Am I forgetting something? Is there something I need to put in directives or
else instructing the client that a method will return an XmlDocument object?

The XmlDocument is created as following

[WebMethod]
public XmlDocument myMethod()
{
string buffer = "<root><blahblahblah></blahblahblah></root>"
xmlDocument objXmlDocument

objXmlDocument.LoadXml(buffer)

return objXmlDocument
}

Thanks in advance
 
C

Chris

I don't know if this helps, but you may want to change the return type to
XmlNode; I have a very similar web service which works fine like this:

[WebMethod(Description="This web service will get the different categories
needed for an Advanced Search UI", EnableSession=false)]

public System.Xml.XmlNode wsGetAdvancedSearchUI()

{

System.Xml.XmlDocument XmlDoc = new System.Xml.XmlDocument();

//load dataset xml in to XmlDoc

XmlDoc.LoadXml(wsDBGetAdvancedSearchDataSet().GetXml());

return XmlDoc;

}


-Chris
 
B

BVM

It works to me, here is my codes:
===================================================
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();


// Add the root element

XmlElement root = doc.CreateElement( "Templates" );

doc.AppendChild( root );

root.SetAttribute("name", "Templates");

root.SetAttribute("path", "");

return doc;



Dennis
 

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

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top