It is quite easy to build a SOAP client in IceBreak. Simply follow these steps:
1) First read the chapter 6 (XML, Webservices and proxies) in the IceBreak manual regarding SOAP and its concepts.
2) Lets make a simple calculator SOAP service – lets name it Soap01Service.ASMX
<%@ language="RPGLE" pgmtype="webservice" %>
<%
h nomain
p*name++++++++++..b...................keywords++++++++++++++++++++++++++comments+++++++++ +++
p Calculator B export
d pi
d x 10i 0 Input
d y 10i 0 Input
d z 10i 0 Output
/free
z = x + y;
/end-free
p Calculator E
Now lets work with the client (consumer part):
3) You need a tool to test the SOAP service you will access. Download SOAP-UI which is a great tool for both test and verification.
5) Open the request and let SOAP - UI create the SOAP envelope: Fill in the request and press the green “>” play arrow to run the request (see screen shot 2).
6) Copy and paste the request envelope (the left side) into the attached SOAP client template code – Place it into the subroutine “BuildSoapEnvelope”.
7) Use XML_locate to point the result of the web service call:
pCalculator = xml_Locate(xmlPtr : '/Envelope/Body/CalculatorResponse');
z = XML_GetValueNum(pCalculator: 'z');
8) The final code looks like:
<%@ language="RPGLE" %>
<%
//Include the ILOB and xml parser prototypes
/include qasphdr,ilob
/include qasphdr,xmlparser
d*Name++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++Comments++++++++++++
d url s 1014 varying
d Error s N
d reqILOB s *
d respILOB s *
d xmlPtr s *
d pCalculator s *
d x s 10i 0
d y s 10i 0
d z s 10i 0
/free
// My goal: Add x=123 to y=456
x=reqNum('x':123);
y=reqNum('y':456);
// First I create my work ILOB's
reqILOB = SesGetILOB('request'); // get a pointer to a session ILOB used as my request
respILOB = SesGetILOB('response'); // get a pointer to a session ILOB used for the response from the server
// Reset my ilob
ILOB_Clear(reqILOB);
ILOB_Clear(respILOB);
// Now I want to populate a simple XML request. - my ILOB header needs a content type XML
// All httpRequest are routet to the same default job hench the cookie
ILOB_SetHeaderBuf(
reqILOB :
'Content-Type: application/XML; charset=windows-1252'
);
// I reroute my response object to the request ILOB, so I can use the ASPX sysnax for creating the XML
// And when done, I redirect my response back to the default responce object (what my browser receives >
SetResponseObject(reqILOB);
exsr buildSoapEnvelope;
SetResponseObject(*NULL);
// Setup the url to the service
Url = 'http://dkexp05:60000/Soap01Service.asmx';
// My request is now ready to go to the server, so I call the httpRequest for ILOB's
Error = ILOB_httpRequest(
Url : // The URL in form:"http://server:port/resource"
30: // Number of seconds before timing out
'POST': // Soap will use the "POST" method
reqILOB: // pointer to my Request ILOB
RespILOB // pointer to my Response ILOB
);
// Check for errors
if error;
%><% = GetlastError('*MSGTXT') %><%
return;
endif;
// My data has arrived - I'll fire up the XML parser
xmlPtr = XML_ParseILOB ( //' Returns XML-object tree from an ILOB
RespILOB: //' Pointer to an ILOB object
'syntax=loose': //' Parsing options
1252: //' The ccsid of the input ilob (0=current job)
0 //' The ccsid of the XML tree (0=current job)
);
// Check for errors
if XML_Error(xmlPtr);
%><% = XML_Message(xmlPtr) %><%
XML_Close(xmlPtr);
return;
endif;
// Use X-path to get data from the SOAP XML tree
pCalculator = xml_Locate(xmlPtr : '/Envelope/Body/CalculatorResponse');
z = XML_GetValueNum(pCalculator: 'z');
// Print result
%><html>
<head>
<link rel="stylesheet" type="text/css" href="/System/Styles/IceBreak.css"/>
</head>
<h1>Calculator output</h1>
<p>The sum of X and Y is : <%= %char(z) %></p>
</html><%
// Always release the memory used
XML_Close(xmlPtr);
return;
// ----------------------------------------------------------------------------------------------------------
Begsr BuildSoapEnvelope;
%><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:sys="http://systest.icebreak.org/">
<soap:Header/>
<soap:Body>
<sys:Calculator>
<sys:x><% = %char(x)%></sys:x>
<sys:y><% = %char(y)%></sys:y>
</sys:Calculator>
</soap:Body>
</soap:Envelope><%
Endsr;
Re: Creating a SOAP service consumer
Hi,
It is quite easy to build a SOAP client in IceBreak. Simply follow these steps:
1) First read the chapter 6 (XML, Webservices and proxies) in the IceBreak manual regarding SOAP and its concepts.
2) Lets make a simple calculator SOAP service – lets name it Soap01Service.ASMX
Now lets work with the client (consumer part):
3) You need a tool to test the SOAP service you will access. Download SOAP-UI which is a great tool for both test and verification.
4) Create a new project in SOAP-UI. Enter to location for the WSDL of the calculator service: in my case http://myibmi:60000/soap01Service.asmx?WSDL (see screen shot 1).
5) Open the request and let SOAP - UI create the SOAP envelope: Fill in the request and press the green “>” play arrow to run the request (see screen shot 2).
6) Copy and paste the request envelope (the left side) into the attached SOAP client template code – Place it into the subroutine “BuildSoapEnvelope”.
7) Use XML_locate to point the result of the web service call:
8) The final code looks like:
<%@ language="RPGLE" %> <% //Include the ILOB and xml parser prototypes /include qasphdr,ilob /include qasphdr,xmlparser d*Name++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++Comments++++++++++++ d url s 1014 varying d Error s N d reqILOB s * d respILOB s * d xmlPtr s * d pCalculator s * d x s 10i 0 d y s 10i 0 d z s 10i 0 /free // My goal: Add x=123 to y=456 x=reqNum('x':123); y=reqNum('y':456); // First I create my work ILOB's reqILOB = SesGetILOB('request'); // get a pointer to a session ILOB used as my request respILOB = SesGetILOB('response'); // get a pointer to a session ILOB used for the response from the server // Reset my ilob ILOB_Clear(reqILOB); ILOB_Clear(respILOB); // Now I want to populate a simple XML request. - my ILOB header needs a content type XML // All httpRequest are routet to the same default job hench the cookie ILOB_SetHeaderBuf( reqILOB : 'Content-Type: application/XML; charset=windows-1252' ); // I reroute my response object to the request ILOB, so I can use the ASPX sysnax for creating the XML // And when done, I redirect my response back to the default responce object (what my browser receives > SetResponseObject(reqILOB); exsr buildSoapEnvelope; SetResponseObject(*NULL); // Setup the url to the service Url = 'http://dkexp05:60000/Soap01Service.asmx'; // My request is now ready to go to the server, so I call the httpRequest for ILOB's Error = ILOB_httpRequest( Url : // The URL in form:"http://server:port/resource" 30: // Number of seconds before timing out 'POST': // Soap will use the "POST" method reqILOB: // pointer to my Request ILOB RespILOB // pointer to my Response ILOB ); // Check for errors if error; %><% = GetlastError('*MSGTXT') %><% return; endif; // My data has arrived - I'll fire up the XML parser xmlPtr = XML_ParseILOB ( //' Returns XML-object tree from an ILOB RespILOB: //' Pointer to an ILOB object 'syntax=loose': //' Parsing options 1252: //' The ccsid of the input ilob (0=current job) 0 //' The ccsid of the XML tree (0=current job) ); // Check for errors if XML_Error(xmlPtr); %><% = XML_Message(xmlPtr) %><% XML_Close(xmlPtr); return; endif; // Use X-path to get data from the SOAP XML tree pCalculator = xml_Locate(xmlPtr : '/Envelope/Body/CalculatorResponse'); z = XML_GetValueNum(pCalculator: 'z'); // Print result %><html> <head> <link rel="stylesheet" type="text/css" href="/System/Styles/IceBreak.css"/> </head> <h1>Calculator output</h1> <p>The sum of X and Y is : <%= %char(z) %></p> </html><% // Always release the memory used XML_Close(xmlPtr); return; // ---------------------------------------------------------------------------------------------------------- Begsr BuildSoapEnvelope; %><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:sys="http://systest.icebreak.org/"> <soap:Header/> <soap:Body> <sys:Calculator> <sys:x><% = %char(x)%></sys:x> <sys:y><% = %char(y)%></sys:y> </sys:Calculator> </soap:Body> </soap:Envelope><% Endsr;Best regards,
Niels Liisberg