微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

WebService—wsdl的简单介绍(未完)

WSDL简介@H_404_7@

WSDL,Web Services Description Language,Web Service的描述语言,是一种接口定义语言,用于描述Web Service的接口信息等。(描述Web服务和说明如何与Web服务通信的XML语言。为用户提供详细的接口说明书。)@H_404_7@

WSDL元素@H_404_7@

WSDL有五大元素,分别是types,message,portType,binding和service。@H_404_7@

  types:用来定义访问的类型
  message:SOAP Message
  portType:指明服务器的接口,并且通过operation绑定相应的in和out消息(in:参数,out:返回值)
  binding:指定传递消息所使用的格式
  service:指定服务所发布的名称
@H_404_7@

下方为 代码优先 生成的wsdl文件@H_404_7@

<?xml version="1.0" encoding="UTF-8"?>
<deFinitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/Metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://service.zttc.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://service.zttc.org/" name="MyServiceImplService">
	<!-- types:用来定义访问的类型 -->
	<types>
		<xsd:schema>
			<xsd:import namespace="http://service.zttc.org/" schemaLocation="http://localhost:8887/ns?xsd=1"></xsd:import>
		</xsd:schema>
	</types>
	<!-- message:SOAP Message,消息体 -->
	<message name="minus">
		<part name="parameters" element="tns:minus"></part>
	</message>
	<message name="minusResponse">
		<part name="parameters" element="tns:minusResponse"></part>
	</message>
	<message name="login">
		<part name="parameters" element="tns:login"></part>
	</message>
	<message name="loginResponse">
		<part name="parameters" element="tns:loginResponse"></part>
	</message>
	<message name="add">
		<part name="parameters" element="tns:add"></part>
	</message>
	<message name="addResponse">
		<part name="parameters" element="tns:addResponse"></part>
	</message>
	<!-- portType:端口类型,指明服务器的接口 -->
	<portType name="IMyService">
		<!-- 并且通过operation绑定相应的in和out消息(in:参数,out:返回值)-->
		<!-- operation,操作,对服务所支持的操作进行抽象描述 -->
		<operation name="minus">
			<input wsam:Action="http://service.zttc.org/IMyService/minusRequest" message="tns:minus"></input>
			<output wsam:Action="http://service.zttc.org/IMyService/minusResponse" message="tns:minusResponse"></output>
		</operation>
		<operation name="login">
			<input wsam:Action="http://service.zttc.org/IMyService/loginRequest" message="tns:login"></input>
			<output wsam:Action="http://service.zttc.org/IMyService/loginResponse" message="tns:loginResponse"></output>
		</operation>
		<operation name="add">
			<input wsam:Action="http://service.zttc.org/IMyService/addRequest" message="tns:add"></input>
			<output wsam:Action="http://service.zttc.org/IMyService/addResponse" message="tns:addResponse"></output>
		</operation>
	</portType>
	<!-- binding:使用的通信协议,指定传递消息所使用的格式 -->
	<binding name="MyServiceImplPortBinding" type="tns:IMyService">
		<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
		<operation name="minus">
			<soap:operation soapAction=""></soap:operation>
			<input>
				<soap:body use="literal"></soap:body>
			</input>
			<output>
				<soap:body use="literal"></soap:body>
			</output>
		</operation>
		<operation name="login">
			<soap:operation soapAction=""></soap:operation>
			<input>
				<soap:body use="literal"></soap:body>
			</input>
			<output>
				<soap:body use="literal"></soap:body>
			</output>
		</operation>
		<operation name="add">
			<soap:operation soapAction=""></soap:operation>
			<input>
				<soap:body use="literal"></soap:body>
			</input>
			<output>
				<soap:body use="literal"></soap:body>
			</output>
		</operation>
	</binding>
	<!-- service:指定服务所发布的名称 -->
	<service name="MyServiceImplService">
		<!-- 定义为绑定和网络地址组合的单个端点 -->
		<port name="MyServiceImplPort" binding="tns:MyServiceImplPortBinding">
			<soap:address location="http://localhost:8887/ns"></soap:address>
		</port>
	</service>
