webservice中wsdl和soap

下面主要分析下webservice中的两种技术,wsdl以及soap

看列子1,这个是一个wsdl定义文件

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://134.96.240.101/zjssc/services/revenueservice" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://134.96.240.101/zjssc/services/revenueservice" xmlns:intf="http://134.96.240.101/zjssc/services/revenueservice" xmlns:tns1="http://common.ifsrv.core.ssc.freesky.com" 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.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
 <wsdl:types>
  <schema elementFormDefault="qualified" targetNamespace="http://common.ifsrv.core.ssc.freesky.com" xmlns="http://www.w3.org/2001/XMLSchema">
   <element name="IfService">
    <complexType>
     <sequence>
      <element name="ifUser" type="xsd:string"/>
      <element name="ifPass" type="xsd:string"/>
      <element name="ifCode" type="xsd:string"/>
      <element name="ifEvent" type="xsd:string"/>
      <element name="info" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
   <element name="IfServiceResponse">
    <complexType>
     <sequence>
      <element name="IfServiceReturn" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
  </schema>
 </wsdl:types>

   <wsdl:message name="IfServiceRequest">

      <wsdl:part element="tns1:IfService" name="parameters"/>

   </wsdl:message>

   <wsdl:message name="IfServiceResponse">

      <wsdl:part element="tns1:IfServiceResponse" name="parameters"/>

   </wsdl:message>

   <wsdl:portType name="RevenueWS">

      <wsdl:operation name="IfService">

         <wsdl:input message="intf:IfServiceRequest" name="IfServiceRequest"/>

         <wsdl:output message="intf:IfServiceResponse" name="IfServiceResponse"/>

      </wsdl:operation>

   </wsdl:portType>

   <wsdl:binding name="revenueserviceSoapBinding" type="intf:RevenueWS">

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

      <wsdl:operation name="IfService">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="IfServiceRequest">

            <wsdlsoap:body use="literal"/>

         </wsdl:input>

         <wsdl:output name="IfServiceResponse">

            <wsdlsoap:body use="literal"/>

         </wsdl:output>

      </wsdl:operation>

   </wsdl:binding>

   <wsdl:service name="RevenueWSService">

      <wsdl:port binding="intf:revenueserviceSoapBinding" name="revenueservice">

         <wsdlsoap:address location="http://134.96.240.101/zjssc/services/revenueservice"/>

      </wsdl:port>

   </wsdl:service>

</wsdl:definitions>

可以看到这个wsdl的定义主要包括这么几个部分

service (服务)-> port (实例接口)-> binding (抽象类型) ->  portType  (访问的类)-> operation (访问的方法) -> message  (包装参数对象)-> type(访问的参数)

这个是我对webservice wsdl的理解


下面写下一个webservice 客户端soap请求报文
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
	<soapenv:Body>
		<impl:IfService
			xmlns:impl="http://134.96.240.101/zjssc/services/revenueservice?wsdl">
			<arg0>用户名</arg0>
			<arg1>密码</arg1>
			<arg2>SSC_YSXT_FYSSK</arg2>
			<arg3>insert</arg3>
			<arg4>
				<ifinfo>
					<cost>
						<maincost>
							<sysid>d17a0c79-e378-4225-9248-e26e0fd7d2e9</sysid>
							<company>3311</company>
							<businessman></businessman>
							<periodid>201412</periodid>
							<commitdate>2014-12-17</commitdate>
							<startuser>zhouyijing</startuser>
							<telephone>
								111111111111
							</telephone>
							<intaffixnum>1</intaffixnum>
							<memo>............</memo>
							<paytype>1</paytype>
						</maincost>
						<detailcosts>
							<debitcost>
								<payer>.........</payer>
								<payabstract>....................................</payabstract>
								<bankname>.......................................
									...
								</bankname>
								<bankno>1111111111111</bankno>
								<debitaccountid>10020101101104</debitaccountid>
								<debitamount>9000.00</debitamount>
							</debitcost>
							<creditcost>
								<detailabstract>....................................
								</detailabstract>
								<costitem>2222222</costitem>
								<creditaccountid>33333333</creditaccountid>
								<costcenter>1105000</costcenter>
								<creditamount>9000.00</creditamount>
							</creditcost>
						</detailcosts>
					</cost>
				</ifinfo>
			</arg4>
		</impl:IfService>
	</soapenv:Body>
</soapenv:Envelope>
这是我通过tcpdump( 这真是一个学习和查找问题的好工具)抓下来的包
可以看到soap信息是经过xml格式包装的
soapenv:Envelope -> soapenv:Body ->  impl:IfService(取自参数element) 三层次的包装
里面的主要信息就只是一一个个的参数了,这里一共有5个参数,可以看到这个与wsdl描述中的ifServiceRequest参数是对应的


下面写下一个webservice 客户端soap报文
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<soapenv:Body>
		<IfServiceResponse
			xmlns="http://134.96.240.101/zjssc/services/revenueservice?wsdl">
			<IfServiceReturn>
				<?xml version="1.0" encode="gb2312"?>
				<IfResponse>
					<IfResult >0</IfResult>
					<IfWarning ></IfWarning>
					<IfError ></IfError>
					<IfErrorStack ></IfErrorStack>
					<IfResultInfo >YJ21412000038</IfResultInfo>
				</IfResponse>
			</IfServiceReturn>
		</IfServiceResponse>
	</soapenv:Body>
</soapenv:Envelope>
这是对应的回馈信息
soapenv:Envelope -> soapenv:Body -> IfServiceResponse(取自参数element name) -> IfServiceReturn(取自参数element)


从上面可以看出,客户端对webservice的访问,消息的访问格式是根据webservice服务提供的wsdl而进行soap封装的,而服务的wsdl恰好就是用来描述这个webservice的,
所以双方可以通信。
这样看起来客户端调用的方法就像是在调用本地的一个访问

String IfService(String ifUser, String ifPass, String ifCode, String ifEvent, String info) 

这个就是服务端的webservice方法,其实wsdl也是根据这个生成的。
在上面的这个webservice服务是通过http访问的,这个可以通过报文就可以看出来


这是回馈信息的tcpdump截图,可以看出来这是一个http协议,至于如何部署webservice可以看我的另一篇文章,是通过spring整合axis2的

http://blog.sina.com.cn/s/blog_bfab07fd0102ux8m.html



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值