首先需要下载QtSoap开源包,下载地址为:
我使用的是:qtsoap-2.6-opensource(不需要安装,直接解压到某个目录即可)。
   如果你从未使用过QtSoap,那么先学习其中的Demo,在目录"examples"中,有easter,google和population 三个例子。
 
Note to Qt Visual Studio Integration users: In the instructions below, instead of building from command line with nmake, you can use the menu command 'Qt->Open Solution from .pro file' on the .pro files in the example and plugin directories, and then build from within Visual Studio.
如果是使用的的是VS+Qt开发方式,在使用菜单中的"Qt→Open Qt Project File (.pro)... 来打开以上工程文件。
 
    本人使用的是VS2010,在采用以上方法时,仍然无法正常载入,于是我先用VS2005打开,在VS2005里对以上项目进行保存,再在VS2010里重新打开,当然在VS2010里重新打开时会提示需要进行格式转换,成功后你就可以编译运行Demo了。
 
本人先重写了:population,主要是为了熟悉下QtSoap以及开发配置。
 
1 在头文件(xxx.h)定义变量(XXX为类名,请您重新定义)。
 
#include
class QTextEdit;
 
private slots:
    void getResponse();
private:
    QTextEdit   *m_pWeatherEdt;
private:
    QtSoapHttpTransport http;
 
2 在类的构造函数中:
    m_pWeatherEdt = new QTextEdit(this);
    connect(&http, SIGNAL(responseReady()), SLOT(getResponse()));
 
3 请求发送:
void XXX::submitRequest()
{
    http.setHost("www.abundanttech.com");
    QtSoapMessage request;
    http.setAction  ("http://www.abundanttech.com/WebServices/Population/getPopulation");
    request.setMethod("getPopulation", "http://www.abundanttech.com/WebServices/Population");
    request.addMethodArgument("strCountry", "", "china");
    http.submitRequest(request, "/WebServices/Population/population.asmx");
 }
 

如下:

SOAP

The following is a sample SOAP request and response. The placeholders shown need to be replaced with actual values.

POST /WebServices/Population/population.asmx HTTP/1.1
Host: www.abundanttech.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.abundanttech.com/WebServices/Population/getPopulation" string
当然,你也可以使用“中国气象局”的web services来做测试示例
void XXX::submitRequest()
{
    http.setHost("www.ayandy.com");
    QtSoapMessage request;
    http.setAction("http://tempuri.org/getSupportProvince");
    request.setMethod("getSupportProvince", "http://tempuri.org/");
    http.submitRequest(request, "/Service.asmx");
 }
以上参数请查看:http://www.ayandy.com/Service.asmx如下:

SOAP 1.1

以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。

POST /Service.asmx HTTP/1.1
Host: www.ayandy.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/getSupportProvince"
 
4 回复解析:
void XXX::getResponse()
{
    // Get a reference to the response message.
    const QtSoapMessage &message = http.getResponse();
    // Check if the response is a SOAP Fault message
    if (message.isFault()) 
    {
        m_pWeatherEdt->append(message.faultString().value().toString().toLatin1().constData());
    }
    else 
    {
        // Get the return value, and print the result.
        const QtSoapType &response = message.returnValue();
        m_pWeatherEdt->append(response["Country"].value().toString().toLatin1().constData());
        m_pWeatherEdt->append(response["Pop"].value().toString().toLatin1().constData());
        m_pWeatherEdt->append(response["Date"].value().toString().toLatin1().constData());
    }
}

以上方法只能解析固定类型的消息,下面介绍一种通用方法:

void XXX::getResponse()
{
    // Get a reference to the response message.
    const QtSoapMessage &message = http.getResponse();
    // Check if the response is a SOAP Fault message
    if (message.isFault()) 
    {
        m_pWeatherEdt->append(message.faultString().value().toString().toLatin1().constData());
    }
    else 
    {
        const QtSoapType &root = message.returnValue();
        QtSoapStruct myStruct((QtSoapStruct&)root);
        //将返回的结构体转换成QtSoapStruct
        for (int i = 0; i < myStruct.count(); i++)
        {
            m_pWeatherEdt->append(myStruct[i].typeName() + " : " + myStruct[i].toString());
        }   
    }
}
 
 
http://blog.chinaunix.net/uid-20718335-id-364410.html

