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接口, ...
随机推荐
- 子请求执行失败。有关更多信息,请检查 InnerException。
异常:子请求执行失败.有关更多信息,请检查 InnerException. 错误:程序请求异常 可能原因: 1.可以检查是否引用了分布视图,而分布视图中发生错误 2.可以检查是否引用了分布视图,而分布 ...
- if语句判断闰年、平年
一.让用户输入一个年份,判断是否是闰年. 判断一个年份是否是闰年有两个条件 ①能被400整除:②能被4整除但是不能被100整除 Console.WriteLine("请输入年份:" ...
- 初探响应式Web设计
公司书柜有本<响应式Web设计:HTML5和CSS3实战>,大概就认真看了前面几章,后面大部分介绍css3(随便找本手册都可以了要你可用!) <响应式Web设计:HTML5和CSS3 ...
- word2vec代码解释
以前看的国外的一篇文章,用代码解释word2vec训练过程,觉得写的不错,转过来了 原文链接 http://nbviewer.jupyter.org/github/dolaameng/tutorial ...
- 在Visual Studio 2010中安装iGraph
本安装步骤参考了:http://www.16kan.com/question/detail/182225.html Igraph actually does work with Visual C++ ...
- literal控件的例子
Literal的Mode属性,举例说明 这个属性的枚举值:PassThrough Encode Transform <%@ Page Language="C#" Auto ...
- repeater一个简单的用法例子
(前台) <asp:Repeater ID="Repeater1" runat="server" onitemdatabound=" ...
- Windows Phone 8初学者开发—第5部分:布局和事件基础
原文 Windows Phone 8初学者开发—第5部分:布局和事件基础 原文地址: http://channel9.msdn.com/Series/Windows-Phone-8-Developme ...
- 【操作系统】:Main features of the X86-64
The combination of the new hardware supplied by Intel and AMD ,and the new versions of GCC targeting ...
- MFC消息顺序
1.AfxWndProc() 该函数负责接收消息,找到消息所属的CWnd对象,然后调用AfxCallWndProc 2.AfxCallWndProc() 该函数负责保存消息(保存的内容主要 ...