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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Consume Web Service 3

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
I have a VFP 9 app that I now have to consume a web service to send and receive XML files that will contain invoice information. I have never done this before and I am looking for some advice. I've seen some information that MS no longer supporting the SDK that I would use to do this. Are there other ways to do this in VFP and is it still a good idea to do this in VFP? I could possibly do this with .NET, but prefer to keep it in VFP. Also, any advice on using XMLAdapters would be appreciated.

Auguy
Sylvania/Toledo Ohio
 
The easiest way to access web services from VFP is to use the code provided via Intellisense. This uses the SOAP toolkit to access the service. This is probably no longer Microsoft's preferred way of doing it, but it works well, and is fairly painless to implement.

The first thing is to check you've got the SOAP toolkit installed, and to install it if necessary. You do that by running the VFP setup CD.

Then you register the particular web service that you want to access, after which you can use Intellisense to generate the necessary code. Details are in the Help topic, "How to: Access XML Web Services".

If that Help topic doesn't tell you what you need to know, come back, and I'll try to talk you through it (or someone else will).

Don't worry for now about the XMLAdapter. The initial task is to make sure you can call the web service, pass parameters, and get a reply. You can worry about the XML later.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Juat to add a word ....

I just found my original notes on the subject. In summary:

1. Open the VFP Toolbox.

2. Go the XML Web Services pane.

3. Click Register.

4. Enter or paste the URL of the WSD file of the service that you want to access.

5. Open a code editing window for the code where you want to call the service (PRG or method).

6. Drag the newly registered web service from the Toolbox, and drop in the code at a suitable point.

7. Intellisense will generate some skeleton code for you. You need to modify this so that it calls the actual methods of the service that you are interested in. This is usually just a question of editing a method name (and perhaps passing some parameters), and should be obvious.

Hope this makes sense.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Great, thanks Mike!

Auguy
Sylvania/Toledo Ohio
 
Slight change of plans. After reviewing the requirements I have found that this is NOT a true web service. Here are some of the details with the company name and other items removed. Should this be approached diferently or still as a web sercice?

Here are their requirements.

Since the transactions are being conducted over an HTTPS connection, there is no
data encryption requirement. Use the HTTP “Post” method when connecting to both
the development and production service.

The company's Invoice2 interface is accessible by means of messages
sent using standard web protocols, notations and naming conventions, including XML
Protocol and SOAP standards. Invoice2 provides a standard method for businessto-
business remote service communications.

A true Web Service allows for dynamic retrieval of information on remote services. A
web service is made up of the following Technology Stack.
UDDI - Universal Description, Discovery and Integration (UDDI)
WSDL - Web Service description language
SOAP - Simple Object Access Protocol
XML - Extensible Markup Language

Invoice2 interface is not a true web service since it does not use UDDI.
The Invoice2 development kit includes a WSDL file which, given a web enabled
environment, may be helpful in constructing the payload that will be passed to Company X.
The WSDL file may assist a developer with transmission of inputs
and outputs, opening ports and the location of information. The WSDL file allows a
developer to quickly generate code by using standard software development tools.

It is not required that a developer use the WSDL file so long as the software
developed can post to Company X servlet via a production URL using
HTTP. HTTP is a synchronies means of communication and will reply with a
validating condition code.
Company X requires using the SSL version 3 (or higher) or TLS
version 1 (or higher) for secured connections to our applications.

Transaction Request/Response Steps
This is a brief description of a normal business system interaction with the Invoice2
service.
1. Build/Encode the XML request message
2. Post data to the Invoice2 service via HTTPS production URL
3. Maintain connection until response is received
4. Receive XML response data
5. Parse XML response message for relevant data. (Status Code, Authorization
Number, Reference Number, Legal Disclosures, etc.)
6. Display information to counterperson and fill in the required fields on the
customer invoice
7. Add the transaction to a report of daily transactions for next day merchant
reconciliation

Auguy
Sylvania/Toledo Ohio
 
It seems like the last 5 web transfer situations I have had to create I ended up with 5 different approaches due to the unique requirements on the 'other' end.

I have used Chilkat ActiveX components to do an HTTP POST
( )
Different 'other' ends have forced me to use different versions of this for each of them.

And I have used Microsoft's XMLHTTP for one of them.
Code:
 oHTTP = CREATEOBJECT("Microsoft.XMLHTTP")
 oHTTP.OPEN("POST", mcAgencyIQURL, .T.)
 oHTTP.setRequestHeader('Content-Type', 'application/x-[URL unfurl="true"]www-form-urlencoded')[/URL]
 oHTTP.SEND(cHTTPPostString)  && XML String previously created

  * --- Create Array To 'Catch' Response --- 
  DIMENSION aryResponse(1)
  aryResponse(1) = oHTTP.responseText
  <do whatever>

Each time I had to wrestle the code back and forth with LOTS of detailed technical support from the 'others' until it met their needs.

And I just completed 3 days of 'shooting in the dark' over a 'true' web service routine which used to work, but due to changes on the 'other' end, now needed changing.

I don't envy your upcoming work. Hopefully it will go easier than my previous work has gone.

Good Luck,
JRB-Bldr
 
Thanks JBR. The XMLHTTP seems to work, though I have to figure out how to wait for a response. I built in a small delay and it works, but there must be a better way. Without the delay I get an error that the response is not ready. Is there a loop I can put this in until I get a rseponse? I would include some code to make sure the loop exits after some period of time.

Auguy
Sylvania/Toledo Ohio
 
Got it to work with the following. I will obviously need to add some more code to make sure not in endless loop. Any suggestions or other ReadyStates I should be aware of?
Code:
DO WHILE oHTTP.readyState <> 4
ENDDO
xmlStream = oHTTP.responseText

Auguy
Sylvania/Toledo Ohio
 
Or would I be better off setting the asynch parameter to .F. With this method I would think I need some sort of timeout value to exit the request.
Code:
 oHTTP.OPEN("POST", "[URL unfurl="true"]https://SomeSite.com/services/Invoice2",[/URL] .T.)

Auguy
Sylvania/Toledo Ohio
 
OK, I have it working using Microsoft.XMLHTTP and the following code. I'm not quite sure what I have add to my project (if anything) and distribute and/or register on the user's computer to make this work properly. Any suggestions will be appreciated.
Code:
 oHTTP = CREATEOBJECT("Microsoft.XMLHTTP")
 oHTTP.OPEN("POST", URLstring, .T.)

 oHTTP.setRequestHeader('Content-Type', 'application/x-[URL unfurl="true"]www-form-urlencoded')[/URL]
 oHTTP.SEND(XMLstring)  && XML String previously created

 SleepCount = 0

 * Wait for Response, Approx SleepMax seconds
 DO while oHTTP.readyState <> 4 AND SleepCount < SleepMax
  Sleep(1000)
  SleepCount = SleepCount + 1
 ENDDO

  * ReadyState = Complete
  IF oHTTP.readyState = 4
    xmlStream = oHTTP.responseText
  Endif

Auguy
Sylvania/Toledo Ohio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top