Creation of a gSOAP Web Service a gSOAP client and an Axis client
2009-07-11 13:50
423 查看
gSOAP: C/C++ Web Services and Clients |
gSOAP: User Guide |
Creation of a gSOAP Web Service a gSOAP client and an Axis client |
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 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
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 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
Build an Axis client
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
Table of contents | DFKI GmbH German Research Center for Artificial Intelligence |
相关文章推荐
- Creation of an Axis Web Service and a gSOAP client
- Java-WebService Exception axis client error Bad envelope tag: definitions
- 【转】gsoap/C++/C 与Axis/JAVA webservice互操作的若干问题总结及持续整理
- [文章笔记]Web Service Discovery and Client Goals(Computers, 2009)
- Interoperable WSDL faults in gSOAP and Apache Axis webservices
- Automating the Configuration of the Firewall Client:Firewall Client and Web Browser Configuration
- How to: Send and Receive Large Amounts of Data to and from a Web Service
- Luxury brand and the pursuit of value creation is an art
- .NET SOAP Web Service client and Borland SOAP server
- UTL_HTTP Call a Web Service and Pass Parameters as Part of the URL
- gSoap开发webservice&nbsp;client
- [论文笔记] A service creation environment based on end to end composition of Web services (WWW, 2005)
- [论文笔记] Quality-of-service oriented web service composition algorithm and planning architecture (JSS, 2008)
- A simple of Using XML Data Source type and Querying a Web Service with Reporting Services 2008
- Web Service That Returns An Array of Objects With KSOAP
- UTL_HTTP Call a Web Service and Pass Parameters as Part of the URL
- Develop an Apache HttpClient client for Android to a JAX-RS web service
- use python and django make an web service
- UTL_HTTP Call a Web Service and Pass Parameters as Part of the URL