DataFlex
DataFlex
Simple SOAP Request
See more HTTP Examples
Demonstrates how to send a simple SOAP request.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoXml
String sSoapRequestBody
String sEndpoint
String sSoapAction
String sContentType
Handle hoHttp
Variant vResp
Handle hoResp
Variant vResponseXml
Handle hoResponseXml
Integer iStatusCode
String sDat_NumberToDollarsResult
String sTemp1
Move False To iSuccess
// --------------------------------------------------------------------------------
// Also see Chilkat's Online WSDL Code Generator
// to generate code and SOAP Request and Response XML for each operation in a WSDL.
// --------------------------------------------------------------------------------
// Create the following XML to be sent in the SOAP request body.
// <soapenv:Envelope xmlns:dat="http://www.dataaccess.com/webservicesserver/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
// <soapenv:Header/>
// <soapenv:Body>
// <dat:NumberToDollars>
// <dat:dNum>99.0</dat:dNum>
// </dat:NumberToDollars>
// </soapenv:Body>
// </soapenv:Envelope>
Get Create (RefClass(cComChilkatXml)) To hoXml
If (Not(IsComObjectCreated(hoXml))) Begin
Send CreateComObject of hoXml
End
Set ComTag Of hoXml To "soapenv:Envelope"
Get ComAddAttribute Of hoXml "xmlns:dat" "http://www.dataaccess.com/webservicesserver/" To iSuccess
Get ComAddAttribute Of hoXml "xmlns:soapenv" "http://schemas.xmlsoap.org/soap/envelope/" To iSuccess
Send ComUpdateChildContent To hoXml "soapenv:Header" ""
Send ComUpdateChildContent To hoXml "soapenv:Body|dat:NumberToDollars|dat:dNum" "99.0"
// In a SOAP HTTP request, including the XML declaration (<?xml version="1.0" encoding="UTF-8"?>) in the XML body is generally not required.
Set ComEmitXmlDecl Of hoXml To False
Get ComGetXml Of hoXml To sSoapRequestBody
Move "https://www.dataaccess.com/webservicesserver/numberconversion.wso" To sEndpoint
Move "" To sSoapAction
// For SOAP requests, the standard Content-Type is usually set to "text/xml" or "application/soap+xml"
Move "text/xml" To sContentType
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Send ComClearHeaders To hoHttp
Send ComSetRequestHeader To hoHttp "SOAPAction" sSoapAction
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
Get pvComObject of hoResp to vResp
Get ComHttpStr Of hoHttp "POST" sEndpoint sSoapRequestBody "utf-8" sContentType vResp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
// Get the XML response body.
Get Create (RefClass(cComChilkatXml)) To hoResponseXml
If (Not(IsComObjectCreated(hoResponseXml))) Begin
Send CreateComObject of hoResponseXml
End
Get pvComObject of hoResponseXml to vResponseXml
Get ComGetBodyXml Of hoResp vResponseXml To iSuccess
Get ComStatusCode Of hoResp To iStatusCode
Showln "response status code: " iStatusCode
// If the status code does not indicate succcess, then show the response XML,
// which probably contains error information.
If (iStatusCode <> 200) Begin
Get ComGetXml Of hoResponseXml To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComGetXml Of hoResponseXml To sTemp1
Showln sTemp1
// Parse the successful SOAP response XML.
// This is a sample of the response XML, but the namespace prefixes will be different.
// We can parse the result using "*" for the namespace prefixes (see below).
// <soapenv:Envelope xmlns:dat="http://www.dataaccess.com/webservicesserver/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
// <soapenv:Header/>
// <soapenv:Body>
// <dat:NumberToDollarsResponse>
// <dat:NumberToDollarsResult>string</dat:NumberToDollarsResult>
// </dat:NumberToDollarsResponse>
// </soapenv:Body>
// </soapenv:Envelope>
Get ComGetChildContent Of hoResponseXml "*:Body|*:NumberToDollarsResponse|*:NumberToDollarsResult" To sDat_NumberToDollarsResult
Showln "result: " sDat_NumberToDollarsResult
End_Procedure