首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

现有一个项目的wsdl文件,怎么以socket组包的方式组SOAP报文来和webservice服务端交互

2012-12-17 
现有一个项目的wsdl文件,如何以socket组包的方式组SOAP报文来和webservice服务端交互本帖最后由 kazoroth

现有一个项目的wsdl文件,如何以socket组包的方式组SOAP报文来和webservice服务端交互
本帖最后由 kazoroth 于 2011-10-27 02:54:56 编辑 因为之前做的都是基于TCP/IP的socket报文,而且我们开发的平台不支持webservice直接调用,所以只能以socket组包的方式组soap包。由于本人对wsdl不熟,所以不知道怎么组包,只是自己做过一个提供加法服务的webservice,函数原型为:long add(long a,long b) ,然后自己通过c#写了个客户端调用了这个加法webservice,并且抓包得到了如下报文(红字是客户端发包,蓝字是webservice服务端返回,两个加数分别为99999、55555,返回的是155554):
POST /axis2/services/AddService.AddServiceHttpSoap11Endpoint/ HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.3623)
Content-Type: text/xml; charset=utf-8
SOAPAction: "urn:TTAdd"
Host: 10.229.21.55:8080
Content-Length: 303
Expect: 100-continue
Connection: Keep-Alive
HTTP/1.1 100 Continue
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><TTAdd xmlns="http://ws"><a>99999</a><b>55555</b></TTAdd></soap:Body></soap:Envelope>HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=utf-8
Transfer-Encoding: chunked
Date: Sun, 23 Oct 2011 15:16:23 GMT

f9
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns:TTAddResponse xmlns:ns="http://ws"><ns:return>155554</ns:return></ns:TTAddResponse></soapenv:Body></soapenv:Envelope>
0
尽管如此,手上有了个项目的wsdl文件,还是不知道该如何通过上述组包的方式组SOAP包,希望有高手能够指点。能够以该文档中的getvioinfo这个函数举个例子就好,主要是想了解该报文的xml的结点结构具体是如何写的,谢谢!下面的工程的wsdl文件:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://webservice.gxjj.com" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://webservice.gxjj.com" xmlns:intf="http://webservice.gxjj.com" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.2.1
Built on Aug 08, 2005 (11:49:10 PDT)-->

   <wsdl:message name="delete_fineResponse">

      <wsdl:part name="delete_fineReturn" type="xsd:string"/>

   </wsdl:message>

   <wsdl:message name="getvioinfoRequest">

      <wsdl:part name="jdsbh" type="xsd:string"/>

      <wsdl:part name="jdslb" type="xsd:string"/>

      <wsdl:part name="yhm" type="xsd:string"/>

      <wsdl:part name="mm" type="xsd:string"/>

   </wsdl:message>

   <wsdl:message name="delete_fineRequest">

      <wsdl:part name="jdsbh" type="xsd:string"/>

      <wsdl:part name="jdslb" type="xsd:string"/>

      <wsdl:part name="sjbh" type="xsd:string"/>

      <wsdl:part name="yhm" type="xsd:string"/>

      <wsdl:part name="mm" type="xsd:string"/>



   </wsdl:message>

   <wsdl:message name="getfineinfoResponse">

      <wsdl:part name="getfineinfoReturn" type="xsd:string"/>

   </wsdl:message>

   <wsdl:message name="insert_fineResponse">

      <wsdl:part name="insert_fineReturn" type="xsd:string"/>

   </wsdl:message>

   <wsdl:message name="insert_fineRequest">

      <wsdl:part name="jdsbh" type="xsd:string"/>

      <wsdl:part name="jdslb" type="xsd:string"/>

      <wsdl:part name="fkje" type="xsd:string"/>

      <wsdl:part name="znj" type="xsd:string"/>

      <wsdl:part name="skjg" type="xsd:string"/>

      <wsdl:part name="sjbh" type="xsd:string"/>

      <wsdl:part name="jksj" type="xsd:string"/>

      <wsdl:part name="jkrxm" type="xsd:string"/>

      <wsdl:part name="yhm" type="xsd:string"/>

      <wsdl:part name="mm" type="xsd:string"/>

   </wsdl:message>

   <wsdl:message name="getvioinfoResponse">

      <wsdl:part name="getvioinfoReturn" type="xsd:string"/>

   </wsdl:message>

   <wsdl:message name="getfineinfoRequest">

      <wsdl:part name="jdsbh" type="xsd:string"/>

      <wsdl:part name="jdslb" type="xsd:string"/>

      <wsdl:part name="yhm" type="xsd:string"/>

      <wsdl:part name="mm" type="xsd:string"/>

   </wsdl:message>

   <wsdl:portType name="vio_bank">

      <wsdl:operation name="getvioinfo" parameterOrder="jdsbh jdslb yhm mm">

         <wsdl:input message="impl:getvioinfoRequest" name="getvioinfoRequest"/>

         <wsdl:output message="impl:getvioinfoResponse" name="getvioinfoResponse"/>

      </wsdl:operation>

      <wsdl:operation name="getfineinfo" parameterOrder="jdsbh jdslb yhm mm">

         <wsdl:input message="impl:getfineinfoRequest" name="getfineinfoRequest"/>

         <wsdl:output message="impl:getfineinfoResponse" name="getfineinfoResponse"/>

      </wsdl:operation>

      <wsdl:operation name="insert_fine" parameterOrder="jdsbh jdslb fkje znj skjg sjbh jksj jkrxm yhm mm">

         <wsdl:input message="impl:insert_fineRequest" name="insert_fineRequest"/>



         <wsdl:output message="impl:insert_fineResponse" name="insert_fineResponse"/>

      </wsdl:operation>

      <wsdl:operation name="delete_fine" parameterOrder="jdsbh jdslb sjbh yhm mm">

         <wsdl:input message="impl:delete_fineRequest" name="delete_fineRequest"/>

         <wsdl:output message="impl:delete_fineResponse" name="delete_fineResponse"/>

      </wsdl:operation>

   </wsdl:portType>

   <wsdl:binding name="vio_bankSoapBinding" type="impl:vio_bank">

      <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>

      <wsdl:operation name="getvioinfo">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="getvioinfoRequest">

            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservice.gxjj.com" use="encoded"/>

         </wsdl:input>

         <wsdl:output name="getvioinfoResponse">

            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservice.gxjj.com" use="encoded"/>

         </wsdl:output>

      </wsdl:operation>

      <wsdl:operation name="getfineinfo">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="getfineinfoRequest">

            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservice.gxjj.com" use="encoded"/>

         </wsdl:input>

         <wsdl:output name="getfineinfoResponse">

            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservice.gxjj.com" use="encoded"/>

         </wsdl:output>

      </wsdl:operation>

      <wsdl:operation name="insert_fine">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="insert_fineRequest">

            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservice.gxjj.com" use="encoded"/>

         </wsdl:input>

         <wsdl:output name="insert_fineResponse">



            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservice.gxjj.com" use="encoded"/>

         </wsdl:output>

      </wsdl:operation>

      <wsdl:operation name="delete_fine">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="delete_fineRequest">

            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservice.gxjj.com" use="encoded"/>

         </wsdl:input>

         <wsdl:output name="delete_fineResponse">

            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservice.gxjj.com" use="encoded"/>

         </wsdl:output>

      </wsdl:operation>

   </wsdl:binding>

   <wsdl:service name="vio_bankService">

      <wsdl:port binding="impl:vio_bankSoapBinding" name="vio_bank">

         <wsdlsoap:address location="http://localhost:8082/webservice/services/vio_bank"/>

      </wsdl:port>

   </wsdl:service>

