To initiate the HTTP requests, and then display the responses, this tutorial uses a COBOL program as its web service client. You can write your own programs to perform this task, using the XML Extensions syntax to interact with RMNet, but a program (TempConvert.cbl) is already supplied in %PUBLIC%\documents\Micro Focus\extend 10.5.1\sample\rmnet, ready for you to use.
This topic points out some of the salient parts of the program.
After accepting a Fahrenheit temperature, the following statements create the SOAP envelope for the request, using one of the style sheets you created in a previous step:
XML EXPORT FILE Fahrenheit-To-Celsius "TempFahrenheitRequest.xml" "Fahrenheit-To-Celsius" "TempConvertRequestF2C.xsl". if not XML-OK go to z.
XML EXPORT TEXT Fahrenheit-To-Celsius request-payload request-len "Fahrenheit-To-Celsius" "TempConvertRequestF2C.xsl". if not XML-OK go to z.
The XML EXPORT FILE statement is a non-mandatory step in the process that produces a copy of the XML that is created by the XML EXPORT TEXT. It allows you to view the TempFahrenheitRequest.xml file and see the format of the request.
After the request has been correctly formatted, the following portion of code, interacts with RMNet to post the HTTPS request (request-payload) to the web service, using one of the public keys supplied in ca-bundle.crt.
call "NetInit" giving response-status. call "NetSetSSLCA" using "ca-bundle.crt". call "HttpPost" using Post-Address Content-Type request-payload request-len response-payload response-len Desired-SOAP-Action giving response-status.
NetInit initializes the RMNet interface, and then HttpPost is called to make a POST request to the URL contained in Post-Address. The Content-Type parameter describes the MIME type and character encoding of the payload. In the case of a SOAP request, the MIME type should always be text/xml.
The request-payload and request-len parameters are the pointer and length of the request payload (created in the XML EXPORT TEXT). The response-payload and response-len parameters receive the pointer and length of the response payload received in the HTTP response to the POST.
Finally, the last parameter (Desired-SOAP-Action) is used to supply the SOAPAction header name/value pair that was ascertained when viewing the WSDL in SoapUI, in an earlier step.
Following the CALL to HttpPost, there follows some error checking:
set address of http-response to response-payload. display "Response: ", response-status. if not response-status = 0 call "NetGetError" using response-payload response-len giving response-status-2 set address of http-response to response-payload display "Error! ", response-status display "Error message: ", http-response(1:response-len) call "NetFree" using response-payload go to z end-if
This is 'normal' error processing if the response status is nonzero. Note that the reuse of response payload pointer is a convenience.
Finally, the response document, a SOAP envelope containing the response value, needs to be imported.
XML FREE TEXT request-payload. if response-payload = NULL display "Error: NULL pointer returned", line 10, blink accept a-single-char prompt go to z end-if. XML PUT TEXT response-payload response-len "TempFahrenheitResponse.xml". if not XML-OK go to z. XML IMPORT TEXT Fahrenheit-To-Celsius-Response response-payload response-len "Fahrenheit-To-Celsius-Response" "TempConvertResponseF2C.xsl". if not XML-OK go to z. call "NetFree" using response-payload. call "NetCleanup".
The request, which is memory allocated by XML Extensions, is returned; it is no longer needed. Similar to the previous XML EXPORT FILE, the XML PUT TEXT statement is optional, and creates the TempFahrenheitRequest.xml file and see the format of the response. The XML IMPORT TEXT imports the required data from the response SOAP envelope, using the XSLT developed above. At this point, the response payload is no longer needed and the memory is returned using NetFree. Finally, NetCleanup is called to terminate RMNet processing, allowing it to release any resources that may have been acquired during its processing.