SUMMARY
This step-by-step article describes how to call the AirportWeather Web service by using Visual FoxPro 7.0.
back to the top
How to Call the AirportWeather Web Service
Visual FoxPro 7.0 contains several features that make working with Web services easier, including IntelliSense and a FoxPro Foundation Class to simplify working with the SOAP toolkit.
AirportWeather is a service that looks up the current weather at any NOAA airport observation post. This code sample displays a message box with the current weather conditions at Seattle-Tacoma International Airport.
NOTE: To call Web services in Visual FoxPro 7.0, you must have the Microsoft SOAP Toolkit version 2.0 installed. You can install the SOAP Toolkit from the Visual FoxPro 7.0 installation CD or by downloading it from the following Microsoft Developer Network (MSDN) Web site:
The client parts of the SOAP Toolkit come preinstalled on Microsoft Windows XP, so you don't need a separate download.
If you are behind a firewall, you may have problems running this code.
back to the top
Find the AirportWeather Web Service
- Browse to the following Web site:
- Scroll down to the AirportWeather service name (owned by Cape Clear).
- Click the service name to browse to the following Web site:
- Click the WSDL URL, to see the formal definition of the Web service at the following Web site:
For help with the other features of the service, see the following Web site:
- Copy the WSDL URL onto the clipboard.
back to the top
Call the AirportWeather Web Service
- In Visual FoxPro 7.0, start the IntelliSense Manager from the Tools menu.
- On the Types tab, click Web Services. Note that you receive an error message if you do not have SOAP version 2.0 or later installed. You also receive a warning if you do not have Microsoft Internet Information Server (IIS) installed, but you can continue.
- For Web Service Name, type AirportWeather.
- For WDSL URL Location, paste the WSDL URL that you copied in step 5 of the previous section (http://www.capescience.com/webservices/airportweather/AirportWeather.wsdl).
- Click Register, and the Web service information is saved in the IntelliSense FoxCode.dbf table.
- Create a new program (for example, Aw.prg).
- In the code window, type LOCAL loAW AS AirportWeather. Note that AirportWeather is included in the list of types that IntelliSense displays.
- Press ENTER. IntelliSense fills in the following code:
LOCAL loWS
loWS = NEWOBJECT("Wsclient",HOME()+"ffc\_webservices.vcx")
loWS.cWSName = "AirportWeather"
loAw = loWS.SetupClient("http://live.capescience.com/wsdl/AirportWeather.wsdl", "AirportWeather", "Station")
- Paste the following code at the end of the program:
LOCAL loAW as AirportWeather
LOCAL loWS
loWS = NEWOBJECT("Wsclient",HOME()+"ffc\_webservices.vcx")
loWS.cWSName = "AirportWeather"
loAW = loWS.SetupClient("http://live.capescience.com/wsdl/AirportWeather.wsdl", "AirportWeather", "Station")
loAW.ConnectorProperty("Timeout") = 60 * 1000 && milliseconds
LOCAL loSummary, lcMessage
loSummary = loAW.getSummary("KSEA")
WITH loSummary
TEXT TO lcMessage NOSHOW
Location: <<.Item(1).Text>>
Wind: <<.Item(2).Text>>
Sky Conditions: <<.Item(3).Text>>
Temperature: <<.Item(4).Text>>
Humidity: <<.Item(5).Text>>
Barometer: <<.Item(6).Text>>
Visibility: <<.Item(7).Text>>
ENDTEXT
MESSAGEBOX(TEXTMERGE(lcMessage), "KSEA Weather Conditions")
ENDWITH
Note that after you type loAW., IntelliSense displays the various methods of the Web service. After you select getSummary, IntelliSense displays a tooltip with its parameters and return value. Note that it returns a value of type WeatherSummary:. This is a complex type that is parsed into a COM object with the SOAP Toolkit.
The AirportWeather service has other methods that return simple strings, which can be displayed normally.
- Run the program.
The third-party products that are discussed in this article are manufactured by companies that are independent of Microsoft. Microsoft makes no warranty, implied or otherwise, regarding the performance or reliability of these products.
In particular, we cannot guarantee that this Web service will be available when you read this article. The principles in the article will apply to any Web service, so if necessary, choose another one to test against, and modify the display code accordingly.
back to the top