zoukankan      html  css  js  c++  java
  • Creation of a gSOAP Web Service a gSOAP client and an Axis client

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


  • Linux platform
  • C(++) compiler
  • gSOAP 2.7.0 [download]
  • Apache Axis 1.3 [download]
  • Java jdk 1.5

  • 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


  • 相关阅读:
    CORS跨域解决方案
    修改数据库排序规则实践总结
    【转】通俗易懂,什么是.NET?什么是.NET Framework?什么是.NET Core?
    调用远程数据库的T-SQL和SP(SQLSERVER)
    解决在微信网页中百度地图定位不准确的问题
    VUE小知识点
    实现鼠标移过时,显示图片的功能
    实现导出功能
    两数据库表之间迁移插入数据
    IIS配置FTP
  • 原文地址:https://www.cnblogs.com/cy163/p/1521395.html
Copyright © 2011-2022 走看看