Sample code for 30+ languages & platforms
PowerBuilder

Simple SOAP Request

See more HTTP Examples

Demonstrates how to send a simple SOAP request.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Xml
string ls_SoapRequestBody
string ls_Endpoint
string ls_SoapAction
string ls_ContentType
oleobject loo_Http
oleobject loo_Resp
oleobject loo_ResponseXml
integer li_StatusCode
string ls_Dat_NumberToDollarsResult

li_Success = 0

// --------------------------------------------------------------------------------
// 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>

loo_Xml = create oleobject
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")
if li_rc < 0 then
    destroy loo_Xml
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Xml.Tag = "soapenv:Envelope"
loo_Xml.AddAttribute("xmlns:dat","http://www.dataaccess.com/webservicesserver/")
loo_Xml.AddAttribute("xmlns:soapenv","http://schemas.xmlsoap.org/soap/envelope/")
loo_Xml.UpdateChildContent("soapenv:Header","")
loo_Xml.UpdateChildContent("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. 
loo_Xml.EmitXmlDecl = 0
ls_SoapRequestBody = loo_Xml.GetXml()

ls_Endpoint = "https://www.dataaccess.com/webservicesserver/numberconversion.wso"
ls_SoapAction = ""
//  For SOAP requests, the standard Content-Type is usually set to "text/xml" or "application/soap+xml"
ls_ContentType = "text/xml"

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")

loo_Http.ClearHeaders()
loo_Http.SetRequestHeader("SOAPAction",ls_SoapAction)

loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")

li_Success = loo_Http.HttpStr("POST",ls_Endpoint,ls_SoapRequestBody,"utf-8",ls_ContentType,loo_Resp)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Xml
    destroy loo_Http
    destroy loo_Resp
    return
end if

// Get the XML response body.
loo_ResponseXml = create oleobject
li_rc = loo_ResponseXml.ConnectToNewObject("Chilkat.Xml")

loo_Resp.GetBodyXml(loo_ResponseXml)

li_StatusCode = loo_Resp.StatusCode
Write-Debug "response status code: " + string(li_StatusCode)

// If the status code does not indicate succcess, then show the response XML,
// which probably contains error information.
if li_StatusCode <> 200 then
    Write-Debug loo_ResponseXml.GetXml()
    destroy loo_Xml
    destroy loo_Http
    destroy loo_Resp
    destroy loo_ResponseXml
    return
end if

Write-Debug loo_ResponseXml.GetXml()

// 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>

ls_Dat_NumberToDollarsResult = loo_ResponseXml.GetChildContent("*:Body|*:NumberToDollarsResponse|*:NumberToDollarsResult")
Write-Debug "result: " + ls_Dat_NumberToDollarsResult


destroy loo_Xml
destroy loo_Http
destroy loo_Resp
destroy loo_ResponseXml