您的位置:首页 > 其它

创建一种服务 为多种客户端提供ws的访问方式

2013-05-15 15:57 316 查看
wsdl定义了3种绑定扩展,即为客户提供了3种访问Web Service的方法
1.soap绑定(包括soap1.1和soap1.2)
2.http get/post
3.MIME

同一个ws可以有多重绑定,每增加一种绑定  就要修改对应的wsdl
需要修改一下内容
1.定义头(增加新的访问协议的xml命名空间)
<wsdl:definations>添加属性
soap:  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
soap12:xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
http: xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
mime:  xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
固有的:
targetNamespace="http://WebXml.com.cn/"
xmlns:tns="http://WebXml.com.cn/"                <!--!!!!!!以上两句必需包含-->
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"<!--soap编码可以不添加-->
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">      <!--!!!!!!必包含-->
xmlns:s="http://www.w3.org/2001/XMLSchema" <!--schema标签定义-->  <!--!!!!!!必包含-->

2.数据类型不做改变
<wdl:type>无需变动
3.服务中每个方法对应的请求和响应
<wsdl:message name="method">
<wsdl:message name="methodResponse">
修改时应标注相应的绑定协议
如
<wsdl:message name="methodSOAP11">
<wsdl:message name="methodResponseSOAP11">
对于http的get 和post方法标准写法如下
<wsdl:message name="methodGetIn">
<wsdl:message name="methodGetOut">
4.端口类型(将3中的输入输出与对应的服务中的方法联系起来)服务中每个方法增加一条
<wsdl:portType>

<wsdl:portType name="qqOnlineWebServiceHttpGet">
<wsdl:operation name="qqCheckOnline"><!--与服务中的方法对应-->
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br /><h3>获得腾讯QQ在线状态</h3><p>输入参数:QQ号码 String,默认QQ号码:8698053。返回数据:String,Y = 在线;N = 离线;E = QQ号码错误;A = 商业用户验证失败;V = 免费用户超过数量</p><br /></wsdl:documentation>
<wsdl:input message="tns:qqCheckOnlineHttpGetIn" /><!--这里是绑定了方法的输入-->
<wsdl:output message="tns:qqCheckOnlineHttpGetOut" /><!--这里是绑定了方法的输出-->
</wsdl:operation>
</wsdl:portType>
5.端口绑定
<wsdl:binding name="qqOnlineWebServiceHttpGet" type="tns:qqOnlineWebServiceHttpGet"> <!--type属性与4portType中定义对应-->
<http:binding verb="GET" />
<wsdl:operation name="qqCheckOnline">     <!--这里的name属性应该与4中的指定严格对应-->
<http:operation location="/qqCheckOnline" />  <!--这里映射了新的url-->
<wsdl:input>
<http:urlEncoded />
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
对于post方式
<wsdl:binding name="qqOnlineWebServiceHttpPost" type="tns:qqOnlineWebServiceHttpPost">
<http:binding verb="POST" />
<wsdl:operation name="qqCheckOnline">
<http:operation location="/qqCheckOnline" />
<wsdl:input>
<mime:content type="application/x-www-form-urlencoded" />  <!--输入为form表单-->
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body" /><!--Body在2<wsdl:type>和3<wsdl:message>中已经定义-->
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
对于soap12
<wsdl:binding name="qqOnlineWebServiceSoap12" type="tns:qqOnlineWebServiceSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" /><!--注意这句-->
<wsdl:operation name="qqCheckOnline">
<soap12:operation soapAction="http://WebXml.com.cn/qqCheckOnline" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
6.服务发布的绑定
<wsdl:service>

<wsdl:port name="qqOnlineWebServiceSoap" binding="tns:qqOnlineWebServiceSoap">    <!--binding属性与5<wsdl:binding>的name属性对应-->
<soap:address location="http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx" />  <!--注意前缀标签名:soap soap12 http 已经在1定义头中定义-->
</wsdl:port>
<wsdl:port name="qqOnlineWebServiceSoap12" binding="tns:qqOnlineWebServiceSoap12">
<soap12:address location="http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx" />
</wsdl:port>
<wsdl:port name="qqOnlineWebServiceHttpGet" binding="tns:qqOnlineWebServiceHttpGet">
<http:address location="http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx" />
</wsdl:port>
<wsdl:port name="qqOnlineWebServiceHttpPost" binding="tns:qqOnlineWebServiceHttpPost">
<http:address location="http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx" />
</wsdl:port>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