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接口, ...
随机推荐
- C#中Cache用法
C#中Cache用法 Cache 是分配在服务器上的一个公共的内存片,所谓公共指的cache只要一创建是任何一个客户端浏览器都可以通过后台代码访问到它,它面向的是所有用户,相对而言sessio ...
- js得到分页栏
自己写的,感觉返回html代码蠢蠢的,但是新手并不知道怎么写更好的,感觉这样子也蛮简单.记录下来,以后来越改越好. //获得分页栏.注意indexSize为奇数,这样也比较好看 //totalNum: ...
- Square(hdu 1511)
题目描述: Problem Description Given a set of sticks of various lengths, is it possible to join them end- ...
- 手把手教你在Windows端搭建Redmine项目管理软件
1.Redmine介绍 Redmine是用Ruby开发的基于web的项目管理软件,是用ROR框架开发的一套跨平台项目管理系统,据说是源于Basecamp的ror版而来,支持多种数据库,有不少自己独特的 ...
- js获取控件位置
//获取坐标位置 function getpos(e) { var t=e.offsetTop; var l=e.offsetLeft; var height=e.offsetHeight; whil ...
- ShareSDK for Android 只有新浪微博分享
本文代码例子:http://pan.baidu.com/share/link?shareid=3710053477&uk=3189484501 ShareSDK 官方的例子非常好,但代码太多看 ...
- Android图像篇
Android的渲染分为2D渲染和3D渲染两种,当中2D渲染的引擎为Skia.3D渲染的引擎是OpenGL ES.眼下.Android支持OpenGL ES1.0和OpenGL ES 2.0两种标准. ...
- stm32之GPIO库函数开发
关于GPIO库函数的重点函数:P122 GPIO_Init() :根据GPIO_InitStruct中指定的参数初始化外设GPIOx寄存器: GPIO_ReadInputDataBit():读取指定端 ...
- [原]详解如何将cocos2dx项目编译到Android平台上的(方式一:Cywin+NDK)
链接地址:http://m.blog.csdn.net/blog/yhc13429826359/29357815 2014-6-8阅读578 评论0 前言:cocos2dx作为一个开源的移动2D游戏框 ...
- BZOJ 1925: [Sdoi2010]地精部落( dp )
dp(i,j)表示1~i的排列中, 以1~j为开头且开头是下降的合法方案数 这种数列具有对称性, 即对于一个满足题意且开头是上升的n的排列{an}, 令bn = n-an+1, 那么{bn}就是一个满 ...