【WebService学习】用思维导图和实例学习Web Service

作者:gnuhpc
出处:
http://www.cnblogs.com/gnuhpc/

1.SOAP消息:

clip_image002[4]

clip_image004[4]

clip_image006[4]

2.WSDL

clip_image008[4]

clip_image010[4]

clip_image012[4]

3.Web Service

clip_image014[4]

4.实例:

1Eclipse 以及Ant建立一个简单的Web Service,以演示Web Service的基本开发过程:http://blog.csdn.net/gnuhpc/archive/2009/12/22/5047951.aspx

2QT SOAP 的一个实例:

开始学习时,看到网上有朋友说这个库难用,我觉得还好吧,蛮好使的,下边写一个例子。

今天早上写的,远程访问这个http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx?op=getStockInfoByCode Web service,获得股票信息。

简单了拖拽了一个界面,如下:

clip_image016[4]

具体代码如下,几个关键的地方我用黑体加粗进行了注释:

main.cpp:

#include
#include "stockws.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    StockWS w;
    w.show();
    return a.exec();
}

stockws.cpp:

#include "stockws.h"
#include

StockWS::StockWS(QWidget *parent, Qt::WFlags flags)
    : QMainWindow(parent, flags), http(this)
{
    ui.setupUi(this);
    ui.idline;
    connect(&http, SIGNAL(responseReady()), SLOT(getResponse()));
    connect(ui.idline, SIGNAL(returnPressed()), SLOT(submitRequest()));
    connect(ui.RequestStock, SIGNAL(clicked()), SLOT(submitRequest()));
    http.setAction("/"
http://WebXml.com.cn/getStockInfoByCode/"");//
设置SOAPACTION
    http.setHost("webservice.webxml.com.cn");//
设置
HOST

}

StockWS::~StockWS()
{

}

void StockWS::submitRequest()
{
    QtSoapQName name;

    // Check that ID is provided or not
    if (ui.idline->text() == "") {
        QMessageBox::warning(this, tr("Missing Stock ID"),
            tr("Please Enter the Stock ID for query"));
        return;
    }

    // Generate request. Details about how to generate a proper

    QtSoapMessage request;
    request.setMethod(QtSoapQName("getStockInfoByCode", "
http://WebXml.com.cn/"));//
设置方法和所在命名空间=>xmlns=http://WebXml.com.cn/
    request.addMethodArgument("theStockCode", "", ui.idline->text()); // 设置方法的参数

    // Submit the method request to the web service.
    http.submitRequest(request, "/WebServices/ChinaStockWebService.asmx"); //
设置POST字段

    // Set the cursor to wait mode.
    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
}

void StockWS::getResponse()
{
    int i;
    // Set cursor back to normal shape.
    QApplication::restoreOverrideCursor();

    // Reset resultView.
    ui.stockResult->clear();

    // Get the response, check for error.
    const QtSoapMessage &resp = http.getResponse();
    if (resp.isFault()) {
        ui.stockResult->setText((resp.faultString().value().toString()));
        return;
    }

    // Extract the return value from this method response, check for
    // errors.
    const QtSoapType &res = resp.returnValue();
    if (!res.isValid()) {
        ui.stockResult->append("Invalid return value");
        return;
    }

    ui.stockResult->setText(res[0].toString());
    for (i=0;i
    {
        ui.stockResult->append(res[i].toString()+"/n");
    }

}

 

 

输入一个股票:sh500006,基金裕阳的股票代码,稍等片刻就得到如下结果:

clip_image018[4]

3gsoap使用:

我想起三月份的时候拿GsoapLibfetion写了一个获取股票实时信息并且发短信指定人的例子,基本功能都实现了,有时间具体完善一下后放上来~

作者:gnuhpc
出处:
http://www.cnblogs.com/gnuhpc/

 

 


               作者:gnuhpc
               出处:http://www.cnblogs.com/gnuhpc/
               除非另有声明,本网站采用知识共享“署名 2.5 中国大陆”许可协议授权。


分享到:

原文地址:https://www.cnblogs.com/gnuhpc/p/2811933.html