XML Replay: Difference between revisions

From DataFlex Wiki
Jump to navigationJump to search
112 bytes added ,  22 November 2007
m
added cookbook category
m (Updated XML logging to XML Logging)
m (added cookbook category)
 
(2 intermediate revisions by the same user not shown)
Line 7: Line 7:
   Use cXmlHttpTransfer.pkg<br />
   Use cXmlHttpTransfer.pkg<br />
   Object oTfr is a cXmlHttpTransfer
   Object oTfr is a cXmlHttpTransfer
   End_Object  <font color="green">// oTfr</font>
   End_Object  <span style="color:green;">// oTfr</span>
    
    
   Procedure InvokeService
   Procedure InvokeService
Line 13: Line 13:
       Boolean bOK
       Boolean bOK
       String  sServer sURI<br />
       String  sServer sURI<br />
       <font color="green">// Create the XML document and load your XML:</font>
       <span style="color:green;">// Create the XML document and load your XML:</span>
       Get Create U_cXmlDomDocument to hoDoc
       Get Create U_cXmlDomDocument to hoDoc
       Set psDocumentName of hoDoc  to (Value(oInput(Self)))
       Set psDocumentName of hoDoc  to (Value(oInput(Self)))
Line 22: Line 22:
       End<br />
       End<br />
       Get DocumentElement of hoDoc to hoMsg<br />
       Get DocumentElement of hoDoc to hoMsg<br />
       <font color="green">// Create the SOAP message, adding the initial processing instruction,
       <span style="color:green;">// Create the SOAP message, adding the initial processing instruction,
       // the "Envelope" document element, the "Body", then append your XML to that:</font>
       // the "Envelope" document element, the "Body", then append your XML to that:</span>
       Get Create U_cXmlDomDocument to hoXML
       Get Create U_cXmlDomDocument to hoXML
       Send AddChildProcessingInstruction of hoXML "xml" 'version="1.0"'
       Send AddChildProcessingInstruction of hoXML "xml" 'version="1.0"'
Line 29: Line 29:
       Get AddElement of hoEnv "soap:Body" "" to hoBody
       Get AddElement of hoEnv "soap:Body" "" to hoBody
       Get AppendNode of hoBody hoMsg to hoMsg<br />
       Get AppendNode of hoBody hoMsg to hoMsg<br />
       <font color="green">// Set up the HTTP headers:</font>
       <span style="color:green;">// Set up the HTTP headers:</span>
       Send ClearHeaders of oTfr
       Send ClearHeaders of oTfr
       Set psAcceptTypes of oTfr to "text/*"
       Set psAcceptTypes of oTfr to "text/*"
       Set psContentTypeSent of oTfr to "text/xml; charset=UTF-8"
       Set psContentTypeSent of oTfr to "text/xml; charset=UTF-8"
       Get AddHeader of oTfr "SOAPAction" ('"' + Value(oOperation(Self)) + '"') to bOk<br />
       Get AddHeader of oTfr "SOAPAction" ('"' + Value(oOperation(Self)) + '"') to bOk<br />
       <font color="green">// Prepare the transfer object for sending:</font>
       <span style="color:green;">// Prepare the transfer object for sending:</span>
       Get Value of oServer to sServer
       Get Value of oServer to sServer
       Get Value of oURI    to sURI
       Get Value of oURI    to sURI
       Set piRemotePort of oTfr to (Value(oPort(Self)))<br />
       Set piRemotePort of oTfr to (Value(oPort(Self)))<br />
       <font color="green">// Send the message:</font>
       <span style="color:green;">// Send the message:</span>
       Get HttpPostXmlNode of oTfr sServer sURI hoXML to hoXMLResponse<br />
       Get HttpPostXmlNode of oTfr sServer sURI hoXML to hoXMLResponse<br />
       <font color="green">// Deal with the response:</font>
       <span style="color:green;">// Deal with the response:</span>
       If (hoXmlResponse=0) Set Value of oReturnedXML to "NO RESPONSE"
       If (hoXmlResponse=0) Set Value of oReturnedXML to "NO RESPONSE"
       Else                Set Value of oReturnedXML to (psXml(hoXmlResponse))<br />
       Else                Set Value of oReturnedXML to (psXml(hoXmlResponse))<br />
       <font color="green">// Tidy up:</font>
       <span style="color:green;">// Tidy up:</span>
       Send Destroy of hoXML
       Send Destroy of hoXML
       If hoXMLResponse Send Destroy of hoXMLResponse<br />
       If hoXMLResponse Send Destroy of hoXMLResponse<br />
   End_Procedure  <font color="green">// InvokeService</font>
   End_Procedure  <span style="color:green;">// InvokeService</span>


The above code obviously assumes the existence of objects (probably mostly of the class "Form") which contain the relevant information for the operation invocation:
The above code obviously assumes the existence of objects (probably mostly of the class "Form") which contain the relevant information for the operation invocation:
Line 55: Line 55:
*oURI - the URI of the service within the host: e.g. "MyService/TestService.wso"  
*oURI - the URI of the service within the host: e.g. "MyService/TestService.wso"  
*oReturnedXML - an object of class "cTextEdit" to take and display the response XML
*oReturnedXML - an object of class "cTextEdit" to take and display the response XML
[[Category:Web Services]] [[Category:Cookbook]]

Navigation menu