Because I write the project using C + + to call C # to write the background server published WebService, so took a little time to collate the relevant knowledge as follows
gSOAP is a tool that binds soap/xml to the C/s + + language, and uses it to quickly and easily develop Soap/xml server side and client. Because gSOAP has quite good compatibility, through gSOAP, we can invoke SOAP services developed by Java,. Net, Delhpi, PHP, and so on, or provide them with soap services
Download the installation package
gSOAP home: HTTP://SOURCEFORGE.NET/PROJECTS/GSOAP2
After downloading the extract, you can find Wsdl2h.exe and Soapcpp2.exe in Gsoap\bin\win32 (plus Linux and Mac versions).
- The role of Wsdl2h.exe is to generate a C + + style header file based on WSDL
- The role of Soapcpp2.exe is to automatically generate the client code (called stub: Stub) that invokes the remote SOAP service and the framework code that provides the SOAP service (called the Framework: Skeleton) based on the header file, and it can also generate a WSDL file from the scratch file
After the interface of the server is written. Write the client code again. Before writing the client's code, make the necessary CPP and header files from the two tools and WSDL files that you just created.
First run, CMD, then open Gsoap\bin\win32, run Wsdl2h.exe
Usage:
Wsdl2h-o header file name WSDL file name or URL example: Wsdl2h-o test.h Http://localhost:2488/Service1.asmx?WSDL can see a Win32 file in Test.h.
Win32 inside a header file test.h, run Soapcpp2.exe in the command line
Usage: Soapcpp2.exe header file name
SOAPCPP2 Common Options
- -C Generate client code only
- -s generate server-side code only
- -L Do not generate SOAPCLIENTLIB.C and SOAPSERVERLIB.C files
- -C Generate pure C code, otherwise C + + code (related to header file)
- -I Specify the import path (see above)
- -x do not generate an XML sample file
- -I generates C + + wrappers, the client is XxxxProxy.h (. cpp), and the server side is xxxxService.h (. cpp).
Example: Soapcpp2.exe-c test.h
If error: Critical error: #import: Cannot open File "Stlvector.h" for reading.
Hint:use option-i<path> (You can define multiple paths separated with '; ')
To specify the gSOAP import file path using the-i option, this path is "$gsoap \gsoap\import":
Soapcpp2.exe-c test.h-i D:\work\gsoap_2.7.13\gsoap-2.7\gsoap\import
This time the Win32 directory will have a lot of files generated.
Will Service1soap.nsmap,soapc.cpp,soapclient.cpp,soaph.h,soapstub.h,
And the Stdsoap2.h,stdsoap2.cpp in the gSOAP project root directory, a total of seven files are added to client project, and then the code is added:
#include "Service1soap.nsmap"
Modify Soapc.cpp,soapclient.cpp,stdsoap2.cpp compile condition to not require precompiled header file, gSOAP does not need MFC.
The preparations are all done by now. Please write the client program according to your own needs.
is actually called the server-side Web method.
The following is a word of his command:
, there are two main commands.
wsdl2h command:
This command is used to generate a C + + header file from a WSDL file
Wsdl2h-o header file name WSDL file name or URL |
Other common parameters:
-o file name, specifying output header file
The-n namespace prefix replaces the default NS
-C generates a pure code, otherwise C + + code
-S do not use STL code
-t file name, specifying type map file, default = Typemap.dat
-e prohibit namespace prefixes for enum members
SOAPCPP2 command:
This command is used to generate the SOAP server and client code from the scratch file, and also includes WSDL, test XML data.
Common options
-C generates only client code
-S generates server-side code only
-L do not generate SOAPCLIENTLIB.C and SOAPSERVERLIB.C files
-C generates a pure code, otherwise C + + code (related to header file)
-I specify the import path (see above)
-X do not produce an XML sample file
-I generates a C + + wrapper, the client is XxxxProxy.h (. cpp), and the server side is xxxxService.h (. cpp).
List of generated files:
SoapStub.h modified and commented header files generated from the header file
SoapH.h header files referenced by client and server-side source files
SOAPC.C serial number and anti-serial number file for a specific data structure
Client stub routine file for Soapclient.c remote method
Stdsoap2.h header file for STDSOAP2 Runtime library
Stdsoap2.cpp run-time C + + XML parser and run-time Support example libraries
********************************************************************************************
How to configure a Mac environment
Download gSOAP source code
Extract:
$ unzip Gsoap_2.8.17.zip
Compile:
$ CD gsoap-2.8/
$ configure
$ make
$ sudo make install
Use of gSOAP (call WebService interface)