Showing posts with label c++. Show all posts
Showing posts with label c++. Show all posts

Sunday, July 14, 2013

Create a Web Service Client using GSoap Toolkit over HP-UX Server

This article was previously posted in CodeProject, I like very much this web site since my college days so this is the url: Create-a-Web-Service-Client-using-GSoap-Toolkit-over-HPUX , I hope this article will be helpful to you.

Sometimes in our daily lives as developers we have to integrate technology with different qualities sometimes this products are expensive or some relative close to the business lines, for example how to use a enterprise service overall the communication with legacy systems that is tough question, so the first possibility to resolve this problem is using message queue or web service or any other component there are many ways but the result should be measured and quantifiable for getting an approximation.

I want to emphasize a scenario where you are using a HP-UX server you want to integrate a legacy business process with enterprise service bus, so typically you have an interface from your ESB that could be a WSDL, this legacy system can execute a library, by now the common solution is doing some message queue put a message and wait that MDB get the message and you will be waiting the response, by this way is a very fast solution but  if you want to use XML on web service scenario well one advantage of ESB is that you could do eventually with the broker a transformation where you put a XML message in queue and the ESB literally will do the transformation this is a nice solution but I can give another one 'webservice vs legacy program' instance you should be thinking use a language like C (ANSI) or Python or cURL.
If you have using web service client generator like axis2 or wsdl.exe you should be familiarized with this toolkit is called GSoap is really fast and reliable in many aspects, if you search on internet you will get something like:
"gSOAP is an open source C and C++ software development toolkit for SOAP/XML Web services and generic XML data bindings. ", Wikipedia
The interesting part of the toolkit is that you will get C ANSI code generated on your stub, essencially all gcc compilers will translate his code The interesting part of the toolkit is that you will get C ANSI code
generated on your stub, essencially all gcc compilers will translate his code.

Using the code   


1. Download GSOAP Toolkit
The first step is download GSoap Toolkit from following site: http://sourceforge.net/projects/gsoap2/files/
Second Step should be install GSoap Toolkit , unzip gsoap_2.7.15.tar in a root directory for execution.
Example:  C:/SOAP/ gsoap_2.7.15
There are two executable files that allow us to generate libraries for connecting to the Web Service:1. wsdl2h.exe
2. soapcpp2.exe 
a.1 Run wsdl2h.exe 

a.2 Run soapcpp2.exe 
 





 2. Get WSDL file from Web Service Endpoint
 Here is an WSDL Example that you can see the xml structure.

GSoap can process the WSDL from the Web Service Endpoint only if the sitio does not have any kind of authetication that prevent direct access to web service. The most recommended option is directly get wsdl file from a web browser, taking care downloading the xsd files and change it form schemaLocation tag.

3. Generate Header File for the Stub

Generate the Header File 'SaleService.wsdl' thats has the necessary structures and procedures to generate the stub, it is important to note that the file will guide us to implement a web service client.
Example:

If we open the file containing struct SalesService.h notice that they are related to the input parameters and return variables.
Example:  
Another important point is that we handle struct for C (ansi), if we had used the-c parameter in wsdlh.exe, would have generated code in C + +, and this does not benefit us in the HP-UX terminals
 
4. Generate the Stub
With SalesService.h  header file we can use the following executable

If we observe the command line, are generated 4 files extension *.c

Files Generated need the following: 




Archivo
Definición
1.
soapH.h
Main Header File
2.
soapC.c
File with Data Structures.
3.
soapClient.c 
File with the implementation of the methods in C Web Service. 
4.
SalesService Soap12Binding.nsmap
SalesServiceSoap11Binding.nsmap  
Struct with corresponding namespaces Soap versions 1.1 and 1.2, this according to the version you wish to use

 5. Header file for the library 
We continue to write the library in first generating Header File (SalesServiceWS.h) 

  This file contains the public firm library SL / DLL


6. Main file with the implementation of the library 

We continue to write the call to the Web Service method according to this signature on file SaleService.h:



 
7. Compilation Shell 

The next thing is to compile the component on a HP-UX Terminal, so we need to ask the following fact:

When HP-UX compile our programs must be generated in 64bit for other programs running on the server can open the library and their corresponding links, as is the case for Progress Program 9, the common misconception regarding compilation this program is on the library dld.sl. 

Finally this is shell you could run on HP-UX Terminal, the reason is to compile all your source and get a library with *.sl extension

 
An important point during compilation is to include operating system libraries needed for compilation as in the case of lxnet, lnsl, ldl, lpthread.