Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to consume a web service in VFP

Internet

How to consume a web service in VFP

by  Mike Gagnon  Posted    (Edited  )
Note: This requires VFP7.0 minimum and SOAP tool kit version 2.0 minimum.
[ignore]"http://www.microsoft.com/downloads/details.aspx?FamilyId=147ED727-0BE8-48A1-B1DA-D50B1EA582CB&displaylang=en"[/ignore]

In order to consume a Web service, you first need an actual web service. This following example assumes you have a web service. (This FAQ is based on a web service in Visual Studio .NET and it works like a DLL where there is no interface). All it does it takes two paramaters, one being a postal code (like a zip code in the US) and the second paramter is a delimeter, in order to be able to parse the answer. In Canada we have a web site run by the Federal government, that if you type-in the postal code, it will return the range of possible addresses, the street name, the city, province. We use this as a validation for our customer service agent to "verify the customer's authenticity". So we wrote a webservice that "sends" postal codes to this site and retrieves the requested information.

[ol][li] Once you have the path as to where the asmx file and the wsdl file (the actual web service files themselves), (the path has to be on a web server, not a regular server)you need to register it with VFP, in order to use it in an application. To register a web service, you go to tools->Intellisense Manager->Type->Webservices. The prompt will ask you for two values (ie. the name of the service, as in the code below the name is pcode2address, the actual web URL address, as in below [ignore]"http://intranet/stgwebservices/pcode2address.asmx?wsdl"[/ignore], that points to the asmx and wsdl files.[/li]
[li]Once register, now you can used (in a similar fashion as a class or a DLL). But once registered Intellisense will actually produce the code for you to use to call the webservice. All you need to do is either create a program, or a function and type :
LOCAL ow as
After you hit the space bar after the 'as' intellisense kicks-in and show you the "class and services available". You select your services and VFP produces the rest of the code, like magic:
Code:
LOCAL loWS
loWS = NEWOBJECT("Wsclient",HOME()+"ffc\_webservices.vcx")
loWS.cWSName = "pcode2address"
ow = loWS.SetupClient("http://intranet/stgwebservices/pcode2address.asmx?wsdl", "PCode2Address", "PCode2AddressSoap")
[/li][/ol]
So the complete code that I use to retrieve the information is:

Code:
LOCAL ow as pcode2address
LOCAL loWS
loWS = NEWOBJECT("Wsclient",HOME()+"ffc\_webservices.vcx")
loWS.cWSName = "pcode2address"
ow = loWS.SetupClient("http://intranet/stgwebservices/pcode2address.asmx?wsdl", "PCode2Address", "PCode2AddressSoap")
oResult = ow.getAddr("h9r3K8",":")
? oResult
Mike Gagnon
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top