Accessing a XML Post on the Active VFP Server

Topics: Developer Forum, User Forum
Oct 24, 2011 at 3:30 PM

I am trying to use VFP on the client and Active VFP on the server for data exchange w/XML. When I recieve the data at the server I want to use the XMLTOCURSOR function to accept the XML data and process whatever message I send up.

Does any know how to do this? The data is not in the FORM or QUERYSTRING. When posting the data in a form variable IIS intercepts it b/c it doesn't like SQL in the form.

 

On the client side I am doing this:

*- Client side handling
*- Send an XML message to the server..
 
oXML = CREATEOBJECT("Msxml2.XMLHTTP.6.0") 
lcTime = ALLTRIM(STR(SECONDS(),112,5)) 

*- XML Snippet
TEXT TO lcXML TEXTMERGE PRETEXT 15 NOSHOW
<?xml version="1.0" encoding="Windows-1252" standalone="yes" ?>
<VFPData>
  <SqlCommand>
    <TableName>Customers</TableName>
    <SqlCommand>Insert Into Foo (FieldName) VALUES ("FieldValue")</SqlCommand>
  </SqlCommand>
</VFPData>
ENDTEXT
 

*- Send it to the server
oXml.Open("POST", "http://localhost/SqlXml.avfp?Time=" + lcTime, .F.)
oXml.SetResponseHeader("Content-Type", "text/xml")
oXml.Send(lcXml)

oXml = Null

 

Coordinator
Oct 24, 2011 at 5:12 PM
Edited Oct 24, 2011 at 5:13 PM

I've seen a few articles suggesting that the Request object can be accessed directly.  See:

http://stackoverflow.com/questions/369226/receiving-xml-from-another-websites-call-to-serverxmlhttp-post-in-classic-asp

ActiveVFP is using the same objects - subclassed and renamed oRequest.  In your SqlXml.avfp you need to check what's in the oRequest object ... maybe something like (from aspvars.avfp):

FOR EACH lcFormVar IN oRequest.oRequest.FORM
    lcVar =   oRequest.oRequest.FORM(lcFormVar)
    lcSTR=lcSTR+[    <TR><TD><b> ]+ lcFormVar +[ </b></TD><TD> ] ;
        +lcVar +[</TD></TR>]
NEXT

------

To get to the base values in Request, oRequest.oRequest is needed.   Otherwise oRequest by itself is just getting values from my subclassed method (which may actually have the value already).

Bottom line is it's being passed to the avfp application, you just need to figure out how to retrieve it based on how it's coming over, most likely in the Request object somewhere.  The previous code may have it embedded

Oct 25, 2011 at 3:12 AM

@claudefox:  Thanks very much for the reply it worked

What I did was use the example in the link and read the xmlDoc.xml property and use the XMLTOCURSOR function to create my cursor and send back a message to the client. What a great way to turn a VFP database and application into a web enabled powerhouse! This is a simple example but is super powerful. We should wrap this up into a VfpServer product for killer apps :o)

<%
oResponse.ContentType = "text/xml"

LOCAL XmlDoc
XmlDoc = CREATEOBJECT("Microsoft.XMLDOM")

xmlDoc.async=.F.
xmlDoc.load(oRequest.oRequest)
lcXml = xmlDoc.xml   
xmlDoc = Null

XMLTOCURSOR(lcXml, "ClientData", 0)

LOCAL lcMessage
lcMessage = ""

IF USED("ClientData") THEN
  lcMessage = "Recieved command for: " + ClientData.TableName
ENDIF


TEXT TO lcXML TEXTMERGE NOSHOW
<?xml version="1.0" encoding="Windows-1252" standalone="yes" ?>
<VFPData>
  <ServerMessage>
    <MessageText><<lcMessage>></MessageText>
  </ServerMessage>
</VFPData>
ENDTEXT
%>
<%=lcXml %>