Decompress gsoap2.8 and generate the C/C ++ header file using the WSDL document. Run the gsoap-2.8/gsoap/bin/linux386/wsdl2h-O soapphp. h service. WSDL to copy gsoap. Source code Stlvector in the import folder. h file to testheader. h. in the same directory, if the-S parameter is used when parsing the WSDL document, that is, if STL is not used, the file does not need to be copied. Gsoap-2.8/gsoap/bin/linux386/soapcpp2-C soapphp. h: soapcpp2-I-X-c-l Calc. h. nsmap ,. H and. CPP file, such as calc. nsmap, soapc. CPP, soaph. h. soapstub. h. soapcalcproxy. CPP, soapcalcproxy. h. Purpose of this step: To generate the corresponding underlying communication Code . ---------------------------------------------------------------------- 1 is generated through the WSDL file. use wsdl2h-O header file name or urlwsdl2h common options-o file name, specify the output header file-n Space prefix instead of the default NS-C to generate pure C code. Otherwise, C ++ code-s should not use STL code-T file name, specify the type map file, the default value is typemap. dat-e prohibits Enum members from adding the namespace prefix type map file to specify the conversion rules between types in soap/XML and C/C ++, such as in wsmap. write 2. usage of CPP/C files required for generating hfiles soapcpp2 header file example: soapcpp2 ayandy. h will generate the following soapstub files. h // The soap stub file, which defines ayandy. h The corresponding Remote Call model soapc. c soaph. h // soap sequence and anti-sequence code, which already contains soapstub. h. Both the server and client must contain soapclient. c soapclientlib. C // client code, soapclientlib. the C file simply contains soapclient. C and soapc. csoapserver. c soapserverlib. C // server code, soapserverlib. the C file simply contains soapserver. C and soapc. cservicesoap. nsmap servicesoap12.nsmap // namespace definition. Both the server and client must contain soapservicesoapproxy. h soapservicesoap12proxy. h // C ++ simple packaging of the client (if the header file is pure C code, these two files will not be generated) In summary, if you write the server side, the project Should be added to soapserverlib. c. The Code contains the header file soaph. h if you write a client, add soapclientlib to the project. c. The Code contains the header file soaph. H (or xxxxproxy. h) Of course, you need to add the stdsoap2.cpp file in the gsoap Library (if you are writing C code, add stdsoap2.c). If you see the soapcpp2 prompt: "critical error: # import: cannot open file" stlvector. H "for reading. "That's because our header file uses STL (the-s option is not used for wsdl2h). In this case, use the-I option to specify the import file path of gsoap, the path is "$ gsoap \ import": soapcpp2 ayandy. h-I d: \ gsoap-2.7 \ gsoap \ importsoapcpp2 common options-C only generate client code-s only generate Service Do not generate soapclientlib. C and soapserverlib. c file-C generates pure C code, otherwise it is C ++ code (related to the header file)-I specifies the import path (see the above) -X do not generate xml sample file-I generate C ++ packaging, the client is xxxxproxy. H (. CPP), and the server side is xxxxservice. H (. CPP ). Instance PHP server <? Class Service { Public Function runserver ($ A, $ B ){ Return $ A. $ B. "KKK "; } $ Server = new soapserver ('service. WSDL '); $ server-> setclass ("service"); // register all methods of the service class $ server-> handle (); // process requests?> C ++ Client # include <iostream> # include "Soap/servicesbinding. nsmap "# include" Soap/soapservicesbindingproxy. H "using namespace STD; void soapclient () {// load servicesbinding. nsmap and soapservicesbindingproxy. h file servicesbindingproxy servicebinding; char * iresult; If (servicebinding. runserver (null, null, "I 'am", "Rooney", iresult) = soap_ OK) {cout <iresult <Endl ;} else {cout <"yes" <Endl;} return;} int main () {soapclient (); Return 0 ;} // solve the problem of file garbled characters in C ++ calling PHP *** proxy. add soap_set_mode (soap, soap_c_utfstring) to the Calling Interface of CPP. For example: int servicesbindingproxy: runserver (const char * endpoint, const char * soap_action, char * a, char * B, char * & runserver ){ Struct soap * soap = this; Struct NS1 _ runserver soap_tmp_ns1 _ runserver; Struct NS1 _ runserverresponse * soap_tmp_ns1 _ runserverresponse; If (endpoint) Soap_endpoint = endpoint; If (! Soap_endpoint) Soap_endpoint = "http: // localhost/services. php "; If (! Soap_action) Soap_action = "urn: Services # service # runserver "; Soap-> encodingstyle = "http://schemas.xmlsoap.org/soap/encoding "; Soap_tmp_ns1 _ runserver. A =; Soap_tmp_ns1 _ runserver. B = B; Soap_begin (SOAP ); Soap_serializeheader (SOAP ); Soap_serialize_ns1 _ runserver (soap, & soap_tmp_ns1 _ runserver ); Soap_set_mode (soap, soap_c_utfstring); // Add a statement ----------- If (soap_begin_count (SOAP )) Return soap-> error; If (soap-> mode & soap_io_length) { If (soap_envelope_begin_out (SOAP )......}
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.