Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Asp.net 2, consuming XML (casting pain)

Reply
Thread Tools

Asp.net 2, consuming XML (casting pain)

 
 
Andrew
Guest
Posts: n/a
 
      03-09-2009
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)

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      03-10-2009
Andrew wrote:
> 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.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Andrew
Guest
Posts: n/a
 
      03-11-2009
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?

"Martin Honnen" wrote:

> Andrew wrote:
> > 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.
>
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Consuming NOAA XML web service xml .NET group ASP .Net 2 04-13-2007 08:46 PM
Consuming XML Web Service =?Utf-8?B?UGV0ZXI=?= ASP .Net 3 03-08-2005 02:06 PM
MCSD 70-310 Creating and Consuming XML Web Services Exam Question Greg MCSD 1 07-17-2004 02:32 PM
Consuming XML Web Services from ASP.NET Tomas Deml ASP .Net 0 11-10-2003 05:56 PM
Creating and Consuming XML configuration Christopher Ambler ASP .Net 2 08-27-2003 04:06 PM



Advertisments