1. gSOAP is an open source project that makes it easy to do SOAP client and server-side programming with C + +, without having to understand the details of XML and SOAP protocols
Wsdl2h.exe: Compiling a WSDL file to generate A/C + + header file
-o file name, specifying output header file
The-n namespace prefix replaces the default NS
-C generates a pure code, otherwise C + + code
-S do not use STL code
-t file name, specifying type map file, default = Typemap.dat
-e prohibit namespace prefixes for enum members
Soapcpp2.exe:gSOAP compiler, the compiler header file generation server and the client-side both the C + + files required (using STL by default, requires Stlvector.h)
-C generates only client code
-S generates server-side code only
-L do not generate SOAPCLIENTLIB.C and SOAPSERVERLIB.C files
-C generates a pure code, otherwise C + + code (related to header file)
-I specify the import path (see above)
-X do not produce an XML sample file
-I generates C + + wrapper, client is XxxxProxy.h (. cpp), server side is xxxxService.h (. cpp)
2. Generating the Memory client stub program and framework
Wsdl2h-o xx.h http://192.168.40.8:88/GMM?wsdl
or Wsdl2h-o xx.h http://js.gps163.com:8994/Server/CsService.svc?wsdl
Soapcpp2-c-l-x-I xx.h (soapcpp2 xx.h-c-i D:\gsoap-2.7\gsoap\import)
3. Add the following generated files to the project:
Soapstub.h,soaph.h,stdsoap2.h
Soapc.cpp,soapclient.cpp,stdsoap2.cpp
Soapbasichttpbinding_uscoreigmmproxy.cpp
Soapbasichttpbinding_uscoreigmmproxy.cpp
Basichttpbinding_uscoreigmm.nsmap
Wsock32.lib
4. Call
#include "Soapbasichttpbinding_uscoreigmmproxy.h"
#include "Basichttpbinding_uscoreigmm.nsmap"
Proxy mode call does not require initialization
struct SOAP Xxsoap;
Soap_init (&XXSOAP);
Proxy class object
Xxwebservicesoap Xxproxy;
Set Header information
Soap_env__header Envheader;
Xxproxy.soap->header = &envHeader;
Web Service object
_ns1__xx xx;
Web Service Result Object
_ns1__xxresponse Xxresponse;
Calling the WebService method
5. Examples of use:
1CString Cgetlocation::getlocation (intIlon,intIlat)2 {3CString straddress = _t ("");4 5 structsoap Soap1;6Soap_init (&soap1);7Soap_set_mode (&Soap1, soap_c_mbstring);8 9 basichttpbinding_uscoreigmmproxy Locationservice (SOAP1);Ten One _ns3__getlocation GetLocation; A _ns3__getlocationresponse getlocationres; - - BOOLBloffset =false; theGetlocation.latitude = &Ilat; -Getlocation.longitude = &Ilon; -Getlocation.bloffset = &Bloffset; - + intNOK =-1; - + Try A { atNOK = Locationservice.getlocation (Strwcfurl.c_str (), NULL, &getlocation, &getlocationres); - } - Catch (...) - { - CString Strlog; -Strlog.format (_t ("GetLocation Try Catch error:%d\r\n"), GetLastError ()); in TRACE (strlog); - returnstraddress; to } + - the if(NOK! =SOAP_OK) * { $ Charszerror[255] = {0};Panax NotoginsengSoap_sprint_fault (&soap1, Szerror,255); - the CString Strlog; +Strlog.format (_t ("SOAP Error:%s\r\n"), szerror); A TRACE (strlog); the returnstraddress; + } - $ if(Getlocationres.getlocationresult = = NULL | | (*getlocationres.getlocationresult). Empty ()) $ { - CString Strlog; -Strlog.format (_t ("SOAP result:error\r\n")); the TRACE (strlog); - returnstraddress;Wuyi } the -straddress = (*getlocationres.getlocationresult). C_STR (); Wu returnstraddress; -}
C + + Call WebService