Gsoap is a cross-platform implementation of soap communication.Source codeLibrary. This is my incomplete understanding of this open-source project. This is what we can introduce, and there may be errors.
Because I am working on a project with my colleagues, I need to use C ++ to communicate with the WebService published by ASP. NET on the client. So I started to study this library these days. The example was implemented yesterday.ProgramBecause I am familiar with ASP. NET, I can only keep the communication with the WebService published by ASP. NET to this day. In the evening, I checked the simple application of ASP. NET. Even if I encountered some problems, I established an ASP. NET Server. No write rowCodeVS is used to think of the generated code. Because it is only used as an example, it is not intended to change the code.
To implement the communication between ASP. NET WebService and gsoap, websites built by ASP. NET are indispensable. I am also a newbie in ASP. NET, so I use the generated code. I will not introduce how to create a course. If there are people like me, please refer to my previous articleArticleI encountered some problems in accessing the IIS metadatabase and running WebService for the first time.
After the website is created, you must publish the website. For example, you can view the WebService at http: // localhost/soap/service. asmx. In the browser, We can enter http: // localhost/soap/service. asmx? To obtain the WSDL file. Save the WSDL file with the WSDL extension name.
To gsoap official website http://www.cs.fsu.edu /~ Download the latest gsoap version from Engelen/soap.html. You can upload wsdl2h.exeand soapcpp.exe tools in the binfolder.
Wsdl2h.exe can generate a. h file based on a wsdl file. Assume that the name of the WSDL we saved is WebService. WSDL. Enter wsdl2h.exe service. WSDL in the command line. In this way, the corresponding. h file is generated. Then soapcpp.exe generates the corresponding code file based on this. h file. Soapcpp.exe-I WebService. h. nsmap, soapc. CPP, soaph. h, soapservicesoapproxy. h, soapservicesoapproxy. CPP, soapstub. h. These files are required to build the gsoap client. I do not know what other files are used for. If you have any knowledge, I hope you can give me some advice. In addition to these files, we also need to find two files: stdsoap2.h and stdsoap2.cpp. After finding all the files, we need to add these files to the project.
Finally, we need to write a client program. Its function is to obtain the "Hello word" string on the server. Its simple code is as follows:
Code
# Include " Stdafx. h "
# Include"Soapservicesoapproxy. h"
# Include"Servicesoap. nsmap"
Const CharServer []= "Http: // localhost/soap/service. asmx";
IntMain (IntArgc,Char **Argv)
{
Printf ("Getting Hello World words! \ N");
Servicesoapproxy soapservice;
Soapservice. soap_endpoint=Server;
_ NS1 _ helloworld input;
_ NS1 _ helloworldresponse output;
Soapservice. helloworld (&Input,&Output );
Printf ("% S", Output. helloworldresult->C_str ());
Return 0;
}
Then we run the code and the following characters will appear: