QtSoap调用Web Service(QtSoap是非官方应用)
今天学习如何用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是非官方应用)的更多相关文章
- ORACLE存储过程调用Web Service
1. 概述 最近在ESB项目中,客户在各个系统之间的服务调用大多都是在oracle存储过程中进行的,本文就oracle存储过程调用web service来进行说明.其他主流数据库,比如mysql和sq ...
- C#开发和调用Web Service
http://blog.csdn.net/h0322/article/details/4776819 1.1.Web Service基本概念 Web Service也叫XML Web Service ...
- php5调用web service
工作中需要用php调用web service接口,对php不熟,上网搜搜,发现关于用php调用web service的文章也不多,不少还是php4里用nusoap这个模块调用的方法,其实php5里已经 ...
- 通过ksoap2-android来调用Web Service操作的实例
import java.io.IOException; import org.ksoap2.SoapEnvelope;import org.ksoap2.serialization.SoapObjec ...
- 使用Android应用调用Web Service
Java本身提供了丰富的Web Service支持,比如Sun公司指定的JAX-WS 2规范,还有Apache开源组织所提供的Axis1.Axis2.CXF等,这些技术不仅可以用于非常方便地对外提 ...
- Dynamic CRM 2013学习笔记(二十五)JS调用web service 实现多条记录复制(克隆)功能
前面介绍过如何克隆一条当前的记录: Dynamic CRM 2013学习笔记(十四)复制/克隆记录 , 主要是通过界面上加一个字段,单击form上的clone 按钮时,改变这个字段的值以触发插件来实现 ...
- ASP.NET调用Web Service
1.1.Web Service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求, ...
- 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 ...
- php5调用web service (笔者测试成功)
转自:http://www.cnblogs.com/smallmuda/archive/2010/10/12/1848700.html 感谢作者分享 工作中需要用php调用web service接口, ...
随机推荐
- the convertion between string and BlobColumn
It's hard to find some samples about the convertion between string and BlobColumn.AddBlobData. It's ...
- Aspx 页面生命周期
ASP.NET 页运行时,此页将经历一个生命周期,在生命周期中将执行一系列处理步骤.这些步骤包括初始化.实例化控件.还原和维护状态.运行事件处理程序代码以及进行 呈现.了解页的生命周期非常重要,这样就 ...
- 修改SQL Server登录密码(使用SQL Server身份登录)
修改登录密码: http://blog.sina.com.cn/s/blog_631611220100iqao.html
- Mybatis 逆向工程
Mybatis逆向工程: 推荐用Java和XML Configuration的方式生成逆向文件 Java类: package generation; import java.io.File; impo ...
- 用composer安装 Laravel | Laravel需要的环境配置
一:安装 参考网站 http://v4.golaravel.com/docs/4.2/installation 1.先确保安装好了PHP,和服务器环境 2.然后下载composer可执行文件到当前目录 ...
- Ants (POJ 1852)
题目描述: Description An army of ants walk on a horizontal pole of length l cm, each with a constant spe ...
- SkipFish
https://zmap.io/ http://code.google.com/p/skipfish/wiki/SkipfishDoc#How_to_run_the_scanner?
- JFreeChart画折线图
请见Github博客: http://wuxichen.github.io/Myblog/htmlcss/2014/09/01/JFreechartLinechart.html
- 用了好多年的XP换成了Win7
因为懒,所以工作的笔记本XP一直没有换 网卡故障被逼无奈正好升成Win7 顺便看了一下市场占有率,Win7已经百分之四十多了,去年就超过XP了 不过XP也够持久的了,都十二年了,有这样长寿的产品对哪家 ...
- ThinkPHP的验证码刷新显示和验证码显示不出来的原因
1.应当这样<imp src='验证码路径' onclick="this.src='验证码路径?'+Math.random()">;如果后面不加Math.random( ...