Since PowerBuilder 2017 R2, we have a new HTTPClient object, which is a base object for sending HTTP requests and receiving HTTP responses from a resource identified by a URI. Compared to the Inet object, the HTTPClient object is easier to use and supports more methods (Get/Post/Put/Delete) and more SSL protocols (TLS 1.0, TLS 1.1, TLS 1.2, SSL 2.0, and SSL 3.0).
Among other things, the HTTPClient can be also used to consume SOAP Web services. This is particularly useful as the Web Service Proxy has many limitations and defects calling SOAP Web services such as not supporting TLS 1.2. This article is to show how you can use the new HTTPClient to call your existing SOAP Web services instead.
Call SOAP Web services using Web Service Proxy
As a background story, let's revisit how PB consumes a SOAP Web service in the past. Firstly, you need to create a Web Service Proxy and then associate it with the pbsoapclient170.pbd or import pbsoapclient170.pbx.
Then in PB IDE, you instantiate the PB proxy with the SOAP Web service link and use the SOAPConnection object to call the associated Web service methods.
Here is the sample code:
SoapConnection conn // Define SoapConnection
n_webservicesoap proxy_obj // Declare the proxy
str_endpoint = "http://localhost/invoice/n_webservice.asmx?WSDL"
conn = create SoapConnection //Instantiate connection
rVal = Conn.CreateInstance(proxy_obj, "n_webservicesoap", str_endpoint)
// Create proxy object
li_rtn = proxy_obj.of_add(2) //invoke Web service of_add method.
messagebox("Error", "Cannot invoke Web service")
// Error handling
With the new HTTPClient object, we have a better option to call SOAP Web service.
1. Find the Correct SOAP Web service parameters
Open the SOAP Web service on IE as shown below. Copy the associated SOAP sample request. Refer to the highlighted content below. (If you don’t see this content, please contact your service provider to get such a sample request.)
Use a third party tool like Postman to verify what protocol and arguments you need to use to successfully call the Web service API.
Note: You need to replace the argument in the XML you copied in the previous step with the real argument to call the API. In this sample, we replace the word short (data type of the parameter ai_test for the of_add method) with the real argument(2).
2. Use the HTTPClient object to call the API.
After you verified successfully with Postman, apply the same protocol and arguments to HTTPClient object in your PB code.
Here is the sample code:
integer li_ret , i , li_StatusCode
ls_body = '<?xml version="1.0" encoding="utf-8"?>'+&
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '+&
' <of_add xmlns="http://tempurl.org">'+&
lo_client = Create httpClient
li_StatusCode = lo_client.GetResponseStatusCode()
ls_ret = lo_client.GetResponseStatusText( )
li_ret = lo_client.getresponsebody( ls_data)
The new approach for calling SOAP Web services is clean and simple, and it gives you more flexibility than the previous approach. We hope that you will find this article useful in your implementation of the consumption of SOAP Web services in your applications.
Note: If you want to use the PBDOM Object to build the XML content, you can refer to this knowledgebase.