Added June 2013
SOAP requests may be formed by combining an XML-format document (based on the requirements for the web service as defined in the WSDL for the service) with a set of HTTP binding headers. The technique is essentially the same as described in Customizing POST headers, except that the Content-Type may be different and typically you will be adding a SOAPAction header. The following is a an example of a real web service (as of June 2013) provided by WebserviceX.NET which returns details about airports based on the airport code. The format of the XML request document is as follows:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getAirportInformationByAirportCode xmlns="http://www.webserviceX.NET">
<airportCode>$AIRPORTCODE$</airportCode>
</getAirportInformationByAirportCode>
</soap:Body>
</soap:Envelope>
To generate an actual request, we copy the above into a file, replacing the $AIRPORTCODE$ with the actual code (see CGIUTL for one technique to simply such replacements). In order to specify the desired Content-Type and the SOAPAction header, we insert it at the top of our file, followed by a blank line and then the XML request:
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://www.webserviceX.NET/getAirportInformationByAirportCode"
<xml doc here>
Assuming that our generated request file is called "airport.req", we can then call the web service as follows:
flags = XHTTPF_REQPOST ! POST request (typical for SOAP)
flags = flags or XHTTPF_FILEREQ or XHTTPF_FILERESP ! request and response are both filespecs
flags = flags or XHTTPF_HDRBODY ! request body contains header lines
url = "http://www.webserviceX.NET/airport.asmx"
xcall HTTP, 1, status, flags, url, "airport.req", "airport.rsp"
To examine the final headers as sent to the service, add the XHTTPF_DEBUG flag and then check the resulting debug.req file, which should look something like:
POST /airport.asmx HTTP/1.1
Host: www.webservicex.net
Content-Type: text/xml; charset="utf-8"
SOAPAction: "http://www.webserviceX.NET/getAirportInformationByAirportCode"
Content-Length: 418
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getAirportInformationByAirportCode xmlns="http://www.webserviceX.NET">
<airportCode>LAX</airportCode>
</getAirportInformationByAirportCode>
</soap:Body>
</soap:Envelope>
Note that the POST, Host:, and Content-Length headers are added automatically, but the Content-Type and SOAPAction headers are copied from the request file.
The program AIRPORT in EXLIB:[908,25] demonstrates this service.