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#程序将excel文件转换成xml文件
要程序你自己去组装去,我只写两个部分,一个是读Excel的部分,然后是写入到xml的1) 从指定的excel读出信息string strConn="provider=Microsoft.Je ...
- Lamd表达式
1. 普通绑定: public void button1_Click(object sender, EventArgs e) { MessageBox.Show("ok"); } ...
- java源代码如何打成jar包
链接地址:http://jingyan.baidu.com/article/046a7b3ed8b23ef9c27fa9b9.html 有时自已写了一个很巧妙的方法,想分享给别人用,这时我们就可以将其 ...
- Jmeter 发送json{Jfinal 接口req rsp均为json}
链接地址:http://yangyoupeng-cn-fujitsu-com.iteye.com/blog/2013649 使用jmeter发送json数据.方法有三种 原创,转载请注明出处 1.利用 ...
- HTML5 总结-音频-2
HTML5 音频 音频格式 当前,audio 元素支持三种音频格式: IE 9 Firefox 3.5 Opera 10.5 Chrome 3.0 Safari 3.0 Ogg Vorbis ...
- shell学习之用户管理和文件属性
1.组和用户的添加 添加组: groupadd [-g gid [-o]] [-r] [-f] group 示例: groupadd -g testgoup1 #添加组testgroup1,同时指定g ...
- qt实现-给SQLITE添加自定义函数
需要使用sqlite里的password对某个字段进行加密,由于使用的sqlite是由QT封装好的QSqlDatabase,没有发现加载扩展函数的方法,所以自己实现了一个. 在网上也没找到相应的参考, ...
- IT第四天 - 运算符、随机数、Math类
IT第四天 上午 运算符 1.%运算符的应用 2.运算符优先级:小括号 ! 算数运算符 关系运算符 && || 赋值运算符 3.三元运算符:?表示条件为true的结果,:表示条件为 ...
- 通过加索引对sql语句优化
今天看数据库的时候遇到这样一个SQL语句: select substr(a.djxh,) as id, (a.nd || a.yf) DECL_YM, a.zspm_dm as LEVY_ITEM_I ...
- Courses(最大匹配)
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...