</wsdl:definitions>


[解决办法]
楼主用什么编程语言?gsoap可以在绝大多数平台上工作
[解决办法]
gsoap生成的函数很乱,我不会用,如果会用还可以抓一下包得到报文(其实还是为了拼报文)。
现在我所在的环境就只有一个方法,就是拼字符串得到报文。
说白了我问的问题就是字符串如何拼,想得到具体格式
[解决办法]
gsoap我用过。楼主看看它的例子就能用了。
[解决办法]
自动生成的函数太多了 眼花缭乱 不知道怎么定位用哪个函数
[解决办法]
问题已经解决了。还是用到了gsoap,但是这个不是用来写客户端的,而是用来编译wsdl文件得到报文格式的(理由前面已经说了,采用组包的方法来解决 而不是写c的客户端),方法如下:
wsdl2h -c -o  vio_bank.h vio_bank.wsdl
得到vio_bank.h,
soapcpp2 -C vio_bank.h
得到vio_USCOREbankSoapBinding.getvioinfo.req.xml和一系列文件
[hwt@localhost2 jj]$ cat  vio_USCOREbankSoapBinding.getvioinfo.req.xml
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:ns1="http://webservice.gxjj.com">
 <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <ns1:getvioinfo>
   <jdsbh></jdsbh>
   <jdslb></jdslb>
   <yhm></yhm>
   <mm></mm>
  </ns1:getvioinfo>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>


就可以得到报文格式。soap头可以自己通过.net编写客户端调用自己写的服务端的helloworld程序去抓包获得格式。
上面的方法需要注意soap协议的版本,服务端版本如果是1.1的用 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"(最后的"/"不能少)
服务端版本是1.2的用xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"

热点排行