DOCUMENT:Q307355 12-JUL-2002 [foxpro] TITLE :HOW TO: Call a Web Service in Visual FoxPro 7.0 PRODUCT :Microsoft FoxPro PROD/VER::7.0 OPER/SYS: KEYWORDS:kbInternet kbMiscTools kbvfp kbGrpDSFox kbDSupport kbvfp700 kbHOWTOmaster ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual FoxPro for Windows, version 7.0 ------------------------------------------------------------------------------- IN THIS TASK ------------ - SUMMARY - How to Call the AirportWeather Web Service - Find the AirportWeather Web Service - Call the AirportWeather Web Service - REFERENCES SUMMARY ======= This step-by-step article describes how to call the AirportWeather Web service by using Visual FoxPro 7.0. 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: Microsoft SOAP Toolkit http://msdn.microsoft.com/downloads/default.asp?URL=/code/sample.asp?url=/msdn-files/027/001/580/msdncompositedoc.xml 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. Find the AirportWeather Web Service: 1. Browse to the following Web site: XMethods.com http://xmethods.com/ 2. Scroll down to the AirportWeather service name (owned by Cape Clear). 3. Click the service name to browse to the following Web site: http://xmethods.com/detail.html?id=129 4. Click the WSDL URL, to see the formal definition of the Web service at the following Web site: http://www.capescience.com/webservices/airportweather/AirportWeather.wsdl For help with the other features of the service, see the following Web site: http://www.capescience.com/webservices/airportweather/index.html 5. Copy the WSDL URL onto the clipboard. Call the AirportWeather Web Service: 1. In Visual FoxPro 7.0, start the IntelliSense Manager from the Tools menu. 2. 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. 3. For Web Service Name, type "AirportWeather" (without the quotation marks). 4. 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). 5. Click Register, and the Web service information is saved in the IntelliSense FoxCode.dbf table. 6. Create a new program (for example, Aw.prg). 7. In the code window, type "LOCAL loAW AS AirportWeather" (without the quotation marks). Note that AirportWeather is included in the list of types that IntelliSense displays. 8. 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") 9. 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." (without the quotation marks), 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. 10. 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. REFERENCES ========== For additional information about Visual FoxPro and Web Services, see the "Walkthrough: Creating Web Services with Visual FoxPro" Visual FoxPro 7.0 white paper and the "Web Services Overview" topic in the Visual FoxPro 7.0 documentation. Additional query words: ====================================================================== Keywords : kbInternet kbMiscTools kbvfp kbGrpDSFox kbDSupport kbvfp700 kbHOWTOmaster Technology : kbVFPsearch kbAudDeveloper kbVFP700 Version : :7.0 Issue type : kbhowto ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 2002.