打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
用Soap Toolkit调用WebService的一个问题

 分析过程:

用soap toolkit的跟踪工具MSSoapT看一下,客户端到底向WebService发送了什么数据:

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="">
<SOAPSDK1:Add xmlns:SOAPSDK1="http://tempuri.org/" SOAP-ENV:encodingStyle="">
<n1 SOAP-ENV:encodingStyle="">5</n1>
<n2 SOAP-ENV:encodingStyle="">10</n2>
</SOAPSDK1:Add>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

再看看vs.NET调试中,IE浏览器发出的数据(模板):


<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Add xmlns="http://tempuri.org/">
<n1>int</n1>
<n2>int</n2>
</Add>
</soap:Body>
</soap:Envelope>

区别在哪里?soaptoolkit的数据中,多了个encodingStyle属性,尽管没有制定值。我们想办法屏蔽这个属性。
在SoapSerializer30的startElement方法中的参数中按照如下方式调用,可以不制定这个属性。
改代码如下:


...
Serializer->startElement("Add","http://tempuri.org/","NONE","");
Serializer->startElement("n1","","NONE","");
Serializer->writeString("5");
Serializer->endElement();
Serializer->startElement("n2","","NONE","");
Serializer->writeString("10");
Serializer->endElement();
Serializer->endElement();
...


但返回结果还是0,看来和encodingStyle无关。看看跟踪情况:


<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="">
<SOAPSDK1:Add xmlns:SOAPSDK1="http://tempuri.org/">
<n1>5</n1>
<n2>10</n2>
</SOAPSDK1:Add>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

问题解决:
比较一下vs.net中发出的请求,差别在哪里?认真看一下,n1和n2没有指定命名空间,那么就指定一下吧。
把代码改成:


Serializer->startElement("Add","http://tempuri.org/","NONE","");
Serializer->startElement("n1","http://tempuri.org/","NONE","");
Serializer->writeString("5");
Serializer->endElement();
Serializer->startElement("n2","http://tempuri.org/","NONE","");
Serializer->writeString("10");
Serializer->endElement();
Serializer->endElement();

测试结果正常了,返回15。

看看这时候发出的xml数据:
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="">
<SOAPSDK1:Add xmlns:SOAPSDK1="http://tempuri.org/">
<SOAPSDK1:n1>5</SOAPSDK1:n1>
<SOAPSDK1:n2>10</SOAPSDK1:n2>
</SOAPSDK1:Add>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

原因:

也许是VS.NET的问题,也许是SoapToolKit的问题,也许是他提供的例子自身就有问题,也许是我的运行环境有问题,当然,更也许是我还没有真正理解xml的命名空间或没有正确使用WebService。


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
[原创&交流]桌面程序调用Web Service应用实例
【原创】用Visual C 客户端调用Weblogic的Webservice
在Delphi中动态调用webservice
用python发布基于soap的webservice(二)
关于webservice框架cxf遇到的一些问题
JAVA6开发WebService (三)——几个概念
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服