In this article we intend to show how web services based on SOAP/HTTP can be consumed in the TXSeries applications which are written in C and C++ language. This is illustrated in a step by step approach using examples.
Web services expect the requests to be a SOAP message. Hence TXSeries applications that need to consume Web Services will need a SOAP message translator to translate C, C++ function calls to SOAP messages. In the examples provided Apache Axis2/C will do this translation, to call a web service deployed in WebSphere Application Server.
Apache Axis2/C is a web services engine implemented in C programming language. It can be used to create web services and consume web services. In this article we are using Axis2/C as a web service client.
TXSeries for Multiplatforms is a transaction manager used by enterprises to process transactions. The TXSeries applications are designed in C, C++, Cobol, PL/1 languages. The transaction manager runs on multiple platforms including Windows, Solaris, AIX HP-UX and HP-Itanium.
Consuming web services in TXSeries Application
Within the J2EE environment many vendors provide their services to other application developers as web services. By integrating them with TXSeries, a rich application can be designed. Typical architecture of TXSeries application consuming web service is shown below in figure 1.
Figure 1. Architecture of TXSeries Application consuming web services
The steps for creating a simple TXSeries application that consumes web services are:
- Install and configure the required products.
- Obtain the WSDL file and create the stubs.
- Typical application code flow.
- Create a TXSeries region and configure the stanzas.
- Develop the TXSeries application.
- Compiling the application.
- Running the application.
1. Install and configure the pre-requisites
On a Windows machine install and configure Axis, Axis2/C and TXSeries for Multiplatforms for windows.
Install Axis 1.5.1 and save it in the following directory: C:\axis2-1.5.1.
Install Axis2/C and save it in the following directory: C:\axis2c1.5.
After the installation, set the environment variable AXIS2_HOME to C:\axis2-1.5.1 within the WSDL2C.bat file located in C:\axis2c1.5\bin\tools\wsdl2c.
The WSDL2C.bat file contains the following:
WSDL2C.bat
set AXIS2_HOME=C:\axis2-1.5.1
setlocal EnableDelayedExpansion
set AXIS2_CLASSPATH=%AXIS2_HOME%
FOR %%c in ("%AXIS2_HOME%\lib\*.jar") DO set AXIS2_CLASSPATH=!AXIS2_CLASSPATH!;%%c;
Java -classpath %AXIS2_CLASSPATH% org.apache.axis2.wsdl.WSDL2C %*
|
2.Obtaining WSDL file and creating stubs
Most often web services will have a WSDL file associated with it. The WSDL file describes the messages that a client should send and receive. It also describes where the service resides and how it can be invoked. WSDL uses XML for this specification. To call the web service in C and C++ client applications, the clients stubcodes are generated from the WSDL file. This is accomplished by using a tool called WSDL2C provided by Axis2/C.
Obtaining the WSDL file
Retrieve the WSDL file from the service provider for the required service. If you know the endpoint of the service, the WSDL file can be obtained by appending ?wsdl to the service end-point.
Here we list down the steps involved in generating the stub code for a web service named "QuoteService".
Let us consider that "QuoteService" example takes the "company name" as the input and gives the "stock quote price" of that company as the output. This QuoteService is deployed on a Websphere Application Server on a host named "xmspamdwin64" and listening on port 9080. The service endpoint for "QuoteService" is http://xmspamdwin64:9080/StockQuoteproj/services/QuoteService.
The WSDL file is obtained by appending ?wsdl to service endpoint as shown below http://xmspamdwin64:9080/StockQuoteproj/services/QuoteService?wsdl.
Generating stubs from WSDL file
The WSDL2C.bat tool provided with the Axis2/C is used to generate client stub files. In our example the client stub for the "QuoteService.wsdl" is generated using either of the following command.
./WSDL2C.bat -uri QuoteService.wsdl -d adb -u or ./WSDL2C.bat -uri http://xmspamdwin64:9080/StockQuoteProj/services/QuoteService?wsdl -d adb -u |
The definitions of the options are:
-d adb Choose adb (axis data binding) -u Unpacks the databinding classes |
It generates following stub files in src directory by default:
adb_GetQuote.c adb_GetQuoteResponse.c adb_GetQuote.h adb_GetQuoteResponse.h axis2_stub_QuoteServiceService.h axis2_stub_QuoteServiceService.c |
Now we have generated the required client stub code to access the web service.
3. Typical application code flow
The TXSeries application should call the sequence of functions generated from the stub code to avail the web service. The stub functions called in the provided TXSeries example to avail the "QuoteService" are explained using the following diagram
Figure 2. Application code flow
4. Create TXSeries region and configure the stanzas
To create the TXSeries region and add the resources entries to the stanzas using the following commands:
cicscp -v create region region_name cicsadd -c td -r <region_name> TRAN1 ProgName="PROG1" cicsadd -c pd -r <region_name> PROG1 PathName="StockCheck.dll" cicsadd -c pd -r <region_name> MAP3 ProgType=map PathName="map3.map |
5. Developing the TXSeries application
In this section we explain the important steps involved in developing a TXSeries application to consume a web service using Axis2/c routines. The complete source code of the example is also provided for the reference.
Generate Map file for 3270 clients.
Create the BMS (quote.bms) file and headerfile (map3.h) using the CICSSDA tool. For more details on how to create BMS file please refer TXSeries for Multiplatforms 7.1 programming guide. Convert the BMS file to map file (map3.map) using the following command
cicsmap quote.bms |
Copy the file map3.map to the following directory: C:/var/cics_regions/region_name/maps/prime
Axis2/C Initialization routines
Call the following Axis2/C routines as part of the initialization. The usage of these routines are explained in section 3.
axutil_env_create_all() axis2_stub_create_QuoteServiceService() adb_GetQuote_create() |
Get the Input from 3270 Terminal
The following code segments illustrate how to get the input from the 3270 terminal using maps.
/* Send the MAP file 3270 to get company code and customers selection
from the user*/
sprintf(map3.map3o.statuso,"Enter Company Code");
EXEC CICS SEND MAP("MAP3") MAPSET("MAP3")
FREEKB ERASE RESP(rcode);
if(rcode != DFHRESP(NORMAL))
EXEC CICS ABEND ABCODE("SERR");
memset(&map3.map3i.cmpnamei,0,4);
memset(&map3.map3i.confi,0, 1);
|
/* Receive the MAP file with company code and the selection */
EXEC CICS RECEIVE MAP("MAP3") MAPSET("MAP3") RESP(rcode);
if(rcode != DFHRESP(NORMAL))
EXEC CICS ABEND ABCODE("RERR");
|
Invoke the web service from TXSeries.
/* Making request to web service */ stock_res = axis2_stub_op_QuoteServiceService_GetQuote(stub, env, stock_in); |
Sending the result to the 3270 terminal
/* extracting the returned value */
res_val = adb_GetQuoteResponse_get_GetQuoteReturn(stock_res, env);
fprintf(stderr, "result = %d\n", res_val);
sprintf(map3.map3o.quoteo,"%d",res_val);
sprintf(map3.map3o.statuso,"Transaction Ended");
EXEC CICS SEND MAP("MAP3") MAPSET("MAP3")
FREEKB ERASE RESP(rcode);
if(rcode != DFHRESP(NORMAL))
EXEC CICS ABEND ABCODE("SERR");
}
EXEC CICS RETURN;
|
Compile and link the TXSeries application with Axis2/C libraries by referring the commands provided in the cics_comp.bat file provided with the example code.
When the TXSeries transaction TRAN1 is executed on a 3270, the following screen shown in figure 3 is displaced. The company name for which the quote price is required and should be entered followed by a confirmation.
Figure 3. Executing the application launch screen
On success, the quote price is displayed as shown in figure 4.
Figure 4. Success message
On failure, the following message is displayed as displayed in figure 5 below.
Figure 5. Failed message
The developer should be aware of the web service endpoint before implementing the solution.
Dynamic lookup of web service is not possible with this approach.
Error handling and security aspects are not covered in this article.
This solution is applicable only to C, C++ TXSeries application.
Quick solution with the existing technologies with minimum development time.
| Description | Name | Size | Download method |
|---|---|---|---|
| A TXSeries application for this article | example.zip | 4KB | HTTP |
Information about download methods
Learn
-
"Use The Apache Software foundation"
for Axis2/C installables and documentation.
-
"Use Apache Axis2/java
Version 1.5.1" for Axis2/Java installables and documentation.
-
"Use
for TXSeries for Multiplatforms Information Center" TXSeries for multiplatforms 7.1 documenation.
-
"Use SOA and web
services" for Articles, tutorials, standards, and other technical resources for web services and SOA.
- In the
Architecture area on developerWorks,
get the resources you need to advance your skills in the architecture arena.
- Browse the
technology bookstore
for books on these and other technical topics.
Get products and technologies
- Download
IBM product evaluation versions
or explore
the online trials in the IBM SOA Sandbox and get your hands on application development tools and middleware products from
DB2®, Lotus®, Rational®, Tivoli®, and
WebSphere®.
Discuss
- Check out
developerWorks
blogs and
get involved in the
developerWorks community.

Ramesh Belavadi has more than 9 years of experience at IBM. He was working as a TXSeries L3 support Engineer before he joined XMS Team as Performance and Test Engineer.






