简述
Qt本身给我们提供了调用WebService的解决方案QtSoap,源码及示例见:qt-solutions-qtsoap
下载编译
下载源码后,需要修改一些地方(我的版本是Qt5),按照错误提示修改即可,很简单。
编译完成之后会生成QtSolutions_SOAP-headd.lib、QtSolutions_SOAP-headd.dll。。。
使用
拷贝QtSolutions_SOAP-headd.lib至lib目录下,拷贝qtsoap.h至include目录下。
pro中添加库文件及库目录:
<code class="language-Qt hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro",monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">INCLUDEPATH <span class="hljs-subst" style="color:#000000;box-sizing: border-box;">+=</span> $<span class="hljs-variable" style="color:#66066;box-sizing: border-box;">$PWD</span>/include
LIBS <span class="hljs-subst" style="color:#000000;box-sizing: border-box;">+=</span> <span class="hljs-attribute" style="box-sizing: border-box;">-L</span>$<span class="hljs-variable" style="color:#66066;box-sizing: border-box;">$PWD</span>/lib <span class="hljs-attribute" style="box-sizing: border-box;">-lQtSolutions_SOAP</span><span class="hljs-attribute" style="box-sizing: border-box;">-headd</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221,221,221); list-style: none; text-align: right; background-color: rgb(238,238,238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221,238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>
实例解析
下面,我们以“获得腾讯QQ在线状态”为例,见:WebXml.com.cn,里面包含了大量的Web服务,例如:手机号码归属地查询,电子邮件地址验证、城市天气预报查询等。
示例
SOAP 1.1
以下是SOAP1.1请求和响应示例。所显示的占位符需替换为实际值。

效果

源码