??xml version="1.0" encoding="utf-8" standalone="yes"?> WS-Addressing moves the destination URL of the message into the message to enable routing and scenarios where messages are delivered over multiple protocols. Before WS-Addressing the URL of the destination was only available in the protocol part of the message. Is you were sending a SOAP message over HTTP, the URL was stored in the HTTP part of the message. You had no access to the URL from within your SOAP processor – unless your Web server vendor chose to give you access to the HTTP headers. Now with WS-Addressing built into WSE, the Web service platform can actually determine if a message was indeed intended for the service that received it because WSE adds the <to> element to the header of the SOAP message: <wsa:To xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing"> http://MyServer/MyService/Service.asmx</wsa:To> WSE is actually being smart about the header and rejects messages where the destination in the <wsa:To> header and the URL in the HTTP header do not match. One unfortunate consequence of this behavior is that you cannot use transparent tracing tools like tcpTrace and MSSoapT for message debugging. These tools act like an intermediary receiver and they do cause the URLs in the <To> header and in the HTTP header to not match. Z(jin)?/span>SOA的应用能够更加的成熟Q一些标准化l织(主要?/span>W
在tomcat容器下自创徏的web应用中也启动axis服务Q想要添加SOAPMonitor的方法是Q?br />
1、编?br />
axis根目录下的SOAPMonitorApplet.java文g复制到web应用的根目录下,~译此文件同时将生成的类文g复制到应用根目录下的WEB-INF目录下?br />
2、修改web.xml文g
修改WEB-INF目录下的web.xml文gQ添加两个元?lt;servlet>?lt;servlet-mapping>Q具体内容如下:(x)
<servlet>
<servlet-name>SOAPMonitorService</servlet-name>
<display-name>SOAPMonitorService</display-name>
<servlet-class>
org.apache.axis.monitor.SOAPMonitorService
</servlet-class>
<init-param>
<param-name>SOAPMonitorPort</param-name>
<param-value>5005</param-value>
</init-param>
<load-on-startup>100</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SOAPMonitorService</servlet-name>
<url-pattern>/SOAPMonitor</url-pattern>
</servlet-mapping>
3、修改server-config.wsdd文g
配置文g中添加soapmonitor的配|信息如Q?br />
<handler name="soapmonitor" type="java:org.apache.axis.handlers.SOAPMonitorHandler">
<service name="SOAPMonitorService" provider="java:RPC">
<parameter name="allowedMethods" value="publishMessage"/>
<parameter name="scope" value="Application"/>
<parameter name="className" value="org.apache.axis.monitor.SOAPMonitorService"/>
</service>
对于需要被soapmonitor监控的web服务Q在其服务设|中d信息如下
<service name="TestAdding" provider="java:RPC">
<parameter name="allowedMethods" value="getAdd"/>
<parameter name="className" value="test.TestAdding"/>
<requestFlow>
<handler type="soapmonitor"/>
</requestFlow>
<responseFlow>
<handler type="soapmonitor"/>
</responseFlow>
</service>
4、运行测?br />
http://localhost:8080/TestAdding/SOAPMonitor
呵呵Q好不容易折腑֥?jin),看来原来的想法还是对的,只不q在配置文g时出?jin)问题?/font>
]]>
Z(jin)使用Soap Toolkit 3.0Q我们在WS client端输入的目标地址为:(x)http://localhost:8080/WSEWebService/Service.asmx?br />
Soap Toolkit 3.0讄为:(x)
Listen
Local port:8080
Forward to
Destination:localhost
Destination:80
之所以这栯|,因ؓ(f)在IIS里设|的本机Web Services为:(x)http://localhost:80/WSEWebService/Service.asmx。Soap Toolkit ?080端口监听来自client端的消息Qƈ消息递交到IIS监听?0端口?br />
可当开启client端wse功能Ӟ抛出如下异常Q?
查看 Soap Toolkit 监听到的SOAP消息可以发现QRequest消息的SoapHeader? 目标地址仍然?span class="m"><wsa:To>http://localhost:8080/WSEWebService/Service.asmx</wsa:To> Q而不?span class="m"><wsa:To>http://localhost:80/WSEWebService/Service.asmx</wsa:To>.因此Qdestination不可达,抛出如上异常?br />
在网上查?jin)资料发玎ͼ?x)
“
不过Q好的消息是QW(xu)SE?.0开始就提供?jin)可以追t到SOAP消息的诊断工兗?br />
NEnable Message TraceQ在调试q程中,生成InputTrace.webinfo和OutputTrace.webinfo文gQ里面记录了(jin)我们惌的信息,到此Q不需要借助其他Trace工具便可q踪到Soap消息?br />
]]>
Destination port:80
Soap Toolkit是客L(fng)和服务器中的一座桥Qlocal port是Soap Toolkit的监听端口(所?0端口一般不能用,除非Ҏ(gu)讑֮Q,凡是l过local port的请求都?x)被截下来,然后由Soap Toolkit转发到Destination hostQDestination port厅R?br />
所以,W(xu)eb Services Client要将端口指定到Trace Utility的local port(L讑֮一个端?QTrace Utility的Destination port指定到WebService的端口。这P可以截获Soap消息?jin)?
]]>
理论?br />
WS-Addressing 问题的引?br />
WS-Addressing EndpointReference
WS-Addressing Message Addressing Properties
实践?/strong>
Applied WSE 3.0 to Web Service Project
Use Web Service Thought Message --- SoapClient
鉴于SOA的概念ƈ没有为大家所q泛理解Q在适当的时候有必要写一?span style="color: #333399;">SOA乱弹?/span>
不过先请你记住以下几句话Q?br />
SOA is an integration solution.
SOA is message oriented first.
The Key character of SOA is loosely coupled.
SOA is enriched by creating composite apps.
相关资源Q?br />
Web Services的设计与模式
Web Services Securitypd
参考资料:(x)WS-Addressing Specification
]]>
WSDL是一个用于精描qWeb服务的文档,W(xu)SDL文档是一个遵循WSDL XML模式的XML文档。WSDL 文档Web服务定义为服务访问点或端口的集合。在 WSDL 中,׃服务讉K点和消息的抽象定义已从具体的服务部v或数据格式绑定中分离出来Q因此可以对抽象定义q行再次使用Q消息,指对交换数据的抽象描qͼ而端 口类型,指操作的抽象集合。用于特定端口类型的具体协议和数据格式规范构成了(jin)可以再次使用的绑定。将Web讉K地址与可再次使用的绑定相兌Q可以定义一 个端口,而端口的集合则定义ؓ(f)服务?/p>
一个WSDL文档通常包含7个重要的元素Q即types、import、message、portType、operation、binding? service元素。这些元素嵌套在definitions元素中,definitions是WSDL文档的根元素。文章的下一部分会(x)详细介绍WSDL 的基本结构?/p>
二:(x)WSDL的基本结?-概述
如第一部分最后描q的那样Q一个基本的WSDL文档包含7个重要的元素。下面将分别介绍q几个元素以?qing)他们的作用?/p>
WSDL 文档在Web服务的定义中使用下列元素Q?/p>
可以参考下图来理解一下WSDL的文档结构图Q?img alt="WSDL文档元素的结构图" src="http://p.blog.csdn.net/images/p_blog_csdn_net/juxtapose/wsdl-01.gif" />
WSDL的xml schema可以参照如下|址Q?a target="_blank">http://schemas.xmlsoap.org/wsdl/
三:(x)WSDL的基本结?-详述
本节通过一个例子详l描qWSDL文档每个元素的作用。下面一个例子是一个简单的WSDL文档的内容,该文档的产生可以参见我的另外一文章:(x)xfire开发实?-HelloWorld?/a> ?/p>
一个简单的Web Service的WSDL文档Q该服务支持名ؓ(f)sayHello的唯一操作Q该操作通过在http上运?a target="_blank" >SOA
♦ types元素使用XML模式语言声明在WSDL文档中的其他位置使用的复杂数据类型与元素Q?/p>
♦ import元素cM于XML模式文档中的import元素Q用于从其他WSDL文档中导入WSDL定义Q?/p>
♦ message元素使用在WSDL文档的type元素中定义或在import元素引用的外部WSDL文档中定义的XML模式的内|类型、复杂类型或元素描述?jin)消息的有效负蝲Q?/p>
♦ portType元素和operation元素描述?jin)Web服务的接口ƈ定义?jin)他的方法。portType元素和operation元素cM? java接口和接口中定义的方法声明。operation元素使用一个或者多个messagecd来定义他的输入和输出的有效负载;
♦ Binding元素portType元素和operation元素赋给一个特D的协议和编码样式;
♦ service元素负责Internet地址赋给一个具体的l定Q?/p>
1、definitions元素
所有的WSDL文档的根元素均是definitions元素。该元素装?jin)整个文档,同时通过其name提供?jin)一个WSDL文档。除?jin)提供一个命名空间外Q该元素没有其他作用Q故不作详细描述?/p>
下面的代码是一个definitions元素的结构:(x)
2、types元素
WSDL采用?jin)W3C XML模式内置cd作ؓ(f)其基本类型系l。types元素用作一个容器,用于定义XML模式内置cd中没有描q的各种数据cd。当声明消息部分的有效负? Ӟ消息定义使用?jin)在types元素中定义的数据cd和元素。在本文的WSDL文档中的types定义Q?/p>
上面是数据定义部分,该部分定义了(jin)两个元素Q一个是sayHelloQ一个是sayHelloResponseQ?/p>
sayHelloQ定义了(jin)一个复杂类型,仅仅包含一个简单的字符Ԍ来用来描述操作的参入传入部分;
sayHelloResponseQ定义了(jin)一个复杂类型,仅仅包含一个简单的字符Ԍ来用来描述操作的返回|
3、import元素
import元素使得可以在当前的WSDL文档中用其他WSDL文档中指定的命名I间中的定义元素。本例子中没有用import元素。通常在用户希望模块化WSDL文档的时候,该功能是非常有效果的?/p>
import的格式如下:(x)
必须有namespace属性和location属性:(x)
namespace属性:(x)值必M正导入的WSDL文档中声明的targetNamespace相匹配;
location属性:(x)必须指向一个实际的WSDL文档Qƈ且该文档不能为空?/p>
4、message元素
message元素描述?jin)Web服务使用消息的有效负载。message元素可以描述输出或者接受消息的有效负蝲Q还可以描述SOAP文g头和错误detail元素的内宏V定义message元素的方式取决于使用RPC样式q是文档样式的消息传递。在本文中的message元素的定义,本文档用了(jin)采用文档样式的消息传递:(x)
该部分是消息格式的抽象定义:(x)定义?jin)两个消息sayHelloResponse和sayHelloRequestQ?/p>
sayHelloRequestQsayHello操作的请求消息格式,׃个消息片断组成,名字为parameters,元素是我们前面定义的types中的元素Q?/p>
sayHelloResponseQsayHello操作的响应消息格式,׃个消息片断组成,名字为parameters,元素是我们前面定义的types中的元素Q?/p>
如果采用RPC样式的消息传递,只需要将文档中的element元素应以修改为type卛_?/p>
5、portType元素
portType元素定义?jin)Web服务的抽象接口。该接口有点cMJava的接口,都是定义?jin)一个抽象类型和Ҏ(gu)Q没有定义实现。在WSDL中, portType元素是由binding和service元素来实现的Q这两个元素用来说明Web服务实现使用的Internet协议、编码方案以? Internet地址?/p>
一个portType中可以定义多个operationQ一个operation可以看作是一个方法,本文中WSDL文档的定义:(x)
portType定义?jin)服务的调用模式的类型,q里包含一个操作sayHelloҎ(gu)Q同时包含input和output表明该操作是一个请求/? 应模式,h消息是前面定义的sayHelloRequestQ响应消息是前面定义的sayHelloResponse。input表示传递到Web服务 的有效负载,output消息表示传递给客户的有效负载?/p>
Q、binding
binding元素一个抽象portType映射Cl具体协?SOAO和HTTP)、消息传递样式、编码样式。通常binding元素与协议专有的元素和在一起用,本文中的例子Q?/p>
q部分将服务讉K点的抽象定义?a target="_blank" >SOAP HTTPl定Q描q如何通过SOAP/HTTP来访问按照前面描q的讉K入口点类型部|的讉K入口。其中规定了(jin)在具?a target="_blank" ?/p>
具体的用需要参考特定协议定义的元素?/p>
Q、service元素和port元素
service元素包含一个或者多个port元素Q其中每个port元素表示一个不同的Web服务。port元素URL赋给一个特定的bindingQ甚臛_以两个或者多个port元素不同的URL赋值给相同的binding。文档中的例子:(x)
q部分是具体的Web服务的定义,在这个名为HelloService的Web服务中,提供?jin)一个服务访问入口,讉K地址?a href="http://localhost:8080/xfire/services/HelloService" target="_blank">http://localhost:8080/xfire/services/HelloServiceQ用的消息模式是由前面的binding所定义的?/p>
本文单介l了(jin)WSDL规范的用途,基本l构和用方法,希望对大家学?fn)WSDL有帮助?/p>