WebService 之 WSDL文件 讲解
http://blog.csdn.net/simbi/article/details/6254146 恩,我想说的是,是不是经常有人在开发的时候,特别是和第三方有接口的时候,走的是SOAP协议,然后用户给你一个WSDL文件,说按照上面的进行适配,嘿嘿,这个时候,要是你以前没有开发过,肯定会傻眼,那如果你想学习的话,就认真的看下面的讲解咯: 一、WSDL概述 二、WSDL基本结构 ??????????? WSDL的声明必须定义成使用:UTF-8 或者UTF-16 编码。 ??????? 3.2 definition元素 ?????????????????????????xmlns:xsd="http://www.w3.org/2001/XMLSchema" ? ?定义了targetNamespace命名空间,它为在模式中显式创建的所有新类型均声明了XML命名空间,而且上面的例子中赋予了mh前缀。 ? ???????? 上面的例子中:message元素利用name属性指定了标签(例如:GetBookPriceRequest),这些标签会自动使用targetNamespace的命名空间,标签了的messages元素通常被称为定义。 ???????? Types元素作为一个容器,用来定义XML模式内置的数据类型(即复杂类型和定制的简单类现,详细见Web Service XML文章)中没有描述的各种数据类型。例如:ISBN。 ??????? ? WSDL的import元素必须声明两个属性,即namespace属性和location属性。 ??????? 4.4 WSDL消息交换模式(MEP) ????????????? Messaging Exchange Patterns(MEP) ????????????? Web服务中使用了四种消息交换模式,即请求/响应、单向、通知以及恳求/响应模式。大多数基于WSDL的web服务使用请求/响应和单向两种模式。 ??????????????WSDL通过operation元素的input/output来定义使用那种模式,如果有input+output+可选的fault参数,那就使用请求/响应模式;如果只使用input,那就使用单向模式。 ????????????? 在通知模式中:Web服务将消息发送给客户,但不等待回复;一般客户通过注册来接收通知;在恳求/响应模式中类似通知模式,唯一的区别要期待客户对Web服务的响应。 五、WSDL实现:binding元素 ??????? Binding元素将一个抽象的portType映射到一组具体的协议(SOAP或者HTTP)、消息传递样式(RPC或者document)以及编码样式(literal或者SOAP encoding)。 ??????? Binding的类似于将接口或者函数的调用绑定到某种协议上:例如CORBA、COM或者RPC的方式,这里使用SOAP协议。 ??????? 5.1 soapbind:binding元素 ???????? 5.2 soapbind:operation元素 ?????? 5.3 soapbind:body元素 ??????????5.4 soapbind:fault元素 ????????? 5.5 soapbind:header元素 ??????? 5.6 soapbind:headerfault元素?? 六、WSDL实现:Service和Port元素
?
<?
xml version="1.0" encoding="UTF-8"
?>
-
<
wsdl:definitions
name
="
HelloWorldImplService
"
targetNamespace
="
http://server.cxf.apache.org/
"
xmlns:ns1
="
http://cxf.apache.org/bindings/xformat
"
xmlns:soap
="
http://schemas.xmlsoap.org/wsdl/soap/
"
xmlns:tns
="
http://server.cxf.apache.org/
"
xmlns:wsdl
="
http://schemas.xmlsoap.org/wsdl/
"
xmlns:xsd
="
http://www.w3.org/2001/XMLSchema
"
>
-
<
wsdl:types
>
-
<
xs:schema
elementFormDefault
="
unqualified
"
targetNamespace
="
http://server.cxf.apache.org/
"
version
="
1.0
"
xmlns:tns
="
http://server.cxf.apache.org/
"
xmlns:xs
="
http://www.w3.org/2001/XMLSchema
"
>
?
<
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
="
sayHi
"
>
?
<
wsdl:part
element
="
tns:sayHi
"
name
="
parameters
"
/>
?
</
wsdl:message
>
-
<
wsdl:message
name
="
sayHiResponse
"
>
?
<
wsdl:part
element
="
tns:sayHiResponse
"
name
="
parameters
"
/>
?
</
wsdl:message
>
-
<
wsdl:portType
name
="
HelloWorld
"
>
-
<
wsdl:operation
name
="
sayHi
"
>
?
<
wsdl:input
message
="
tns:sayHi
"
name
="
sayHi
"
/>
?
<
wsdl:output
message
="
tns:sayHiResponse
"
name
="
sayHiResponse
"
/>
?
</
wsdl:operation
>
?
</
wsdl:portType
>
-
<
wsdl:binding
name
="
HelloWorldImplServiceSoapBinding
"
type
="
tns:HelloWorld
"
>
?
<
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
="
HelloWorldImplService
"
>
-
<
wsdl:port
binding
="
tns:HelloWorldImplServiceSoapBinding
"
name
="
HelloWorldImplPort
"
>
?
<
soap:address
location
="
http://localhost:8080/cxf/ws/HelloWorld
"
/>
?
</
wsdl:port
>
?
</
wsdl:service
>
?
</
wsdl:definitions
>
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |