Gsoap: C/C ++ Web Services and clients |
Gsoap: User Guide |
Creation of a gsoap Web Service A gsoap client and an axis Client |
Table of contents
- Conditions to create gsoap Web Services
- Creation of a gsoap Web Services
- Build a gsoap Client
- Build an axis Client
Conditions to create gsoap Web Services
Linux platform
C (++) compiler
Gsoap 2.7.0 [Download]
Apache axis 1.3 [Download]
Java JDK 1.5
Creation of a gsoap Web Service
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 shoshould 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:TextServiceint 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 in 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);...}// Serviceint ns__processData(char ** request, char** response){ ...}
4)Compile the service class
Command:
G ++-wno-deprecated-I/<gsoap-path>-O 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
Build a gsoap Client
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 shocould 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
Build an axis Client
The following steps show how an axis client, that can connect to a gsoap server, shocould 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
Table of contents
|
Dfki GmbH German Research Center for artificial intelligence |