Gsoap for Qt (windows), gsoapqt

Source: Internet
Author: User

Gsoap for Qt (windows), gsoapqt

This article has been summarized by myself, and also referred to another online buddy document.

Environment: win32, vs2008, Qt 4.7, gsoap2.7.17

1. Install the vs2008 + Qt 4.7 + plug-in. You can simply use QtCreator.

2. Go to the official website to download gsoap2.7.17. If you cannot find a solution, I will upload it to the group for sharing. However, the group number is not convenient.

Three, source code decompress, and then set the gsoap-2.7/gsoap/bin/win32to the pathpath of the system, this directory has two executable files wsdl2h.exeand soapcpp2.exe, the two files can generate the client interface file you need according to the wsdl interface file.

4. Create a server webserivce test. The following code is used to note:

Open VS2008 and create a WebService project. Use the default settings.

Finally, modify the code and add Chinese characters. As follows:

Namespace WebService1

{

/// <Summary>

/// Summary of Service1

/// </Summary>

[WebService (Namespace = "http://tempuri.org/")]

[WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]

[ToolboxItem (false)]

// To allow ASP. net ajax to call this Web service from a script, cancel the comments to the downstream.

// [System. Web. Script. Services. ScriptService]

Public class Service1: System. Web. Services. WebService

{

 

[WebMethod]

Public string HelloWorld ()

{

Return "Hello World ";

}

}

}

5. Perform client gaosp operations:

1. Create a folder client/gsoap. And copy stdsoap2.cpp and stdsoap2.h under the gsoap-2.7/gsoap/to the created gsoap folder. In addition, you need to test several files gsoap/soapC. cpp, gsoap/soapClient. cpp. If you need to copy them, I will test these files.

2, wsdl2h-I "E:/gsoap/source/gsoap-2.7/gsoap/WS"-s-o test. h http: // localhost: 5925/Service1.asmx? WSDL (adding-s indicates that the stl library is not used)

3, execute soapcpp2-I "E:/gsoap/source/gsoap-2.7/gsoap/import" test. h

4. Compile 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 ()

{

Service1Soapsoap;

Soap_set_mode (soap. soap, SOAP_C_UTFSTRING );

_ Ns1 _ HelloWorldreq;

_ Ns1 _ HelloWorldResponseres;

Soap. _ ns__ HelloWorld (& req, & res );

QStringstr = QString: fromUtf8 (res. HelloWorldResult-> c_str ());

Line-> setText (str );

}

};

 

# Include "test. moc"

 

Int main (intargc, char * argv [])

{

QApplicationapp (argc, argv );

MyDialogmd;

Md. show ();

Return app.exe c ();

 

}

Modify it as needed.

6. soap_set_mode (soap. soap, SOAP_C_UTFSTRING); this sentence is used to display Chinese characters and the string is UTF-8 encoded. When we use the command line program, even if this option is used, Chinese characters are not displayed, because the strings displayed on the command line must be decode into GBK for display.

7. Common soapcpp2 options

  • -CGenerate only client code
  • -S: only generate server code
  • -LDo not generate soapClientLib. c and soapServerLib. c files
  • -CGenerate pure C code, otherwise it is C ++ code (related to the header file)
  • -ISpecify the import path (see the preceding Section)
  • -XDo not generate XML sample files
  • -IGenerate C ++ packaging. The client is xxxxProxy. h (. cpp), and the server side is xxxxService. h (. cpp ).

8. The generated client interface is in the test. h file. You can view the encoding.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.