QtSoap开发web services客户端程序的更多相关文章

  1. Qt 开发WEB Services客户端代码(使用gSoap)

    1.   首先下载gSoap开发包 http://sourceforge.net/projects/gsoap2  目录包含 wsdl2h.exe( 由wsdl生成接口头文件C/C++格式的头文件 ) ...

  2. 在 IBM RAD 平台上基于 JAX-WS 开发 Web Services服务器端,客户端

    原文地址:https://www.ibm.com/developerworks/cn/websphere/library/techarticles/1305_jiangpl_rad/1305_jian ...

  3. web调用客户端程序

    背景 最近做一个集成需求,我们是B/S架构的,对方是C/S架构的,对方直接扔过来一个EXE连OCX都没有,让我们调用,也就是说,我们需要通过js程序去调用他们的客户端程序并传入多个参数,当时内心是崩溃 ...

  4. 开发 web 桌面类程序几个必须关注的细节

    HoorayOS 写了差不多快2年了,在我的坚持下也有一部分人打算着手自己也写套类似的程序,我想我可以提供一点经验. 俗话说细节决定成败,开发2年多来,我看过大大小小类似的程序不下20个,各有优点也各 ...

  5. 跟我一起学WCF(3)——利用Web Services开发分布式应用

    一.引言 在前面文章中分别介绍了MSMQ和.NET Remoting技术,今天继续分享.NET 平台下另一种分布式技术——Web Services 二.Web Services 详细介绍 2.1 We ...

  6. 利用Web Services开发分布式应用

    一.引言 在前面文章中分别介绍了MSMQ和.NET Remoting技术,今天继续分享.NET 平台下另一种分布式技术——Web Services 二.Web Services 详细介绍 2.1 We ...

  7. 利用WSCF进行契约先行的Web Services开发

    http://www.cnblogs.com/goody9807/archive/2007/06/05/772107.html 什么是契约先行(Contract-First)? 如果说一个新的软件开发 ...

  8. Delphi 6 Web Services初步评估之三(转)

    Delphi 6 Web Services初步评估之三(转)   Delphi 6 Web Services初步评估之三(转)★ 测试总体印象:在整个测试中,对Delphi 6创建的Web Servi ...

  9. 使用 python 开发 Web Service

    使用 python 开发 Web Service Python 是一种强大的面向对象脚本语言,用 python 开发应用程序往往十分快捷,非常适用于开发时间要求苛刻的原型产品.使用 python 开发 ...

随机推荐

  1. Struts2配置问题java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

    方法一:右键点击项目--->build path-->configure build path-->左侧菜单栏就会看到Deployment Assembly-->右侧点击add ...

  2. js 和 jsp关系

    http://stackoverflow.com/questions/11718063/use-javascript-or-jquery-inside-a-cif-statement 纠结了半天的问题

  3. cocostudio中button

    在编辑器中使用Button控件调用setBright(false)函数控件会不显示 开始以为是代码哪调用了setVisible(false)就在底层函数void Node::setVisible(bo ...

  4. Atom power-mode

    最近看到很多大牛都在用这个酷炫狂拽掉渣天的插件,于是就默默地git了一波.实际结果就是机械键盘加上砰砰砰砰,根本停不下来有没有. 建议(ˉ(∞)ˉ) :视力2.0的同学不建议使用,眼瞎的同学用就用吧, ...

  5. Python进阶之模块与包

    模块 .note-content {font-family: "Helvetica Neue",Arial,"Hiragino Sans GB","S ...

  6. avalon.js 多级下拉框实现

    学习avalon.js的时候,有一个多级下拉框的例子,地址 戳这里 代码实现了联动, 但是逻辑上面理解有点难度,获取选择的值 和 页面初始化 功能存在问题. 在写地图编辑的时候,也用到了多级下拉框,特 ...

  7. html 字符串互转DOM

    描述 拼动态HTML 字符串的时候,把HTML转DOM对象设置属性后,在转字符串 var str1="<ul><li>kim</li><li> ...

  8. “Options模式”下的配置是如何绑定为Options对象

    “Options模式”下的配置是如何绑定为Options对象 配置的原子结构就是单纯的键值对,并且键和值都是字符串,但是在真正的项目开发中我们一般不会单纯地以键值对的形式来使用配置.值得推荐的做法就是 ...

  9. MYSQL 关闭服务的过程

    服务器关闭进程可以概括为: 1.    启动关闭进程 2.    服务器根据需要创建关闭线程 3.    服务器停止接收新连接 4.    服务器终止当前的活动 5.    存储引擎被停掉或关闭 6. ...

  10. 3000本IT书籍下载地址

    http://www.shouce.ren/post/d/id/112300    黑客攻防实战入门与提高.pdfhttp://www.shouce.ren/post/d/id/112299    黑 ...