A1VBCode Forums

Problem using returned data from web service


http://www.a1vbcode.com/vbforums/Topic27030.aspx

By adept710 - 2/16/2009

Hello Everyone,

 

I am having problems with my VB 2008 Express project. Here is a quick outline of what I have done.

 

Used WSDL Tool to create a file named “Racing.vb”.

I then added this file to my project by using Project>Add Existing Item.

This added a file to my Solution Explorer Window named “Racing.vb”

I then searched the new file to find the method I would use to send a web request. This method is copied straight from the Racing.vb file:

 

'''<remarks/>

    <System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://direct.tab.com.au/LiveOdds/MeetingSummary", RequestNamespace:="http://direct.tab.com.au/LiveOdds/", ResponseNamespace:="http://direct.tab.com.au/LiveOdds/", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)>  _

Public Function MeetingSummary(ByVal Key As String, ByVal Jurisdiction As String, ByVal [Date] As String, ByVal TypeCode As String) As System.Xml.XmlElement

        Dim results() As Object = Me.Invoke("MeetingSummary", New Object() {Key, Jurisdiction, [Date], TypeCode})

        Return CType(results(0),System.Xml.XmlElement)

End Function

 

 

          From this I wrote the following code as the request for the web service:

 

 

Dim objMSInfo As New Racing()

Dim MSResult As String

 

MSResult = objMSInfo.MeetingSummary(myKey, strJ, strRD, strTC)

 

 

          As soon as I had finished typing the last line of this code, I got the error message in the Error Box, saying:

 

 

Value of type 'System.Xml.XmlElement' cannot be converted to 'String'.

 

So figuring that the returned values could not be declared as a String, I decided to change my code a little and see if I could return it as an Xml Document, so I changed my code to the following:

 

Dim objMSInfo As New Racing()

Dim MSResult As New XDocument

 

MSResult = objMSInfo.MeetingSummary(myKey, strJ, strRD, strTC)

 

 

          This brings back the same error message, only this time saying:

 

 

Value of type ‘System.Xml.XmlElement’ cannot be converted to ‘XDocument’

 

 

So I am now resigned to asking for the help of someone who has been through this and can see where I am going wrong. I am migrating up from VB4, which I learnt a few years ago now, to VB.Net using the 2008 Express edition, and so I am a bit lost with this Xml Stuff.

 

Oh and for clarification, this is the structure of the data that should be coming back from the MeetingSummary request:

 

 

- <Meetings Jurisdiction="NSW">

- <Summary MID="SR_20040705">

<VenueName>COFFS HARBOUR (NSW)</VenueName>

<Type>R</Type>

<Events>12</Events>

<track>GOOD</track>

<weather>FINE</weather>

             - <Races>

- <Race RID="SR_20040705_01">

<Name>MARES SC PLTE</Name>

<Distance>1200M</Distance>

<Class/>

<RunnerNo Acceptors="14">12</RunnerNo>

<JumpTime>16:52</JumpTime>

<TimeToJump>+03:01:00</TimeToJump>

<RaceStatus>Betting Open</RaceStatus>

</Race>

+ <Race RID=" SR_20040705_2">

+ <Race RID=" SR_20040705_3">

+ <Race RID=" SR_20040705_4">

+ <Race RID=" SR_20040705_5">

+ <Race RID=" SR_20040705_6">

+ <Race RID=" SR_20040705_7">

+ <Race RID=" SR_20040705_8">

+ <Race RID=" SR_20040705_9">

</Races>

</Summary>

+ <Summary MID="MR_20040705">

+ <Summary MID="MH_20040705">

+ <Summary MID="SH_20040705">

+ <Summary MID="BH_20040705">

+ <Summary MID="SG_20040705">

+ <Summary MID="PG_20040705">

+ <Summary MID="MG_20040705">

</Meetings>

 

          Can anyone shed some light on how I can display this information in my program. I intend to declare each element as a variable so that I can display them in a particular way. I can also paste the entire Racing.vb file if needed, however it is a really big file and so for now to save space I will not include it unless needed.

 

          Thanx in advance to anyone who can help guide me with this problem.
By adept710 - 2/17/2009

Hi everyone,

I am stuck again after using the above code to clear the error in my error box, I then ran the project to see that it was producing the right results.

I modified the earlier code again by adding the following line:

    Dim objMSInfo As New Racing()

    Dim MSResult As String

 

    MSResult = objMSInfo.MeetingSummary(myKey, strJ, strRD, strTC).ToString

 

and then I added this following line:

 

    OutputTextBox.Text = MSResult

 

 

Now I am getting text displayed in the textbox, except instead of the text showing the structure of the results above in one string, it simply returns the following in the text box:

 

    "System.Xml.XmlElement"

 

Can anyone shed any light on why it is returning this result and not the structure as outlined in the original post? And also how I should approach this problem?

 

Cheers and Thanx in Advance.