This article through its own practice summary, at the same time refer to the other online buddy document.
Environment: WIN32,VS2008,QT 4.7,gsoap2.7.17
First, install VS2008+QT 4.7+ plug-in will not say, directly with Qtcreator can also.
Second, to the official website download gsoap2.7.17, under not to own way, I uploaded the group to share. But the group number is not convenient to say.
Third, the source decompression, and then set the GSOAP-2.7/GSOAP/BIN/WIN32 to the system path, the directory has two executables Wsdl2h.exe and Soapcpp2.exe, These two files can generate the client interface files you need based on the WSDL interface file.
Four, establish the server Webserivce test, the following code to take note:
Open the VS2008 and set up the WebService project. All with the default settings.
Finally change the code, add a bit of Chinese. As follows:
namespace WebService1
{
/// <summary>
/// Service1 Summary description of
/// </summary>
[WebService(Namespace ="http://tempuri.org/")]
[webservicebinding(conformsto =wsiprofiles. Basicprofile1_1)]
[ToolboxItem(false)]
// to allow the Web service to be called from the script using ASP. NET AJAX, uncomment the downstream.
//[system.web.script.services.scriptservice]
Public class Service1 : System. Web. Services. WebService
{
[WebMethod]
Public string HelloWorld ()
{
return "Hello World Hello ";
}
}
}
Five, perform client GAOSP operation:
1. Create a folder Client/gsoap. and copy the Stdsoap2.cpp and stdsoap2.h under the gsoap-2.7/gsoap/to the gSOAP folder you just created. In addition to test several documents Gsoap/soapc.cpp, Gsoap/soapclient.cpp, have the need to continue to copy, I test on these few enough.
2,wsdl2h–i "E:/gsoap/source/gsoap-2.7/gsoap/ws"-s-o test.h Http://localhost:5925/Service1.asmx?WSDL (plus-s means not using STL libraries)
3, execute Soapcpp2-i "E:/gsoap/source/gsoap-2.7/gsoap/import" test.h
4. Write the Test.cpp file
#include <QApplication>
#include <QPushButton>
#include <QLineEdit>
#include <QHBoxLayout>
#include <QDialog>
#include "Gsoap/service1soap.nsmap"
#include "Gsoap/soapservice1soapproxy.h"
class mydialog: public qdialog
{
Q_object
Public:
Mydialog (qwidget *parent=0):qdialog(parent)
{
btn=newQpushbutton("invoke");
line = new qlineedit;
Connect (btn,SIGNAL(clicked()),This,SLOT(onclicked()));
qhboxlayout*Layout =newqhboxlayout;
layout,addwidget(line);
layout--addwidget(btn);
setlayout (layout);
}
Private:
Qpushbutton*btn;
qlineedit*Line;
Public Slots:
void onclicked ()
{
Service1Soap soap;
Soap_set_mode (soap. soap,soap_c_utfstring);
_ns1__helloworld req;
_ns1__helloworldresponse Res;
soap. __ns2__helloworld (&req,&res);
QString str =QString::fromUtf8(res. Helloworldresult,c_str());
Line-setText(str);
}
};
#include "Test.moc"
int Main (intargc,Char* argv[])
{
qapplication app (argc,argv);
Mydialog MD;
MD. Show ();
return app. exec ();
}
Modify it yourself as needed.
Six, Soap_set_mode (Soap.soap, soap_c_utfstring); This sentence is to display the Chinese language, so that the string using UTF8 encoding. When we use the command-line program, even if the use of this option is not displayed in Chinese, because the command line display string must be decode into GBK to display.
Seven, soapcpp2 common options
- - 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 a C + + wrapper, the client is XxxxProxy.h (. cpp), and the server side is xxxxService.h (. cpp).
Eight, the generated client interface in the Test.h file, you can view the encoding.
gSOAP for Qt (Windows)