WebService–了解wsdl文件

WebService–了解wsdl文件获取到的 wsdl 文件 以 CXF 发布的服务为例 以下说的节点标签都是去掉 wsdl 的 wsdl definitionsx xsd http www w3 org 2001 XMLSch

大家好,欢迎来到IT知识分享网。

schema约束文件

规范:

  1. 所有标签和属性都需要有schema文件定义
  2. 所有的schema文件都需要有一个id,但在这里它叫namespace
  3. namespace由targetNamespace属性来定义,targetNamespace的值是一个url(此属性很大可能不存在)
  4. 如何引入一个schema文件:通过xml的属性xmlns,属性值为schema文件的id,即namespace值,即argetNamespace属性的值,
  5. 如果引入的schema文件不会w3c组织定义,则必须指定schema文件的位置
  6. schema文件的位置由schemaLocation属性定义,值为schema文件的namespace的值
  7. 如果引入n个约束,需要给约束取n-1个别名,名别是通过xmlns加上冒号,即xmlns:起的别名=“约束文件的地址”

获取到的wsdl文件(以CXF发布的服务为例)

以下说的节点标签都是去掉wsdl的

<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://impl.webservice.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:ns1="http://webservice.com/" name="UserServiceImplService" targetNamespace="http://impl.webservice.com/"> <wsdl:import location="http://localhost:8000/user?wsdl=IUserService.wsdl" namespace="http://webservice.com/"> </wsdl:import> <wsdl:binding name="UserServiceImplServiceSoapBinding" type="ns1:IUserService"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="sayHi"> <soap:operation soapAction="" style="document"/> <wsdl:input name="sayHi"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="sayHiResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="UserServiceImplService"> <wsdl:port binding="tns:UserServiceImplServiceSoapBinding" name="UserServiceImplPort"> <soap:address location="http://localhost:8000/user"/> </wsdl:port> </wsdl:service> </wsdl:definitions> 

复制import节点的location的值在浏览器中打开进一步获取详细的wsdl文件

<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://webservice.com/" name="IUserService" targetNamespace="http://webservice.com/"> <wsdl:types> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://webservice.com/" elementFormDefault="unqualified" targetNamespace="http://webservice.com/" version="1.0"> <xs:element name="sayHi" type="tns:sayHi"/> <xs:element name="sayHiResponse" type="tns:sayHiResponse"/> <xs:complexType name="sayHi"> <xs:sequence> <xs:element minOccurs="0" name="arg0" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="sayHiResponse"> <xs:sequence> <xs:element minOccurs="0" name="return" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:schema> </wsdl:types> <wsdl:message name="sayHiResponse"> <wsdl:part element="ns1:sayHiResponse" name="parameters"> </wsdl:part> </wsdl:message> <wsdl:message name="sayHi"> <wsdl:part element="ns1:sayHi" name="parameters"> </wsdl:part> </wsdl:message> <wsdl:portType name="IUserService"> <wsdl:operation name="sayHi"> <wsdl:input message="ns1:sayHi" name="sayHi"> </wsdl:input> <wsdl:output message="ns1:sayHiResponse" name="sayHiResponse"> </wsdl:output> </wsdl:operation> </wsdl:portType> </wsdl:definitions> 

文档节点

  1. definitions

1. definitions

2. import

Import元素可以让当前的文档使用其他WSDL文档中指定命名空间中的定义。 必须声明两个属性,即namespace属性和location属性。namespace属性必须和正导入的WSDL文档中声明的targetNamespace相匹配。一般为域名,即包名的倒置。location属性必须指向一个实际的WSDL文档。可以通过此节点的location属性的值再次发送请求获取wsdl文件

3. binding

Binding元素将一个抽象的portType映射到一组具体的协议(SOAP或者HTTP)、消息传递样式(RPC或者document)以及编码样式(literal或者SOAP encoding)。binding 元素有两个属性 – name 属性和 type 属性。name 属性定义 binding 的名称,而 type 属性指向用于 binding 的端口(值为服务接口类名)

<wsdl:binding name="UserServiceImplServiceSoapBinding" type="ns1:IUserService"> 
soap:binding元素

soap:binding元素指定了用于传输SOAP消息的Internet协议以及operation缺省的消息类型(RPC还是document)

<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 
operation(name属性值是请求方法名)

operation元素指定了消息传递样式(RPC或者document),并且指定了SOAPAction字段的值(访问接口的方法名)。

<wsdl:operation name="sayHi"> <soap:operation soapAction="" style="document"/> 

4. types(同样包含请求参数和响应参数)

此内容包含了定义处理请求的接口中的函数名,参数类名和返回值类型其中sayHiResponse是函数名自动加上Response生成的,在实际中并没有。此文档中targetNamespace必须是一个有效的非空值,而且必须属于由WSDL文档。

<wsdl:types> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://webservice.com/" elementFormDefault="unqualified" targetNamespace="http://webservice.com/" version="1.0"> <xs:element name="sayHi" type="tns:sayHi"/> <xs:element name="sayHiResponse" type="tns:sayHiResponse"/> <xs:complexType name="sayHi"> <xs:sequence> <xs:element minOccurs="0" name="arg0" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="sayHiResponse"> <xs:sequence> <xs:element minOccurs="0" name="return" type="xs:int"/> </xs:sequence> </xs:complexType> </xs:schema> </wsdl:types> 

5. message(请求和响应参数)

通信消息的数据结构的抽象类型化定义。引用types中定义的标签,包含请求和响应的参数名称和参数类型,此节点的name属性是请求方法加上类型,如请求是请求方法加上Request,此方法的响应是方法名加上Response

6. portType

对于某个访问入口点类型所支持的操作的抽象集合,这些操作可以由一个或多个服务访问点来支持。

友情提醒

如果解析soup协议返回的报文或者解析wsdl文件,我们会看到xml文件的节点会有soup开头的和wsdl开头的,但是解析的时候获取节点不用加上那个,只要后面的名称,如wsdl:import节点,解析是用import获取才能获取到

请求需要的信息

  1. 请求地址带?wsdl的
  2. 命名空间:属性targetNamespace的值
  3. 请求方法:上面operation节点的name属性值
  4. 请求参数:上面types节点或者message节点的信息

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/111556.html

(0)
上一篇 2026-01-24 09:15
下一篇 2026-01-24 09:26

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信