I. Environment preparation
In this article, all programs are developed in Linux and can run normally after testing.
In the development process, we need to use gsoap, can download from the following URL: http://www.cs.fsu.edu /~ Engelen/soap.html
What I download is gsoap_2.7.12.tar.gz.
Download and decompress the package. Compile and install the package according to the normal installation process.
# Tar zxvf gsozp_2.7.12.tar.gz
# Cd gsoap_2.7.12
#./Configure -- prefix =/usr/local/gsoap (specify the installation path)
# Make
# Make install
Ii. Generate Related Files
1. Generate the C/C ++ header file through the WSDL document
# /usr/local/gSOAP/bin/wsdl2h.exe -c -o calc.h http://www.genivia.com/calc.wsdl
2. Copy the stdsoap2.c and stdsoap2.h files in the SRC folder in the gsoap source code to the same directory of calc. h.
3. parse the Calc. h file and generate the stub program.
# /usr/local/gSOAP/bin/soapcpp2 –c –C calc.h
The-C parameter in the Command generates the Standard C program. If this parameter is not provided, the C ++ program is generated.
In the command, parameter-C indicates that only the client program is generated. If this parameter is not provided, the client and server program are generated by default.
3. Conduct related development
1. Create a project
Create a new C file for testing. The code is shown in figure 2.
2. Code Development
For more information about how to call WebService, see the generated soapstub. h file.
DEMO code (call WebService add ):
#include "soapH.h"#include "calc.nsmap"main(){ struct soap *soap = soap_new(); double result; if (soap_call_ns2__add(soap, NULL, NULL, 1.0, 2.0, &result) == SOAP_OK) printf("The sum of 1.0 and 2.0 is %lg\n", result); else soap_print_fault(soap, stderr); soap_end(soap); soap_free(soap);}
After compilation and running, you can view the processing result returned by WebService on the console.
4. Compile the Code:
# Gcc-O addtest. c soapc. c soapclient. c stdsoap2.c