现有一个项目的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>
就可以得到报文格式。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"