今天学习如何用QtSoap访问Web Service服务。这里调用的是查询QQ在线状态的服务qqOnlineWebService。调用的几个步骤:

1.创建QtSoapMessage对象 message;

2.message调用setMethod设置调用的服务

3.message调用addMethodArgument设置参数

4.创建QtSoapHttpTransport  *m_pHttp

5.m_pHttp调用setHost,setAction

6.最后m_pHttp调用submitRequest提交请求

class WebServiceClient : public QDialog

{

Q_OBJECT

public:

WebServiceClient(QWidget *parent = 0,Qt::WFlags flags = 0);

~WebServiceClient();

private slots:

voidSubmitSlot();

voidResponseSlot(const QtSoapMessage &response);

private:

voidresizeEvent(QResizeEvent *event);

QLineEdit   *m_pNumber;

QPushButton *m_pSubmit;

QLineEdit   *m_pResult;

QLabel      *m_pQQNumber;

QLabel      *m_pState;

QtSoapHttpTransport  *m_pHttp;

};

WebServiceClient::WebServiceClient(QWidget*parent, Qt::WFlags flags)

: QDialog(parent, flags)

{

m_pQQNumber = newQLabel(tr("QQ号码"),this);

m_pState = newQLabel(tr("QQ状态"),this);

m_pNumber = newQLineEdit(this);

m_pResult = newQLineEdit(this);

m_pResult->setReadOnly(true);

m_pSubmit = newQPushButton(tr("提交"),this);

m_pHttp = newQtSoapHttpTransport;

connect(m_pSubmit,SIGNAL(clicked()),this,SLOT(SubmitSlot()));

connect(m_pHttp,SIGNAL(responseReady( const QtSoapMessage & )),this,SLOT(ResponseSlot(constQtSoapMessage &)));

this->setFixedSize(QSize(300,300));

}

WebServiceClient::~WebServiceClient()

{

}

voidWebServiceClient::ResponseSlot( constQtSoapMessage & response )

{

QString xml = response.toXmlString();

QDomDocument doc;

doc.setContent(xml);

QDomNodeList nodeList =doc.elementsByTagName("qqCheckOnlineResult");

if(nodeList.size())

{

QDomNode resultNode =nodeList.at(0);

QString result =resultNode.toElement().text();

QString state;

if(QString::compare(result,"Y") ==0)

{

state = tr("在线");

}

elseif (QString::compare(result,"N") == 0)

{

state = tr("离线");

}

elseif (QString::compare(result,"E") == 0)

{

state = tr("QQ号码错误");

}

elseif (QString::compare(result,"A") == 0)

{

state = tr("商业用户验证失败");

}

elseif (QString::compare(result,"V") == 0)

{

state = tr("免费用户超过数量");

}

m_pResult->setText(state);

}

}

voidWebServiceClient::SubmitSlot()

{

QtSoapMessage message;

message.setMethod("qqCheckOnline","http://WebXml.com.cn/");

m_pHttp->setAction("http://WebXml.com.cn/qqCheckOnline");

m_pHttp->setHost("webservice.webxml.com.cn");

QString number = m_pNumber->text();

message.addMethodArgument("qqCode","",number);

QString xml = message.toXmlString();

m_pHttp->submitRequest(message,"/webservices/qqOnlineWebService.asmx");

}

voidWebServiceClient::resizeEvent( QResizeEvent *event)

{

m_pQQNumber->setGeometry(5,5,50,20);

m_pNumber->setGeometry(60,5,100,20);

m_pSubmit->setGeometry(160,5,50,20);

m_pState->setGeometry(5,30,50,20);

m_pResult->setGeometry(60,30,100,20);

}

int main(int argc, char*argv[])

{

QApplication a(argc, argv);

QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GB2312"));

QTextCodec::setCodecForLocale(QTextCodec::codecForName("GB2312"));

QTextCodec::setCodecForTr(QTextCodec::codecForName("GB2312"));

WebServiceClient w;

w.show();

returna.exec();

}

http://blog.csdn.net/hai200501019/article/details/19755987

