Creation of a gSOAP Web Service a gSOAP client and an Axis client

gSOAP: C/C++ Web Services and Clients
gSOAP: User Guide

 

 


 


 

This short tutorial describes how to create a stand-alone Web Service in C(++) utilizing the gSOAP library. The gSOAP compiler makes it possible to generate SOAP Web Services and client applications without detailed knowledge of the SOAP protocol 1.1.

 

1) Creation of the header file
The headerfile <gSoapTextService.h> can be created by hand or by dint of a tool, for example wsdl2h.

In this file it is necessary to declare the parameter of the remote methods.
The following entries should be contained:

  	
        //gsoap ns service name:	TextService
	//gsoap ns service style:	document
	//gsoap ns service encoding:	literal
	//gsoap ns service namespace:	http://smartweb.semanticweb.org/TextService.wsdl
	//gsoap ns service location:	http://localhost:1444
	
	//gsoap ns schema namespace: urn:TextService
	int ns__processData(char **requestData, char **responseData);

  

 

 

2) Creation of the stub und skeleton classes
The gSOAP stub and skeleton compiler soapcpp2 creates automatically a skeleton routine in c++ source code, for each of the remote methods. The remote methods must be specified as function prototypes in the header file. The skeleton routines can be readily used to implement the remote methods in a new SOAP Web Service. Also the input and output parameters of these remote methods, that can contain compound data types, must be declared in the header file. The gSOAP compiler automatically generates serializers and deserializers for the data types to enable the generated skeleton routines to encode and decode the contents of the parameters of the remote methods.

command: soapcpp2 -I/<gsoap-path> gSoapTextService.h

The gSOAP compiler creates the following files:

            
            TextService.wsdl, 
	    soapH.h, 
	    soapTextServiceObject.h, 
	    soapTextServiceProxy.h, 
	    soapStub.h,
	    TextService.nsmap, 
	    soapC.cpp, 
	    soapServer.cpp, 
	    soapServerLib.cpp,
	    soapClient.cpp, 
	    soapClientLib.cpp, 
	    ns.xsd,
	    TextService.processData.req.xml,
	    TextService.processData.res.xml
  

 

 

3) Implementation of the service class
The implementation of the stand-alone service class <gSoapTextService.cpp>. This class owns server functionality.

 
 	#include "soapH.h"
	#include "stdsoap2.h"
	#include "TextService.nsmap"

	...
	main() {
	    struct soap soap;
	        ...
	    // Serverfunktionalität
	    soap_init2(&soap, ..);
	    soap_bind(&soap, ..);
	    soap_accept(&soap);
	    soap_serve(&soap);
	    soap_destroy(&soap);
	    soap_end(&soap);
	    soap_done(&soap);
		...
	}
	
	// Service
	int ns__processData(char ** request, char** response){
	  ...
	}
   

4) Compile the service class
command:
g++ -Wno-deprecated -I/<gsoap-path> -o gSoapTextService gSoapTextService.cpp soapC.cpp soapServer.cpp soapClient.cpp <gsoap-path>/stdsoap2.cpp

 

5) Start the gSOAP Web Service
The gSOAP stand-alone Web Service can be started by the call of the object file.
command: gSoapTextService

 

 

1) Creation of the header file
The header file <cTextClient.h> is identical to <gSoapTextService.h>.Tthis file can be used to create the stub classes. There must be made a namespace replacement.

 

2) Creation of the stub and skeleton classes which are necessary for the client
The implementation of a SOAP client application needs a stub routine for each remote method, that should be called by the client. These classes will be automatically created by the stub and skeleton compiler of the gSOAP library soapcpp2.
command: soapcpp2 -I/<gsoap-path> cTextClient.h

 

3) Implementation of the client class

        
	main() {
	    struct soap soap;
	    soap_init(&soap); 
	
	    // remote call	
	    soap_call_ns__processData(&soap, ..);
		...
	}
   

 

4) Compilation of the client class
command:

g++ -Wno-deprecated -I/<gsoap-path> -o  cTextClient cTextClient.cpp soapC.cpp soapClient.cpp <gsoap-path>/stdsoap2.cpp

 

 

5) Start the gSOAP client
The gSOAP client can be started by the call of an object file.
command: cTextClient -i ExampleOutput_RDF

 

 

The following steps show how an Axis client, that can connect to a gSOAP server, should be created.

1) Creation of the classes of the client side
Create with the WSDL parser WSDL2Java and the WSDL file of the service the stub class for the Java client. Rename the file to JavaTextClient.wsdl.
This replacement must also been made in the WSDL file and the port must be controlled. (port: 1444)

command: java org.apache.axis.wsdl.WSDL2Java JavaTextClient.wsdl

A directory is automatically generated like the adjusted namespace of the WSDL file. The classes (stub, locator and interfaces)are saved there.

 

2) Creation of an own client
The client class is not generated automatically. The following code shows how to call a method of a remote Web Service. The used method name is adjusted in the WSDL file.

 

           // Make a service	
	   TextService service = new TextServiceLocator();

	   // use the service to get a stub which implements the SDI
	   TextServicePortType port = service.getTextService();

	   // make the actual call
	   String response = port.processData(stringdata);
	    ...
	 }
    

 

 

3) Compile the client class <JavaTextClient.java>
command: javac -d build <package-path>JavaTextClient.java

 

4) Start the client
command: java <package-path>JavaTextClient ExampleOutput_RDF

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值