Use the C/C ++ program to call WebService through gsoap

Source: Internet
Author: User

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

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.