Consuming Returned Data in a WindowsForm App from a web service

  • Thread starter Thread starter Wayne Taylor
  • Start date Start date
W

Wayne Taylor

Hi All,


I have a weather web service, if I do the following I get the data return OK
as XML...

Dim WeatherData As New weather.WeatherInfo.GlobalWeather


Debug.WriteLine(WeatherData.GetCitiesByCountry("United Kingdom"))

What I don't understand is how to consume/read the data. I presume you have
to use XML classes, however my experience using xml is next to none.

The example code I have seen put's the data return into a DataSet, but this
won't work due to the fact the GetCitiesByCountry returns as a string......

Can any one point me in the correct direction?

Thanks in advance and I hope this is the correct NG.....

Wayne Taylor.
www.kryptos.co.uk/blog
 
Hi Wayne,

If you get xml string from this webservice method, you can still use that xml
string to create a Dataset.
Please review the article below for a sample.

309702 HOW TO: Read XML Data into a DataSet by Using Visual Basic .NET
http://support.microsoft.com/?id=309702

If it is not an xml string and it is a concatenated string with some separator
character, you can split the string in an array.

Dim s1 As String
s1 = "Chicago,Dallas,New York"
Dim cities() As String
cities = s1.Split(",")
Debug.WriteLine("First city: " & cities(0))


Hope this helps!
Bharat Patel
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
Thanks for the reply.

Ok, I've looked at the kb article you suggested, and it seems to get it's
XML file a XML file...

It's seems a bit odd to me that I have to take the XML string returned from
the WebService and write it out to file and then read it back in.

I have tried using the sytax as suggested in the article but it won't let me
pass the string into a dataset....

Thanks,

Wayne
 
Hi Wayne,

You can create StringReader and use it to create a dataset directly.

Dim xmlData As String
xmlData = MyWebservice.GetData()
Try
Dim xmlSR As System.IO.StringReader = New
System.IO.StringReader(xmlData)
ds.ReadXml(xmlSR)
Catch ex Exception
'handle exception
End Try

Review the following MSDN site for more details. This is actually referenced in
the article I gave you earlier.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cp
conloadingdatasetfromxml.asp


Hope this helps!
Bharat Patel
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
Thanks! Bharat...

It worked, I knew it would be simply, I just had a mental block on this one.
The learning Curve is so steep for VB.NET and I'm playing around in diffient
areas, which I think is just confusing me.....

I think I need to bit of small chunks and get my head around them...

Thanks.
 
Hi Wayne,

I am glad that you got it.

Check out the link below for some HowTo type questions:
http://samples.gotdotnet.com/quickstart/howto/


Hope this helps!
Bharat Patel
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
Back
Top