Asp.net 2, consuming XML (casting pain)


A

Andrew

I have a web method like this:

<WebMethod(Description:="Tester")> _
Public Function WTest(ByVal xTest As XmlDocument) As XmlDocument
Return "TEST"
End Function

And When I call the function from VB/ASP.Net 2 I receive the following error:

Unable to cast object of type 'System.Xml.XmlElement' to type
'System.Xml.XmlDocument'.

I call it like this:

Dim cX As New XmlDocument()
Dim cR As String
cR = "<some>xml</some>"
cR.LoadXml(c)
 
Ad

Advertisements

M

Martin Honnen

Andrew said:
I have a web method like this:

<WebMethod(Description:="Tester")> _
Public Function WTest(ByVal xTest As XmlDocument) As XmlDocument
Return "TEST"

That does not make sense to me, the return type you declare is
XmlDocument yet you return a String.
End Function

And When I call the function from VB/ASP.Net 2 I receive the following error:

Unable to cast object of type 'System.Xml.XmlElement' to type
'System.Xml.XmlDocument'.

I call it like this:

Dim cX As New XmlDocument()
Dim cR As String
cR = "<some>xml</some>"
cR.LoadXml(c)

That does not make any sense, 'cR' is declared as a String so why would
you call LoadXml on it? And what is 'c'?

As for the WebMethod, I think XmlElement is the only type you can safely
use as parameter or return type. Or the abstract XmlNode, but you will
get an XmlElement that way I think.
 
Ad

Advertisements

A

Andrew

Sorry I gave you the wrong code, that should have been as follows. No matter
the problem with that was that I had not hit the update web reference
button!!!

<WebMethod(Description:="Tester")> _
Public Function WTest(ByVal xTest As XmlDocument) As String
Return "TEST"
End Function


Noted - I will try returning XmlElements as apposed to XmlDocuments and see
how it works out?
 

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