What is gSOAP?
The gSOAP compilation tool provides a soap/xml implementation of the C + + language, making it much easier to develop a Web service or client program in the C/D + + language. The vast majority of the C++web Service Toolkit provides a set of API function class libraries to handle specific SOAP data structures, which makes it necessary for users to change the program structure to fit the relevant class library. In contrast, gSOAP uses compiler technology to provide a transparent set of soap APIs and hides content related to the development-agnostic SOAP implementation details to the user.
Simply put, one of the gSOAP functions is to help us to invoke the Web Service using C + +.
Download gSOAP
gSOAP's official website is:
Http://www.cs.fsu.edu/~engelen/soap.html
can go to
Http://sourceforge.net/projects/gsoap2/?source=typ_redirect Download gSOAP
The download is a ZIP package, the following path is extracted:
The Gsoap/bin directory is a development tool for different systems.
client code generation and invocation steps
1. Start with the WSDL on the server (if you already have an address, you can save the WSDL in the browser)
This assumes that the WSDL file name is TEST.WSDL
2. Using Wsdl2h.exe, generate a header file based on the WSDL (such as test.h), this is a temporary file, the next step after the execution of automatic deletion!
Command:
Wsdl2h.exe-c-e-o test.h test.wsdl
3. Using Soapcpp2.exe to generate the client calling code, Soapcpp2.exe is a precompiled compiler that can generate the C + + source required to build a C + + SOAP client.
(after generating the code test.h is useless, can be deleted directly)
Command:
Soapcpp2.exe- C test.h
-C: Generate only client code
Take a look at the resulting file structure:
The red boxes are the ones that are newly created.
Green section for Web service-related files
XXXSoapBinding.nsmap:namespaces declaration, need to be included in a CPP file, such as put in StdAfx.cpp inside, otherwise connected times wrong: unresolved external symbol _namespaces
When actually called, in the. c file that is called
Method of//call Web service #include "soapStub.h" #include "soapH.h" #include "Xxxsoapbinding.nsmap"
The method that is called is generated in the SoapStub.h header file.
It can also be packaged as a static link library such as libsoa.a to use.
Two commands:
Cc-c libsoa.c soapc.c soapclient.c stdsoap2.c
AR r libsoa.a libsoa.o soapc.o SOAPCLIENT.O stdsoap2.o
STDSOAP2.H,STDSOAP2.C in the downloaded gSOAP directory
other
If you are developing a more Web service, name space is more, and there may be some confusion.
You can specify a fixed prefix at this time
Create a new Typemap.dat file
The contents are as follows:
ns1 = "Http://XXX" ns2 = "http://XXXXX2" NS3 = "http://XXXXXX3" ns4 = "Http://XXXXXX4"
Add a parameter to the. h,. c file when the command is generated, for example, for. H.
Wsdl2h.exe-t./typemap.dat-c-e-o test.h
gSOAP Implementing a C + + call to a Web service