consuming web service


B

Brock

I have a classic textbook example of consuming a Web service. I'm
using Visual Web Developer Express 2008 v9. I have a textbox, a
listbox, and a button on my .aspx form. I'm trying to use the
http://developer.capeclear.com/files/GlobalWeather.wsdl as my Web
reference which looks good so far. But my code has some what will
assurably be obvious flaws to many. You can see the WSDL at the above
link. The method in that I am trying to use is "searchByCode"... so I
would of course enter an airport code like "LAX" and get weather for
Los Angeles. The following code needs some help. the compiler doesn't
like the item "textCode" below and it's saying that all the "ws." 's
are not declared. Anyone? THANKS!!

<script runat="server">


Private Sub btnGetSummary_Click(ByVal sender As Object, ByVal e
As
System.EventArgs) Handles btnGetSummary.Click
Dim aw As com.capeclear.developer.WeatherReport = New
com.capeclear.developer.WeatherReport()
Dim ws As
com.capeclear.developer.getWeatherReport(txtCode.Text)
With lbResults.Items
.Clear()
.Add("Visibility: " & ws.visibility)
.Add("Temperature: " & ws.temperature)
.Add("Winds: " & ws.winds)
.Add("Precipitation: " & ws.precipitation)
.Add("Sky: " & ws.sky)
.Add("Pressure: " & ws.pressure)
End With
End Sub


</script>
 
Ad

Advertisements

C

Cowboy \(Gregory A. Beamer\)

First off, I cringe a bit when I see someone embedding code in the page. The
two file model (.aspx and .aspx.language (in this case .aspx.vb)) is so much
cleaner. It requires a paradigm shift from interpretted models, like
traditional ASP, but once you make the shift it is SO worth it.

I am also not as fond of VB, but that one is just a personal preference. :)

Next, I am not finding the service is up and running properly, but I will
show you how services like this are set up, based on the WSDL. Code could be
the airport. It could also be airport = 'LAX' etc. You need to consult their
documentation. When I searched the site, they had a new link to the service,
but it was down.

Dim service As New WeatherService.GlobalWeatherBinding()
Dim params As New WeatherService.getWeatherReport()
params.code = "{not sure what this is}"

Dim response As WeatherService.getWeatherReportResponse
response = service.getWeatherReport(params)

Dim ws As WeatherService.WeatherReport = response.return


That gives you ws to pull from. Now, your Add is all messed up. I would use
String.Format() instead, like so:

With WeatherListBox.Items
.Clear()
.Add(String.Format("Visibility: {0}", ws.visibility))
.Add(String.Format("Temperature: {0}", ws.temperature))
.Add(String.Format("Winds: {0}", ws.wind))
.Add(String.Format("Precipitation: {0}", ws.precipitation))
.Add(String.Format("Sky: {0}", ws.sky))
.Add(String.Format("Pressure: {0}", ws.pressure))
End With

Finally, it is wind, not winds.

As I said, the above code has some issues in it, in the code = "" section.
As I see no help file, and this is not my game, I cannot figure out what to
put here.

If you are just learning, this service might be better to play with.
http://www.webservicex.net/globalweather.asmx

It is built more like .NET (as it is in .NET), so it is easier to get the
hang of:
Dim service As New WeatherService.GlobalWeather()
Dim weather As String = service.GetWeather("Los Angeles", "US")

WeatherLabel.Text = weather

It does not give as many features.

There is another at:
http://www.deeptraining.com/webservices/weather.asmx

Roughly the same setup, and this one is returning something
Dim service As New Weather2.Weather
Dim weather As String = service.GetWeather("LAX")

WeatherLabel.Text = weather
 

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