Date:  12/14/2008 08:33:15 AM Msg ID:  003873
From:  Gabriel Badea Thread:  003871
Subject:  Re: WEB Services with FoxWeb
This is the code that queries the web service:

= Alltrim(Str((Rand() * 10**8),20,6))

loHTTP = CreateObject("MSXML2.XMLHTTP.3.0")

lcRequestString = "http://" + Strtran(Alltrim(This.cIntermedServer), "http://", "") + "/ws.fwx?service=" + tcService + ;

      "&function=" + tcRequestFunction + IIF(Empty(tcRequestParameters), "", "&") + tcRequestParameters + ;

      "&appkey=" + IIF(Empty(This.cSessionKey), This.cAppKey, This.cSessionKey) + "&device=" + This.cDevice + "&rand=" + lcRand

If This.lLogRequests

      StrToFile(lcRequestString + Chr(13) + Chr(10), "HTTPRequest.txt", 1)


loHTTP.Open("GET", lcRequestString, .F.)


tcResponse = loHTTP.ResponseBody

If This.lLogResponses

      StrToFile(tcResponse + Chr(13) + Chr(10), "HTTPResponse.txt", 1)EndIf


I understand that I should be using POST as opposed to GET but I've never done this.  I'll check MS documentation but I've only found examples that use GET.

Here is something I came accross that I adapted from some AJAX speaking site, that looks like it may work:


= Alltrim(Str((Rand() * 10**8),20,6))

lcFormData = "service=" + tcService "&function=" + tcRequestFunction + IIF(Empty(tcRequestParameters), "", "&") + tcRequestParameters + ;

      "&appkey=" + IIF(Empty(This.cSessionKey), This.cAppKey, This.cSessionKey) + "&device=" + This.cDevice + "&rand=" + lcRand

loHTTP = CreateObject("MSXML2.XMLHTTP.3.0")"POST", "http://" + Strtran(Alltrim(This.cIntermedServer), "http://", "") + "/ws.fwx" , .F.)




I'll be trying this out as soon as I write the server side code, but if anyone has any suggestions how else I could do it please let me know. 
One last detail is bugging me though : I'm sending form data that is NOT XML in the latter.  If I were to generate XML data as the contents of lcFormData), how do I specify XML content in the request header as opposed to loHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded;"); ?


Sent by FoxWeb Support on 12/13/2008 09:43:54 PM:
What consumes your web service? I would think that, at least when in production, it will not be you typing URLs in the browser's location bar, but rather, an application that uses some sort of HTTP component to initiate the request to your FoxWeb server. Virtually all HTTP components can send data via post. The exact method varies, so consult the documentation of the component you plan to use.
On the FoxWeb side you can retrieve the complete POST data, by calling the Request.Form() method with no parameters.
FoxWeb Support Team email
Sent by Gabriel Badea on 12/13/2008 11:35:34 AM:

I have written a homegrown version of a web service using FoxWeb. 

I use a normal query string (i.e. http://.../ws.fwx?service=someservice&function=somefunction&appkey=ABCD-12345678-FDB7&param1=...  well... you get the idea) to run some process defined by the querystring field/value pairs and return an XML response (i.e. Response.ContentType = "text/xml").   There is a severe limitation to this way of doing things if the querystring is long and exceeds the maximum length for a query string (some say 2048 bytes others 4096 etc...)

1. How would I go about sending an xml string using the POST method?

2. I noticed that once in a while one or more channels die and do not get restarted (i.e. if I check show_channels.fwx I'll only see channels 1-3, 5-7 and 9-10).  Waiting for them to restart didn't help as I .  It happens only occasionnally and I have to restart Foxweb to fix the problem.  I'm running version 3.51 as a service with 10 channels.