QtSoap调用Web Service(QtSoap是非官方应用)的更多相关文章

  1. ORACLE存储过程调用Web Service

    1. 概述 最近在ESB项目中,客户在各个系统之间的服务调用大多都是在oracle存储过程中进行的,本文就oracle存储过程调用web service来进行说明.其他主流数据库,比如mysql和sq ...

  2. C#开发和调用Web Service

    http://blog.csdn.net/h0322/article/details/4776819 1.1.Web Service基本概念 Web Service也叫XML Web Service ...

  3. php5调用web service

    工作中需要用php调用web service接口,对php不熟,上网搜搜,发现关于用php调用web service的文章也不多,不少还是php4里用nusoap这个模块调用的方法,其实php5里已经 ...

  4. 通过ksoap2-android来调用Web Service操作的实例

    import java.io.IOException; import org.ksoap2.SoapEnvelope;import org.ksoap2.serialization.SoapObjec ...

  5. 使用Android应用调用Web Service

    Java本身提供了丰富的Web  Service支持,比如Sun公司指定的JAX-WS  2规范,还有Apache开源组织所提供的Axis1.Axis2.CXF等,这些技术不仅可以用于非常方便地对外提 ...

  6. Dynamic CRM 2013学习笔记(二十五)JS调用web service 实现多条记录复制(克隆)功能

    前面介绍过如何克隆一条当前的记录: Dynamic CRM 2013学习笔记(十四)复制/克隆记录 , 主要是通过界面上加一个字段,单击form上的clone 按钮时,改变这个字段的值以触发插件来实现 ...

  7. ASP.NET调用Web Service

    1.1.Web Service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求, ...

  8. delphi调用web service出现 Unable to retrieve the URL endpoint for Service/Port .....

    delphi调用web service出现 Unable to retrieve the URL endpoint  for Service/Port, 错误截图如下 查了很长时间, 发现在DataM ...

  9. php5调用web service (笔者测试成功)

    转自:http://www.cnblogs.com/smallmuda/archive/2010/10/12/1848700.html 感谢作者分享 工作中需要用php调用web service接口, ...

随机推荐

  1. [译]Stairway to Integration Services Level 15 – SSIS 参数回顾

    介绍 在本文中我们会研究SSIS变量姐妹: SSIS 变量. 我们会演示参数配置,通过包参数管理动态属性值,然后会演示SSIS包执行的时候参数怎么被配置的. SSIS Parameters 101 S ...

  2. python中的异常如何处理

    一.异常基础 在编程程序出现bug时一般不会将错误信息显示给用户,而是现实一个提示的页面. try: #正常逻辑代码 input = raw_input("输入数字:") data ...

  3. 【转】C++常见错误大全

    原文转自:http://hi.baidu.com/qiou2719/item/b9eed949130ff50ec0161331 C++常见错误大全 0. XXXX "is not a cla ...

  4. 转:让ie6-8支持部分css3样式的方案

    我们都知道,IE浏览器暂不支持CSS3的一些属性.国外的工程师们,不安于此现状,他们总是尽量使用一些手段使IE浏览器也能支持CSS3属性,我觉得这些都是很有意义,很有价值的工作,可以推动整个技术领域的 ...

  5. QMessageBox 用法

    案例一:QMessageBox msgBox;msgBox.setText("The document has been modified.");msgBox.setInforma ...

  6. 投票系统前台 C#,数据库SQL

    ------------vote.aspx.cs--------------------  private void Page_Load(object sender, System.EventArgs ...

  7. BZOJ 1621: [Usaco2008 Open]Roads Around The Farm分岔路口

    题目 1621: [Usaco2008 Open]Roads Around The Farm分岔路口 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 56 ...

  8. android中menu菜单的简单使用

    我认为menu用起来简洁方便,特别是在一些大一点的程序中我们早就厌烦了一遍遍的加button,设置了菜单可谓是事半功倍,简单省事. <1>先声明定义下你的menu: private sta ...

  9. ceph之crush map

    编辑crush map: 1.获取crush map: 2.反编译crush map: 3.至少编辑一个设备,桶, 规则: 4.重新编译crush map: 5.重新注入crush map: 获取cr ...

  10. Linux内核态抢占机制分析(转)

    Linux内核态抢占机制分析  http://blog.sina.com.cn/s/blog_502c8cc401012pxj.html 摘 要]本文首先介绍非抢占式内核(Non-Preemptive ...