Qt + GSoAP Access CXF WebService

Content: as the title

Description of requirements: The existing springMvc framework system, which runs business data, and develops a QT interface, needs to call the data of the java system

Ideas: Use cxf to publish the webService interface on the java side Client: Use Gsoap to convert the wsdl file published by cxf into a C++ file, and then call it.

Environment: win10 QT5+ cxf Springmvc

Steps:

One: gsoap installation

Download the gsoap installation file, very simple , It can be used directly after downloading, I downloaded gsoap_2.8.51;

Gsoap configuration environment variables (of course the image is not big, after configuring the environment variables, the subsequent operations are relatively simple)

As shown in the figure below: Add the win32 path of gsoap to the path

Two: Assuming that the webService in the java project can be accessed here (no further explanation here)

Mine can be accessed normally: as shown below:

At this time, it proves that your server is normal.

3: Create a new directory D:\QT\gsoapSource (can be created at will according to the actual situation)

Enter the windows command window
< /p>

cd into the directory created above

cd D:\QT\gsoapSource

Convert the wsdl file into a .h file

Execute the command wsdl2h -o taskInfo.h http://(server ip)/taskTodo/webService/taskInfo?wsdl (the following address is the address of wsdl in the second item)

At this time, in the D:\QT\gsoapSource directory, you will see the generated Now, the taskInfo.h file

At this time, execute the command: soapcpp2 taskInfo.h -IE:\tools\application software\gsoap_2.8.51\gsoap-2.8 \gsoap\import (Note: The import path under the gsoap installation path is specified after -I, which can be changed according to your own situation)

At this time, a bunch of files will be generated in the directory, regardless of whether it is What is it for

At this point, the preparation work has been completed, and the next step is the development of the QT side :

Four: Establish a QT client project (the specific steps will not be described in detail)

The project structure is shown in the figure below:

The main ones are .pro files, widget.h and widget.cpp files.

After generating the project, first create a gsoap folder in the widget.cpp level directory, and move the third step to the end All the files generated under the gsoapSource file except the .xml file are copied to the gsoap folder (some people on the Internet say that it is not necessary to have all of them, here in order to avoid omissions, take them all), in addition, also You need to copy 3 important files (stdsoap2.cpp, stdsoap2.c, stdsoap2.h) under the gsoap installation path to this folder

Next, take a look at the codes of the three files mentioned above in QT

. pro code The value behind LIBS is configured according to your own QT environment

# -------------------------------------------------# # Project created by QtCreator 2017-08-09T17:22:13##---------------------------------- ------ ---------QT += core guiLIBS += C:\Qt\Qt5.6.2\Tools\mingw492_32\i686-w64-mingw32\lib\libws2_32.agreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsTARGET = TestTEMPLATE = appSOURCES += main.cpp\ widget.cpp\ gsoap/stdsoap2.cpp \ gsoap/soapClient.cpp \ gsoap/soapC.cppHEADERS += widget.h\ gsoap/stdsoap2.h \ gsoap/soapStub.h \ gsoap /soapH.hINCLUDEPATH += gsoap

widget.c

#ifndef WIDGET_H#define WIDGET_H#include #include #include class QPushButton;class QLineEdit;class Widget: public QWidget{ Q_OBJECTpublic: Widget(QWidget *parent = 0); ~Widget(); public slots: void OnClicked();private: QPushButton *btn;// QLineEdit *line; QTextEdit *line; QLabel *labelUserName; QLineEdit *editUserName; QLabel *labelPassWord; QLineEdit *editPassWord; QLabel *labelresult;};#endif // WIDGET_H

widget.cpp

#include "widget.h"#include < QPushButton>#include #include #include #include #include #include #include #include "TaskInfoWebServiceSoapBinding.nsmap"Widget::Widget(QWidget *parent): QWidget(parent){ setWindowTitle(tr("Get task information")); setFixedSize(800,500); labelUserName =new QLabel(tr("Username:")); editUserName =new QLineEdit; labelPassWord =new QLabel (tr("Password:")); editPassWord =new QLineEdit; labelresult = new QLabel(tr("Result:")); btn =new QPushButton("Submit"); line = new QTextEdit; connect(btn,SIGNAL( clicked()),this,SLOT(OnClicked())); QGridLayout *layout = new QGridLayout; layout->addWidget(labelUserName,0,0); layout->addWidget(editUserName,0,1); layout->addWidget (labelPassWord,1,0); layout->addWidget(editPassWord,1,1); layout->a ddWidget(labelresult,2,0); layout->addWidget(line,2,1); layout->addWidget(btn,3,0); setLayout(layout);}Widget::~Widget(){}void Widget ::OnClicked(){ struct soap add_soap; soap_init(&add_soap); soap_set_mode(&add_soap,SOAP_C_UTFSTRING); ns1__findUserTaskInfo req; std::string name =editUserName->text().toStdString(); // initialized by assignment std: :string password =editPassWord->text().toStdString(); req.userName=&name; req.passWord=&password; ns1__findUserTaskInfoResponse res; QString str; int result =_call___ns1__findUserTaskInfo(&add_soap,NULL,NULL,&req,res); if (result == SOAP_OK) {// qDebug()<c_str(); str = QString::fromUtf8(res.return_->c_str());} else {str = tr("Failed" );} line->setText(str);}

main.cpp

#include "widget.h"#include int main(int argc, char *arg v[]){ QApplication a(argc, argv); Widget w; w.show(); return a.exec();}

Run the QT project as shown below:


ok, at this point, the end

Note: My webService interface receives two parameters, userName and passWord, and then calls the database Perform verification, return the string data corresponding to the user, and then display it in the QT result box. When testing, you can simply write a test interface to call.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3467 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.