</deFinitions>


下方为 契约优先,手动编写的wsdl文件@H_404_7@

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:deFinitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
	xmlns:tns="http://www.example.org/mywsdl/" 
	xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
	xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
	name="MyServiceImplService" 
	targetNamespace="http://www.example.org/mywsdl/">
  
  <!-- types:用来定义访问的类型 -->
  <wsdl:types>
    <xsd:schema targetNamespace="http://www.example.org/mywsdl/">
    	<xsd:element name="plus" type="tns:plus" />
    	<xsd:element name="plusResponse" type="tns:plusResponse" />
    	<xsd:element name="minus" type="tns:minus" />
    	<xsd:element name="minusResponse" type="tns:minusResponse" />
    	<xsd:element name="licenseInfo" type="xsd:string" />
    	
    	<xsd:complexType name="plus">
    		<xsd:sequence>
    			<xsd:element name="a" type="xsd:int" />
    			<xsd:element name="b" type="xsd:int" />
    		</xsd:sequence>
    	</xsd:complexType>
    	<xsd:complexType name="plusResponse">
    		<xsd:sequence>
    			<xsd:element name="plusResult" type="xsd:int" />
    		</xsd:sequence>
    	</xsd:complexType>
    	<xsd:complexType name="minus">
    		<xsd:sequence>
    			<xsd:element name="num1" type="xsd:int" />
    			<xsd:element name="num2" type="xsd:int" />
    		</xsd:sequence>
    	</xsd:complexType>
    	<xsd:complexType name="minusResponse">
    		<xsd:sequence>
    			<xsd:element name="minusResult" type="xsd:int" />
    		</xsd:sequence>
    	</xsd:complexType>
    </xsd:schema>
  </wsdl:types>
  
  <!-- message:SOAP Message,消息体 -->
  <wsdl:message name="plus">
  	<wsdl:part name="plus" element="tns:plus" />
  </wsdl:message>
  <wsdl:message name="plusResponse">
  	<wsdl:part name="plusResponse" element="tns:plusResponse" />
  </wsdl:message>
  <wsdl:message name="minus">
  	<wsdl:part name="minus" element="tns:minus" />
  </wsdl:message>
  <wsdl:message name="minusResponse">
  	<wsdl:part name="minusResponse" element="tns:minusResponse" />
  </wsdl:message>
  <wsdl:message name="licenseInfo">
  	<wsdl:part name="licenseInfo" element="tns:licenseInfo" />
  </wsdl:message>
  
  <!-- portType:端口类型,指明服务器的接口 -->
  <wsdl:portType name="IMyService">
	<!-- 并且通过operation绑定相应的in和out消息(in:参数,out:返回值)-->
  	<wsdl:operation name="plus">
  		<wsdl:input message="tns:plus" />
  		<wsdl:output message="tns:plusResponse" />
  	</wsdl:operation>
  	
  	<wsdl:operation name="minus">
  		<wsdl:input message="tns:minus" />
  		<wsdl:output message="tns:minusResponse" />
  	</wsdl:operation>
  </wsdl:portType>
  
  <!-- binding:使用的通信协议,指定传递消息所使用的格式 -->
  <wsdl:binding name="myServiceSOAP" type="tns:IMyService">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="plus">
      <wsdl:input>
        <soap:body use="literal"/>
        <soap:header use="literal" part="licenseInfo" message="tns:licenseInfo" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    
    <wsdl:operation name="minus">
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  
  <!-- service:指定服务所发布的名称 -->
  <wsdl:service name="MyServiceImplService">
    <wsdl:port binding="tns:myServiceSOAP" name="MyServiceImplPort">
      <soap:address location="http://localhost:8989/ms"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:deFinitions>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