今天学习如何用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. 使用线程 在shell上同步动态显示当前系统时间

    //创建一个用于刷新当前系统时间的线程 new Thread() { public void run() { // 此处为另外一个单独线程,非UI线程 Display dis=shell.getDis ...

  2. AS3 Post 参数和ByteArray的方法及服务器端接收

    as端: (form表单形式)req.method = URLRequestMethod.POST; var reqHeader:URLRequestHeader = new URLRequestHe ...

  3. jQuery的AJAX方法简介及与其他文件$符号冲突的解决办法

    一.重要的jQuery AJAX方法简介 $.load(url) 从服务器载入数据 $.get(url,callback) 从服务器请求数据,并执行回调函数 $.post(url,data,callb ...

  4. javaweb学习路之四--cxf发布Webservice

    背景:maven构建的springMvc+mybatis框架 源码--->https://github.com/Zering/MyWeb 步骤:(本步骤是自己在实际探索过程中的步骤,我的思路是先 ...

  5. [译]Stairway to Integration Services Level 3 - 增量导入数据

    让我们打开之前的项目:My_First_SSIS_Project_After_Step_2.zip 之前项目中我们已经向dbo.contact 导入了19972行,如果再次执行包会重复导入,让我们来解 ...

  6. Oracle游标循环更新数据案例

    declare v_XTXMBH number; v_ZJZJZJRQ varchar2(40); cursor c_job is SELECT XT.XTXMBH AS XTXMBH, QJ.ZJZ ...

  7. BZOJ 2190 仪仗队

           这道题的关键就是找到所有的点中,x与y互质的点,第一反应必定是暴搜,稍想一下可以从中分开求一半,但范围仍然限定了这条路行不通,仔细画了几张图后发现下图中从第三行起第k行可连fai k个, ...

  8. Android之判断设备网络连接状态,并判断连接方式

    在Android开发过程中,对于一个需要连接网络的Android设备,对设备的网络状态检测是很有必要的!有很多的App都需要连接网络.判断设备是否已经连接网络,并且在连接网络的状态下判断是wifi无线 ...

  9. zookeeper 安装

    Zookeeper安装 一.   下载zookeeper http://www.apache.org/dist/zookeeper/stable/ 二.   解压zookeeper.tar >& ...

  10. Windows Phone 8初学者开发—第8部分:理解编译和部署

    原文 Windows Phone 8初学者开发—第8部分:理解编译和部署 第8部分:理解编译和部署 原文地址: http://channel9.msdn.com/Series/Windows-Phon ...