Generally, you can use the soap Toolkit 3.0 SDK provided by Microsoft to write a WebService client in VC. This is convenient and quick, but as you may know, such code deployment is very problematic, you must deploy the machine to install the SDK.
Gsoap is an open-source project that can solve this deployment problem. However, since it is only an open-source project, seamless integration with VC is not an easy task.
Http://www.cs.fsu.edu /~ Engelen/soapdoc2.html is the gsoap guide. It will not be successful if you follow this guide step by step.
IDE version:
Vs2008 (applicable to other versions)
Gsoap version:
Gsoap2.7.12 (applicable to other versions)
1. Environment assumptions:
1) there is a WebService: http: // localhost: 16041/webservice1.asmx, which exposes the Method
[Webmethod]
Public String helloworld ()
{
Return "Hello World ";
}
2) assume that the Win32 console project CLN is generated using the wizard, and the directory c:/code/CLN
3) assume that the gsoap source directory c:/gsoap
2. preparation:
1) create a subdirectory C:/code/CLN/gsoap
2) Copy wsdl2h.exe,soapcpp2.exe to C:/code/CLN/gsoap. The 2 file can be found in C:/gsoap/bin/Win32.
3) Copy stdsoap2.h, stdsoap2.cpp to C:/code/CLN/gsoap. The 2 files are in the C:/gsoap root directory.
3. wsdl2h.. h
Run the command line to enter C:/code/CLN/gsoap.
Wsdl2h-I "C:/gsoap/WS"-O test. h http: // localhost: 16041/webservice1.asmx? WSDL
This operation will generate C:/code/CLN/gsoap/test. h
4. soapcpp2 compilation. cpp
Soapcpp2-I "C:/gsoap/import" test. h
5. Integrated CLN project Compilation
Add soapc. cpp, soapclient. cpp, and stdsoap2.cpp to the project, right-click the three CPP files, and remove the pre-compilation header. Otherwise, the project cannot be compiled normally.
CLN. cpp source code
# Include "stdafx. H"
# Include "gsoap/soapwebservice1soapproxy. H"
# Include "gsoap/webservice1soap. nsmap"
Int _ tmain (INT argc, _ tchar * argv [])
{
Webservice1soap S;
_ NS1 _ helloworld request;
_ NS1 _ helloworldresponse response;
S. _ ns__ helloworld (& request, & response );
Return 0;
}