Gsoap compilation and simple use

Source: Internet
Author: User

1. Download gsoap2.8.8.zip from the official website
2. Install gsoap
A): If you extract a gsoap2.8 directory in windows. There is a corresponding
B): Decompress the package in linux to the gsoap2.8 directory and install the package. Installation Steps
./Configure
Make
Make install
Openssl must be installed to install gsoap.

C) I have not installed windows. Directly use the wsdl2h and soapcpp2 tools under the bin directory
After linux is installed, wsdl2h and soapcpp2 can be directly used.
Wsdl2h generate a. h file based on webserveic, and soapcpp2 generate a corresponding call File Based on the. h file.
The two tools are used as follows:
Note 1: wsdl2h usage (WSDL/schema parsing and code generator) wsdl2h [opt] header file name WSDL file name or URL wsdl2h common options
-O file name, specifying the output header file
-N Space prefixes Replace the default ns
-C: generate pure C code; otherwise, it is C ++ code.
-S: Do not use STL code
-T file name, specifying the type map file. The default value is typemap. dat.
-E do not add the namespace prefix to The enum member. The type map file is used to specify the conversion rules between the types in SOAP/XML and C/C ++. For example, write in wsmap. dat
In this example, the following is used:
Wsdl2h-s-o calc.h http://www.cs.fsu.edu /~ Engelen/calc. wsdl
The parameter s indicates that the header file calc. h without the stl c/C ++ syntax structure is generated. If you do not need s, the header file with STL will be generated. In this way, you need to add the STL header stlvector. h to the subsequent compilation, which is located in the: gsoap/import/directory.
NOTE 2: soapcpp2 usage (Compilation and code generator) soapcpp2 [opt] header file name soapcpp2 common options
-C: only generate client code
-S: Generate server code
-L do not generate soapClientLib. c and soapServerLib. c files
-C generates pure C code; otherwise, it is C ++ code (related to header files)
-I: Specifies the import path (see the preceding section)
-X: do not generate XML sample files.
-I generate C ++ encapsulation (proxy), the client is xxxxProxy. h (. cpp), and the server side is xxxxService. h (. cpp ).

D) Example:
I): vi add. h
Add the following content: int ns _ add (int num1, int num2, int * sum );
Ii): soapcpp2-S-x-L-I add. h. Only server files of C ++ are generated.
The following file is generated:
SoapStub. h soapServer. cpp soapH. h soapC. cpp ns. nsmap and other files
Iii) vi addServer. cpp
As follows:
# Include "soapH. h"
# Include "add. h"
# Include "ns. nsmap"
# Include <stdio. h>

Int main (int argc, char * argv [])
{
Int m, s;/* master and slave sockets */
Struct soap add_soap;
Soap_init (& add_soap );
// Soap_set_namespaces (& add_soap, add_namespaces );
If (argc <2)
{
Printf ("usage: % s <server_port> \ n", argv [0]);
Exit (1 );
}
Else
{
M = soap_bind (& add_soap, NULL, atoi (argv [1]), 100 );
If (m <0)
{
Soap_print_fault (& add_soap, stderr );
Exit (-1 );
}

Fprintf (stderr, "socket connection successful: Master socket = % d \ n", M );
For (;;)
{
S = soap_accept (& add_soap );
If (S <0)
{
Soap_print_fault (& add_soap, stderr );
Exit (-1 );
}
Fprintf (stderr, "Socket connection successful: slave socket = % d \ n", s );

Soap_serve (& add_soap); // specifies the server service.
Soap_end (& add_soap );
}
}
Return 0;
}
// The server-side implementation function is the same as the function declared in add. h, but the current soap connection parameter is added.
Int ns _ add (struct soap * add_soap, int num1, int num2, int * sum)
{
* Sum = num1 + num2;
Return 0;
}

Iv): Copy stdsoap2.cpp stdsoap. h under the gsoap-2.8 \ gsoap \ directory to the directory of the project

V): gcc compilation g ++ soapC. cpp soapServer. cpp stdsoap2.cpp addServer. cpp-o addServer
Vi) Run:./addserver to implement a simple server program
G ++ addserer. cpp so

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.