﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-风人园-文章分类-Web Service</title><link>http://www.blogjava.net/wuxufeng8080/category/12717.html</link><description /><language>zh-cn</language><lastBuildDate>Sat, 03 Mar 2007 05:00:07 GMT</lastBuildDate><pubDate>Sat, 03 Mar 2007 05:00:07 GMT</pubDate><ttl>60</ttl><item><title>Java6 WebServices （二）客户端 (ZT)</title><link>http://www.blogjava.net/wuxufeng8080/articles/89492.html</link><dc:creator>风人园</dc:creator><author>风人园</author><pubDate>Fri, 22 Dec 2006 04:54:00 GMT</pubDate><guid>http://www.blogjava.net/wuxufeng8080/articles/89492.html</guid><description><![CDATA[
		<div class="postbody">在<a href="http://blog.csdn.net/vip01/archive/2006/12/20/1450269.aspx" _fcksavedurl="http://blog.csdn.net/vip01/archive/2006/12/20/1450269.aspx"><font color="#1d58d1">Java6 WebServices （一）服务端</font></a>这篇文章中和大家分享了Java6 WebServices 服务端的写法，光有服务端还不行，还要有客户端才行啊。看了一些网友的相关文章，都只给出了服务端的写法，没有说客户端怎么说。经过一番研究，终于搞定了客户端，今天偶就和大家分享下。<br />首先启动<a href="http://blog.csdn.net/vip01/archive/2006/12/20/1450269.aspx" _fcksavedurl="http://blog.csdn.net/vip01/archive/2006/12/20/1450269.aspx"><font color="#1d58d1">Java6 WebServices （一）服务端</font></a>一文中写好的服务端。<br />新建个项目。命令行到src目录执行，<br />wsimport -keep  http://localhost:8080/HelloService?wsdl<br />会自动生成一些代码。<br /><br /><div style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: rgb(230,230,230) 0% 50%; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"><div><span style="COLOR: rgb(0,0,0)"><br /></span><span style="COLOR: rgb(0,0,255)">package</span><span style="COLOR: rgb(0,0,0)"> org.hermit.study.jdk.client;<br /><br /></span><span style="COLOR: rgb(0,0,255)">import</span><span style="COLOR: rgb(0,0,0)"> javax.jws.WebMethod;<br /></span><span style="COLOR: rgb(0,0,255)">import</span><span style="COLOR: rgb(0,0,0)"> javax.jws.WebParam;<br /></span><span style="COLOR: rgb(0,0,255)">import</span><span style="COLOR: rgb(0,0,0)"> javax.jws.WebResult;<br /></span><span style="COLOR: rgb(0,0,255)">import</span><span style="COLOR: rgb(0,0,0)"> javax.jws.WebService;<br /></span><span style="COLOR: rgb(0,0,255)">import</span><span style="COLOR: rgb(0,0,0)"> javax.jws.soap.SOAPBinding;<br /><br /><br /></span><span style="COLOR: rgb(0,128,0)">/**</span><span style="COLOR: rgb(0,128,0)"><br /> * This class was generated by the JAXWS SI.<br /> * JAX-WS RI 2.0_02-b08-fcs<br /> * Generated source version: 2.0<br /> * <br /> </span><span style="COLOR: rgb(0,128,0)">*/</span><span style="COLOR: rgb(0,0,0)"><br />@WebService(name </span><span style="COLOR: rgb(0,0,0)">=</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">Hello</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">, targetNamespace </span><span style="COLOR: rgb(0,0,0)">=</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">http://jdk.study.hermit.org/client</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">)<br />@SOAPBinding(style </span><span style="COLOR: rgb(0,0,0)">=</span><span style="COLOR: rgb(0,0,0)"> SOAPBinding.Style.RPC)<br /></span><span style="COLOR: rgb(0,0,255)">public</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,255)">interface</span><span style="COLOR: rgb(0,0,0)"> Hello {<br /><br /><br />    </span><span style="COLOR: rgb(0,128,0)">/**</span><span style="COLOR: rgb(0,128,0)"><br />     * <br />     * </span><span style="COLOR: rgb(128,128,128)">@param</span><span style="COLOR: rgb(0,128,0)"> arg0<br />     * </span><span style="COLOR: rgb(128,128,128)">@return</span><span style="COLOR: rgb(0,128,0)"><br />     *     returns java.lang.String<br />     </span><span style="COLOR: rgb(0,128,0)">*/</span><span style="COLOR: rgb(0,0,0)"><br />    @WebMethod<br />    @WebResult(partName </span><span style="COLOR: rgb(0,0,0)">=</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">return</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">)<br />    </span><span style="COLOR: rgb(0,0,255)">public</span><span style="COLOR: rgb(0,0,0)"> String sayHello(<br />        @WebParam(name </span><span style="COLOR: rgb(0,0,0)">=</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">arg0</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">, partName </span><span style="COLOR: rgb(0,0,0)">=</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">arg0</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">)<br />        String arg0);<br /><br />}<br /></span></div></div><div style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: rgb(230,230,230) 0% 50%; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"><div><span style="COLOR: rgb(0,0,0)"><br /></span><span style="COLOR: rgb(0,0,255)">package</span><span style="COLOR: rgb(0,0,0)"> org.hermit.study.jdk.client;<br /><br /></span><span style="COLOR: rgb(0,0,255)">import</span><span style="COLOR: rgb(0,0,0)"> java.net.MalformedURLException;<br /></span><span style="COLOR: rgb(0,0,255)">import</span><span style="COLOR: rgb(0,0,0)"> java.net.URL;<br /></span><span style="COLOR: rgb(0,0,255)">import</span><span style="COLOR: rgb(0,0,0)"> javax.xml.namespace.QName;<br /></span><span style="COLOR: rgb(0,0,255)">import</span><span style="COLOR: rgb(0,0,0)"> javax.xml.ws.Service;<br /></span><span style="COLOR: rgb(0,0,255)">import</span><span style="COLOR: rgb(0,0,0)"> javax.xml.ws.WebEndpoint;<br /></span><span style="COLOR: rgb(0,0,255)">import</span><span style="COLOR: rgb(0,0,0)"> javax.xml.ws.WebServiceClient;<br /><br /><br /></span><span style="COLOR: rgb(0,128,0)">/**</span><span style="COLOR: rgb(0,128,0)"><br /> * This class was generated by the JAXWS SI.<br /> * JAX-WS RI 2.0_02-b08-fcs<br /> * Generated source version: 2.0<br /> * <br /> </span><span style="COLOR: rgb(0,128,0)">*/</span><span style="COLOR: rgb(0,0,0)"><br />@WebServiceClient(name </span><span style="COLOR: rgb(0,0,0)">=</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">HelloService</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">, targetNamespace </span><span style="COLOR: rgb(0,0,0)">=</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">http://jdk.study.hermit.org/client</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">, wsdlLocation </span><span style="COLOR: rgb(0,0,0)">=</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">http://localhost:8080/HelloService?wsdl</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">)<br /></span><span style="COLOR: rgb(0,0,255)">public</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,255)">class</span><span style="COLOR: rgb(0,0,0)"> HelloService<br />    </span><span style="COLOR: rgb(0,0,255)">extends</span><span style="COLOR: rgb(0,0,0)"> Service<br />{<br /><br />    </span><span style="COLOR: rgb(0,0,255)">private</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,255)">final</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,255)">static</span><span style="COLOR: rgb(0,0,0)"> URL HELLOSERVICE_WSDL_LOCATION;<br /><br />    </span><span style="COLOR: rgb(0,0,255)">static</span><span style="COLOR: rgb(0,0,0)"> {<br />        URL url </span><span style="COLOR: rgb(0,0,0)">=</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,255)">null</span><span style="COLOR: rgb(0,0,0)">;<br />        </span><span style="COLOR: rgb(0,0,255)">try</span><span style="COLOR: rgb(0,0,0)"> {<br />            url </span><span style="COLOR: rgb(0,0,0)">=</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,255)">new</span><span style="COLOR: rgb(0,0,0)"> URL(</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">http://localhost:8080/HelloService?wsdl</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">);<br />        } </span><span style="COLOR: rgb(0,0,255)">catch</span><span style="COLOR: rgb(0,0,0)"> (MalformedURLException e) {<br />            e.printStackTrace();<br />        }<br />        HELLOSERVICE_WSDL_LOCATION </span><span style="COLOR: rgb(0,0,0)">=</span><span style="COLOR: rgb(0,0,0)"> url;<br />    }<br /><br />    </span><span style="COLOR: rgb(0,0,255)">public</span><span style="COLOR: rgb(0,0,0)"> HelloService(URL wsdlLocation, QName serviceName) {<br />        </span><span style="COLOR: rgb(0,0,255)">super</span><span style="COLOR: rgb(0,0,0)">(wsdlLocation, serviceName);<br />    }<br /><br />    </span><span style="COLOR: rgb(0,0,255)">public</span><span style="COLOR: rgb(0,0,0)"> HelloService() {<br />        </span><span style="COLOR: rgb(0,0,255)">super</span><span style="COLOR: rgb(0,0,0)">(HELLOSERVICE_WSDL_LOCATION, </span><span style="COLOR: rgb(0,0,255)">new</span><span style="COLOR: rgb(0,0,0)"> QName(</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">http://jdk.study.hermit.org/client</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">, </span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">HelloService</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">));<br />    }<br /><br />    </span><span style="COLOR: rgb(0,128,0)">/**</span><span style="COLOR: rgb(0,128,0)"><br />     * <br />     * </span><span style="COLOR: rgb(128,128,128)">@return</span><span style="COLOR: rgb(0,128,0)"><br />     *     returns Hello<br />     </span><span style="COLOR: rgb(0,128,0)">*/</span><span style="COLOR: rgb(0,0,0)"><br />    @WebEndpoint(name </span><span style="COLOR: rgb(0,0,0)">=</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">HelloPort</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">)<br />    </span><span style="COLOR: rgb(0,0,255)">public</span><span style="COLOR: rgb(0,0,0)"> Hello getHelloPort() {<br />        </span><span style="COLOR: rgb(0,0,255)">return</span><span style="COLOR: rgb(0,0,0)"> (Hello)</span><span style="COLOR: rgb(0,0,255)">super</span><span style="COLOR: rgb(0,0,0)">.getPort(</span><span style="COLOR: rgb(0,0,255)">new</span><span style="COLOR: rgb(0,0,0)"> QName(</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">http://jdk.study.hermit.org/client</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">, </span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">HelloPort</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">), Hello.</span><span style="COLOR: rgb(0,0,255)">class</span><span style="COLOR: rgb(0,0,0)">);<br />    }<br /><br />}<br /></span></div></div><br />下面我们再写个测试，看看能不能用：<br /><div style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: rgb(230,230,230) 0% 50%; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"><div><span style="COLOR: rgb(0,0,255)">package</span><span style="COLOR: rgb(0,0,0)"> org.hermit.study.jdk.client.test;<br /><br /></span><span style="COLOR: rgb(0,0,255)">import</span><span style="COLOR: rgb(0,0,0)"> org.hermit.study.jdk.client.Hello;<br /></span><span style="COLOR: rgb(0,0,255)">import</span><span style="COLOR: rgb(0,0,0)"> org.hermit.study.jdk.client.HelloService;<br /><br /><br /></span><span style="COLOR: rgb(0,0,255)">public</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,255)">class</span><span style="COLOR: rgb(0,0,0)"> TestClient {<br />    </span><span style="COLOR: rgb(0,0,255)">public</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,255)">static</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,255)">void</span><span style="COLOR: rgb(0,0,0)"> main(String[] args) {<br />        HelloService service </span><span style="COLOR: rgb(0,0,0)">=</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,255)">new</span><span style="COLOR: rgb(0,0,0)"> HelloService();<br />        Hello _hello </span><span style="COLOR: rgb(0,0,0)">=</span><span style="COLOR: rgb(0,0,0)"> service.getHelloPort();<br />        System.out.println(_hello.sayHello(</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">hermit</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">));<br />    }<br />}</span></div></div>执行。<br />控制台输出：<br />hello:hermit<br /><br />ok！搞定。<br />java6搞定web service就这么简单。。。。。。。。。。。。。。。。。。。。。。。。。。<br /><br />xfire危险了。。。。。。。。。。。。。。。。。。。。。。。。</div>
<img src ="http://www.blogjava.net/wuxufeng8080/aggbug/89492.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wuxufeng8080/" target="_blank">风人园</a> 2006-12-22 12:54 <a href="http://www.blogjava.net/wuxufeng8080/articles/89492.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java6 WebServices （一）服务端 (ZT)</title><link>http://www.blogjava.net/wuxufeng8080/articles/89491.html</link><dc:creator>风人园</dc:creator><author>风人园</author><pubDate>Fri, 22 Dec 2006 04:53:00 GMT</pubDate><guid>http://www.blogjava.net/wuxufeng8080/articles/89491.html</guid><description><![CDATA[Java6发布了，其中一个吸引我的新特性就是原生支持WebServices。在这和大家分享下学习心得。<br />下面就开始写个最简单的WebServices：<br /><div style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: rgb(230,230,230) 0% 50%; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"><div><span style="COLOR: rgb(0,0,255)">package</span><span style="COLOR: rgb(0,0,0)"> org.hermit.study.jdk;<br /><br /></span><span style="COLOR: rgb(0,0,255)">import</span><span style="COLOR: rgb(0,0,0)"> javax.jws.WebMethod;<br /></span><span style="COLOR: rgb(0,0,255)">import</span><span style="COLOR: rgb(0,0,0)"> javax.jws.WebService;<br /></span><span style="COLOR: rgb(0,0,255)">import</span><span style="COLOR: rgb(0,0,0)"> javax.jws.soap.SOAPBinding;<br /><br />@WebService(targetNamespace </span><span style="COLOR: rgb(0,0,0)">=</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">http://jdk.study.hermit.org/client</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">)<br />@SOAPBinding(style </span><span style="COLOR: rgb(0,0,0)">=</span><span style="COLOR: rgb(0,0,0)"> SOAPBinding.Style.RPC)<br /></span><span style="COLOR: rgb(0,0,255)">public</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,255)">class</span><span style="COLOR: rgb(0,0,0)"> Hello {<br />    @WebMethod<br />    </span><span style="COLOR: rgb(0,0,255)">public</span><span style="COLOR: rgb(0,0,0)"> String sayHello(String name) {<br />        </span><span style="COLOR: rgb(0,0,255)">return</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">hello:</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,0)">+</span><span style="COLOR: rgb(0,0,0)"> name;<br />    }<br />}<br /></span></div></div>怎么样简洁吧，很多朋友的写法还要在命令行中执行“<span style="FONT-FAMILY: 'Courier New',Courier,monospace"><span style="COLOR: rgb(0,0,0)">wsgen –cp . &lt;path&gt;</span></span>”<br />用偶这种方法写的service可以省去上面这步。<br /><br />targetNamespace = "http://jdk.study.hermit.org/client"这句是指定客户端获取服务端服务后存放的类路径。注意是反着的，http: //jdk.study.hermit.org/client在客户端生成的类会放在org.hermit.study.jdk.client包下。<br />下面是发布服务：<br /><div style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: rgb(230,230,230) 0% 50%; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"><div><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" _fcksavedurl="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" /><span style="COLOR: rgb(0,0,255)">package</span><span style="COLOR: rgb(0,0,0)"> org.hermit.study.jdk;<br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" _fcksavedurl="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" /><br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" _fcksavedurl="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" /></span><span style="COLOR: rgb(0,0,255)">import</span><span style="COLOR: rgb(0,0,0)"> javax.xml.ws.Endpoint;<br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" _fcksavedurl="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" /><br /><img id="_88_206_Open_Image" onclick="this.style.display='none'; document.getElementById('_88_206_Open_Text').style.display='none'; document.getElementById('_88_206_Closed_Image').style.display='inline'; document.getElementById('_88_206_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align="top" _fcksavedurl="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" /><img id="_88_206_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_88_206_Closed_Text').style.display='none'; document.getElementById('_88_206_Open_Image').style.display='inline'; document.getElementById('_88_206_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align="top" _fcksavedurl="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" /></span><span style="COLOR: rgb(0,0,255)">public</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,255)">class</span><span style="COLOR: rgb(0,0,0)"> StartService </span><span id="_88_206_Closed_Text" style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">...</span><span id="_88_206_Open_Text"><span style="COLOR: rgb(0,0,0)">{<br /><img id="_130_204_Open_Image" onclick="this.style.display='none'; document.getElementById('_130_204_Open_Text').style.display='none'; document.getElementById('_130_204_Closed_Image').style.display='inline'; document.getElementById('_130_204_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" _fcksavedurl="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" /><img id="_130_204_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_130_204_Closed_Text').style.display='none'; document.getElementById('_130_204_Open_Image').style.display='inline'; document.getElementById('_130_204_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top" _fcksavedurl="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" />    </span><span style="COLOR: rgb(0,0,255)">public</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,255)">static</span><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,255)">void</span><span style="COLOR: rgb(0,0,0)"> main(String[] args) </span><span id="_130_204_Closed_Text" style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">...</span><span id="_130_204_Open_Text"><span style="COLOR: rgb(0,0,0)">{<br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" _fcksavedurl="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" />        Endpoint.publish(</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">http://localhost:8080/HelloService</span><span style="COLOR: rgb(0,0,0)">"</span><span style="COLOR: rgb(0,0,0)">, </span><span style="COLOR: rgb(0,0,255)">new</span><span style="COLOR: rgb(0,0,0)"> Hello());<br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" _fcksavedurl="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" />    }</span></span><span style="COLOR: rgb(0,0,0)"><br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align="top" _fcksavedurl="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" />}</span></span></div></div>呵呵，更简洁。一句话而已。<br /><span id="_88_206_Open_Text"><span id="_130_204_Open_Text"><span style="COLOR: rgb(0,0,0)">http://localhost:8080/HelloService是指发布的地址<br /><br />运行</span></span></span><span style="COLOR: rgb(0,0,0)">StartService </span><span id="_88_206_Closed_Text" style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">...</span><span id="_88_206_Open_Text"><span style="COLOR: rgb(0,0,0)">，开发浏览器输入：http://localhost:8080/HelloService?wsdl<br /><br /></span></span><br /><br />如果能看到以下内容，就可以<br /><div style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: rgb(230,230,230) 0% 50%; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"><div><span style="COLOR: rgb(0,0,0)"> </span><span style="COLOR: rgb(0,0,255)">&lt;?</span><span style="COLOR: rgb(255,0,255)">xml version="1.0" encoding="UTF-8" </span><span style="COLOR: rgb(0,0,255)">?&gt;</span><span style="COLOR: rgb(0,0,0)"> <br />- </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">definitions </span><span style="COLOR: rgb(255,0,0)">xmlns</span><span style="COLOR: rgb(0,0,255)">="http://schemas.xmlsoap.org/wsdl/"</span><span style="COLOR: rgb(255,0,0)"> xmlns:tns</span><span style="COLOR: rgb(0,0,255)">="http://jdk.study.hermit.org/client"</span><span style="COLOR: rgb(255,0,0)"> xmlns:xsd</span><span style="COLOR: rgb(0,0,255)">="http://www.w3.org/2001/XMLSchema"</span><span style="COLOR: rgb(255,0,0)"> xmlns:soap</span><span style="COLOR: rgb(0,0,255)">="http://schemas.xmlsoap.org/wsdl/soap/"</span><span style="COLOR: rgb(255,0,0)"> targetNamespace</span><span style="COLOR: rgb(0,0,255)">="http://jdk.study.hermit.org/client"</span><span style="COLOR: rgb(255,0,0)"> name</span><span style="COLOR: rgb(0,0,255)">="HelloService"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />  </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">types </span><span style="COLOR: rgb(0,0,255)">/&gt;</span><span style="COLOR: rgb(0,0,0)"> <br />- </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">message </span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="sayHello"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />  </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">part </span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="arg0"</span><span style="COLOR: rgb(255,0,0)"> type</span><span style="COLOR: rgb(0,0,255)">="xsd:string"</span><span style="COLOR: rgb(255,0,0)"> </span><span style="COLOR: rgb(0,0,255)">/&gt;</span><span style="COLOR: rgb(0,0,0)"> <br />  </span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">message</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />- </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">message </span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="sayHelloResponse"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />  </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">part </span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="return"</span><span style="COLOR: rgb(255,0,0)"> type</span><span style="COLOR: rgb(0,0,255)">="xsd:string"</span><span style="COLOR: rgb(255,0,0)"> </span><span style="COLOR: rgb(0,0,255)">/&gt;</span><span style="COLOR: rgb(0,0,0)"> <br />  </span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">message</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />- </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">portType </span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="Hello"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />- </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">operation </span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="sayHello"</span><span style="COLOR: rgb(255,0,0)"> parameterOrder</span><span style="COLOR: rgb(0,0,255)">="arg0"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />  </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">input </span><span style="COLOR: rgb(255,0,0)">message</span><span style="COLOR: rgb(0,0,255)">="tns:sayHello"</span><span style="COLOR: rgb(255,0,0)"> </span><span style="COLOR: rgb(0,0,255)">/&gt;</span><span style="COLOR: rgb(0,0,0)"> <br />  </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">output </span><span style="COLOR: rgb(255,0,0)">message</span><span style="COLOR: rgb(0,0,255)">="tns:sayHelloResponse"</span><span style="COLOR: rgb(255,0,0)"> </span><span style="COLOR: rgb(0,0,255)">/&gt;</span><span style="COLOR: rgb(0,0,0)"> <br />  </span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">operation</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />  </span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">portType</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />- </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">binding </span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="HelloPortBinding"</span><span style="COLOR: rgb(255,0,0)"> type</span><span style="COLOR: rgb(0,0,255)">="tns:Hello"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />  </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">soap:binding </span><span style="COLOR: rgb(255,0,0)">style</span><span style="COLOR: rgb(0,0,255)">="rpc"</span><span style="COLOR: rgb(255,0,0)"> transport</span><span style="COLOR: rgb(0,0,255)">="http://schemas.xmlsoap.org/soap/http"</span><span style="COLOR: rgb(255,0,0)"> </span><span style="COLOR: rgb(0,0,255)">/&gt;</span><span style="COLOR: rgb(0,0,0)"> <br />- </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">operation </span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="sayHello"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />  </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">soap:operation </span><span style="COLOR: rgb(255,0,0)">soapAction</span><span style="COLOR: rgb(0,0,255)">=""</span><span style="COLOR: rgb(255,0,0)"> </span><span style="COLOR: rgb(0,0,255)">/&gt;</span><span style="COLOR: rgb(0,0,0)"> <br />- </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">input</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />  </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">soap:body </span><span style="COLOR: rgb(255,0,0)">use</span><span style="COLOR: rgb(0,0,255)">="literal"</span><span style="COLOR: rgb(255,0,0)"> namespace</span><span style="COLOR: rgb(0,0,255)">="http://jdk.study.hermit.org/client"</span><span style="COLOR: rgb(255,0,0)"> </span><span style="COLOR: rgb(0,0,255)">/&gt;</span><span style="COLOR: rgb(0,0,0)"> <br />  </span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">input</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />- </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">output</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />  </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">soap:body </span><span style="COLOR: rgb(255,0,0)">use</span><span style="COLOR: rgb(0,0,255)">="literal"</span><span style="COLOR: rgb(255,0,0)"> namespace</span><span style="COLOR: rgb(0,0,255)">="http://jdk.study.hermit.org/client"</span><span style="COLOR: rgb(255,0,0)"> </span><span style="COLOR: rgb(0,0,255)">/&gt;</span><span style="COLOR: rgb(0,0,0)"> <br />  </span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">output</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />  </span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">operation</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />  </span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">binding</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />- </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">service </span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="HelloService"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />- </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">port </span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="HelloPort"</span><span style="COLOR: rgb(255,0,0)"> binding</span><span style="COLOR: rgb(0,0,255)">="tns:HelloPortBinding"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />  </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">soap:address </span><span style="COLOR: rgb(255,0,0)">location</span><span style="COLOR: rgb(0,0,255)">="http://localhost:8080/HelloService"</span><span style="COLOR: rgb(255,0,0)"> </span><span style="COLOR: rgb(0,0,255)">/&gt;</span><span style="COLOR: rgb(0,0,0)"> <br />  </span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">port</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />  </span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">service</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />  </span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">definitions</span><span style="COLOR: rgb(0,0,255)">&gt;</span></div></div><img src ="http://www.blogjava.net/wuxufeng8080/aggbug/89491.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wuxufeng8080/" target="_blank">风人园</a> 2006-12-22 12:53 <a href="http://www.blogjava.net/wuxufeng8080/articles/89491.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>通过 Axis2 开发 Web 服务，第 1 部分: 通过 Axis2 运行时部署和使用简单 Web 服务</title><link>http://www.blogjava.net/wuxufeng8080/articles/56378.html</link><dc:creator>风人园</dc:creator><author>风人园</author><pubDate>Mon, 03 Jul 2006 09:01:00 GMT</pubDate><guid>http://www.blogjava.net/wuxufeng8080/articles/56378.html</guid><description><![CDATA[
		<p>
				<a name="N1006A">
						<span class="atitle">
								<font face="Arial" size="4">引言</font>
						</span>
				</a>
		</p>
		<p>Axis2 是下一代 Apache Axis。Axis2 虽然由 Axis 1.x 处理程序模型提供支持，但它具有更强的灵活性并可扩展到新的体系结构。Axis2 基于新的体系结构进行了全新编写，而且没有采用 Axis 1.x 的常用代码。支持开发 Axis2 的动力是探寻模块化更强、灵活性更高和更有效的体系结构，这种体系结构可以很容易地插入到其他相关 Web 服务标准和协议（如 WS-Security、WS-ReliableMessaging 等）的实现中。</p>
		<p>Axis2 的特性包括： 
</p>
		<ul>
				<li>采用名为 AXIOM（<b>AXI</b>s <b>O</b>bject <b>M</b>odel，Axis 对象模型）的新核心 XML 处理模型 
</li>
				<li>支持 In-Only 和 In-Out 消息交换模式 (MEP) 
</li>
				<li>阻塞和非阻塞客户端 API（应用程序编程接口） 
</li>
				<li>支持内置的 Web 服务寻址 (WS-Addressing) 
</li>
				<li>支持 XMLBeans 数据绑定 
</li>
				<li>新部署模型 
</li>
				<li>支持超文本传输协议 (HTTP)、简单邮件传输协议 (SMTP) 和传输控制协议 (TCP) 等传输协议 </li>
		</ul>
		<p>
		</p>
		<p>本系列文章以 Axis2 0.92 版本为基础。您可以在 <a href="http://ws.apache.org/axis2"><font color="#996699">Apache</font></a> 网站获得 Axis2 的最新版本。</p>
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
										<br />
										<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
										<br />
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																		<br />
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/webservices/ws-webaxis1/#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="N1009E">
						<span class="atitle">
								<font face="Arial" size="4">Axis 体系结构概述</font>
						</span>
				</a>
		</p>
		<br />
		<a name="figure1">
				<b>图 1. Axis2 体系结构</b>
		</a>
		<br />
		<img height="454" alt="Axis2 体系结构" src="http://www-128.ibm.com/developerworks/cn/webservices/ws-webaxis1/axis2.gif" width="562" />
		<br />
		<p>Axis2 体系结构将逻辑与状态分离；这允许在并行线程中执行逻辑。服务和调用的静态状态和动态状态分别存储在 <code>Description</code> 和 <code>Context</code> 类中。Axis2 体系结构是使用 7 个独立模块实现的。</p>
		<ol>
				<li>
						<b>信息模型：</b>此模块管理 SOAP 引擎的状态。该模型定义一组用于存放状态的类，而引擎管理这些信息对象的生命周期。信息模型包含两种用于存放状态的类。<code>Description</code> 类存放本质上是静态的且存在于 Axis 引擎实例的整个生命周期中的数据（如传输、服务和操作的配置）。<code>Context</code> 类存放调用上下文中有效的服务和操作的动态信息，例如当前请求和响应 SOAP 消息、From 地址、To 地址和其他元素。 
</li>
				<li>
						<b>XML 处理模型：</b>Axis2 引入了一个名为 AXIOM 的新模型，用于处理 SOAP 消息。AXIOM 使用 <a href="http://www.jcp.org/aboutJava/communityprocess/first/jsr173/"><font color="#5c81a7">StAX</font></a> (Streaming API for XML) 来解析 XML。StAX 是一个标准的流式 Pull 解析器 Java™ API。AXIOM 非常精巧，不会减慢 XML 信息集的构建速度——换句话说，对象只有在绝对必要时才会创建。总体而言，AXIOM 和 Axis2 所占用的内存要小于 Axis 1 所占用的内存。 
</li>
				<li>
						<b>SOAP 处理模型：</b>Axis2 体系结构定义了两个管道（或流），分别称为 InPipe (InFlow) 和 OutPipe (OutFlow)，用于处理服务器端的请求消息和响应消息。在客户端，这两个管道是反向的——换句话说，SOAP 请求消息流经 OutPipe，而响应消息流经 InPipe。管道或流包含一系列分为阶段的处理程序。阶段按照预先定义的顺序执行，如上面的<a href="http://www-128.ibm.com/developerworks/cn/webservices/ws-webaxis1/#figure1"><font color="#996699">图 1</font></a> 所示。除预先定义的阶段和处理程序集外，用户还可以在操作级别、服务级别或全局级别配置用户阶段和相关处理程序。处理程序充当 SOAP 消息的拦截器，可以处理 SOAP 消息的 Header 或 Body。InPipe 是通过以下阶段进行配置的： 
<ul><li>TransportIn 
</li><li>PreDispatch 
</li><li>Dispatch 
</li><li>PostDispatch 
</li><li>PolicyDetermination 
</li><li>User phases 
</li><li>Message validation </li></ul>我们将在本系列文章的第 2 部分中详细介绍上述各阶段。请求消息在通过 Inpipe 中配置的所有阶段后，到达 MessageReceiver，然后由 MessageReceiver 调用实际服务实现。服务器的 OutPipe 包含以下阶段： 
<ul><li>Message initialization 
</li><li>Policy determination 
</li><li>User phases 
</li><li>MessageOut </li></ul>用户配置的阶段位于这两个管道的用户阶段(User phases) 部分。如果在执行这些管道的过程中发生错误，则这些错误将通过 InFaultPipe 或 OutFaultPipe 管道。收到 Fault 消息后，在客户端调用 InFaultPipe；如果某个调用导致将错误发送到客户端，则在服务器端调用 OutFaultPipe。用户可以将处理程序添加到预先定义的阶段，并且按照这些处理程序运行的顺序进行配置。 
</li>
				<li>
						<b>部署模块：</b>此模块配置 Axis 引擎并部署服务和模块。<i>axis2.xml</i>（在 webapps/axis2/WEB-INF 中）包含 Axis2 引擎的全局配置，包括： 
<ul><li>全局模块 (Global modules) 
</li><li>全局接收器 (Global receivers) 
</li><li>传输 (Transports) 
</li><li>用户阶段定义 (User phase definitions) </li></ul>每个服务的配置都包含在服务存档的 <i>services.xml</i> 文件中。本文稍后将详细讨论此文件。 
</li>
				<li>
						<b>WSDL 和代码生成：</b>此模块从 WSDL 文件中生成客户端存根和服务器框架代码。Axis2 代码生成器发出采用正确 XML 样式表的 XML 文件，以用所需语言生成代码。 
</li>
				<li>
						<b>客户端 API：</b>Axis2 客户端 API 调用遵循 WSDL 2.0 定义的 In-Only 和 In-Out 消息模式的操作。客户端 API 支持 In-Out 操作的阻塞和非阻塞调用。 
</li>
				<li>
						<b>传输：</b>此模块包含与传输层交互的处理程序。传输处理程序有两种类型：TransportListener 和 TransportSender。TransportListener 从传输层接收 SOAP 消息，然后将其传送到 <i>InPipe</i> 进行处理。TransportSender 发送通过指定传输从 <i>OutPipe</i> 接收到的 SOAP 消息。Axis2 提供 HTTP、SMTP 和 TCP 的处理程序。对于 HTTP 传输，服务器端上的 <i>AxisServlet</i> 和客户端上的一个简单的独立 HTTP 服务器（由 Axis2 提供）充当 TransportReceiver。 </li>
		</ol>
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
										<br />
										<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
										<br />
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																		<br />
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/webservices/ws-webaxis1/#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="N10143">
						<span class="atitle">
								<font face="Arial" size="4">部署 Axis2</font>
						</span>
				</a>
		</p>
		<p>部署 Axis2 与部署 Axis 1 一样简单。首先在 Axis2 二进制代码分发包的 <i>webapps</i> 目录下查找 Axis2 Web 应用程序 axis2.war。在 servlet 容器中部署此 war 文件。在 Tomcat 中，如果已在服务器配置中将 <i>unpackWARs</i> 设置为 True，则只需将 axis2.war 复制到 $TOMCAT_HOME/webapps 目录即可部署 Axis2。请立即启动 Tomcat 并访问 http://localhost:&lt;port&gt;/axis2。将显示 Axis2 欢迎页，单击此页上的 <b>Validate</b> 链接。您应到达 <b>Axis2 Happiness page</b>，不会出现任何错误。</p>
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
										<br />
										<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
										<br />
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																		<br />
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/webservices/ws-webaxis1/#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="N10158">
						<span class="atitle">
								<font face="Arial" size="4">开发 StockQuoteService</font>
						</span>
				</a>
		</p>
		<p>下面介绍如何使用 In-Only subscribe() 和 In-Out getQuote() 这两个操作来开发 StockQuoteService。subscribe() 操作将预订指定代号的每小时报价，而 getQuote() 将获得指定代号的当前报价。</p>
		<p>下面的<a href="http://www-128.ibm.com/developerworks/cn/webservices/ws-webaxis1/#listing1"><font color="#996699">清单 1</font></a> 是 StockQuoteService 的实现示例：</p>
		<br />
		<a name="N1016C">
				<b>清单 1. StockQuoteService 实现</b>
		</a>
		<br />
		<table cellspacing="0" cellpadding="5" width="572" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<code>
												<pre class="section">				
package stock;
import org.apache.axis2.om.OMAbstractFactory;
import org.apache.axis2.om.OMElement;
import org.apache.axis2.om.OMFactory;
import org.apache.axis2.om.OMNamespace;
		
public class StockQuoteService {
		 
  public void subscribe(OMElement in){
    String symbol = in.getText();
    System.out.println("Subscription request for symbol ="+symbol);
    // put the actual subscribe code here...    
  }
		  
		  
  public OMElement getQuote(OMElement in){
		  
    // Get the symbol from request message
    String symbol = in.getText();
		    
    int quote = 0;
    if(symbol.equals("IBM")){
      quote = 100;
    }
    // Put more quotes here ...
		    
    // Create response
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace(
      "http://www.developerworks.com/example", "example");
    OMElement resp = fac.createOMElement("getQuoteResponse", omNs);
    resp.setText(String.valueOf(quote));
    return resp;      
  }
}
</pre>
										</code>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>对方法签名感到很疑惑？我们将讨论上述方法中的 <i>OMElement</i>。</p>
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
										<br />
										<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
										<br />
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																		<br />
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/webservices/ws-webaxis1/#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="N1017E">
						<span class="atitle">
								<font face="Arial" size="4">部署服务</font>
						</span>
				</a>
		</p>
		<p>
				<b>部署描述符</b>
		</p>
		<p>在 Axis2 中，服务部署信息包含在 <i>services.xml</i> 文件（在 0.92 以前的版本中，此文件名为 <i>service.xml</i>）中。对于上述 StockQuoteService，服务部署描述符与下面的<a href="http://www-128.ibm.com/developerworks/cn/webservices/ws-webaxis1/#listing2"><font color="#996699">清单 2</font></a> 类似。</p>
		<br />
		<a name="listing2">
				<b>清单 2. Services.xml</b>
		</a>
		<br />
		<table cellspacing="0" cellpadding="5" width="572" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<code>
												<pre class="section">				
&lt;service name="StockQuoteService"&gt;
  &lt;parameter name="ServiceClass" locked="xsd:false"&gt;
    stock.StockQuoteService
  &lt;/parameter&gt;
		
  &lt;operation name="getQuote"&gt;
    &lt;messageReceiver 
      class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/&gt;
  &lt;/operation&gt;
		
  &lt;operation name="subscribe"&gt;
    &lt;messageReceiver 
      class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/&gt;
  &lt;/operation&gt;
&lt;/service&gt;
</pre>
										</code>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>服务的 <i>name</i> 属性定义服务的名称。Axis2 使用服务的名称创建服务的端点地址，例如 http://localhost:&lt;port&gt;/axis2/services/&lt;nameofservice&gt;。因此，对于 StockQuoteService，服务端点为 <i>http://localhost:&lt;port&gt;/axis2/services/StockQuoteService</i>。<code>ServiceClass</code> 参数指定服务实现类。</p>
		<p>每个 &lt;operation&gt; 元素定义服务中一个操作的配置。&lt;operation&gt; 的 <i>name</i> 属性应设置为服务实现类中方法的名称。<code>messageReceiver</code> 元素定义用于处理此操作的消息接收器。Axis2 针对 In-Only 和 In-Out 操作提供了两个无数据绑定的内置 MessageReceivers；<code>org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver</code> 用于 In-Only 操作，而 <code>org.apache.axis2.receivers.RawXMLINOutMessageReceiver</code> 用于 In-Out 操作。如果没有指定 messageReceiver，则 Axis2 将尝试使用 org.apache.axis2.receivers.RawXMLINOutMessageReceiver 作为缺省的 messageReceiver。上述 RAWXML 消息接收器将传入 SOAP 消息的 &lt;Body&gt; 的内容作为 OMElement（OMElement 是 XML 元素的 AXIOM 缩写）传递给服务实现。此操作应作为 OMElement 返回 SOAP 响应的 &lt;Body&gt; 元素包含的 XML 内容。这便解释了为何 subscribe() 和 getQuote() 操作采用和返回 OMElement。</p>
		<p>
				<i>services.xml</i> 还可以包含分为 <i>servicegroup</i> 的多个服务。</p>
		<p>
				<b>打包</b>
		</p>
		<p>Axis 2 服务是作为 Axis Archive (.aar) 打包的。这是一个 JAR 文件（使用 jar 或 zip 实用程序创建），在存档的 META-INF 目录中打包了 <i>services.xml</i> 文件。StockQuoteService 在打包成 <i>StockQuoteService.aar</i> 时将具有以下结构： 
</p>
		<table cellspacing="0" cellpadding="5" width="572" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<code>
												<pre class="section">./stock/StockQuoteService.class
./META-INF/services.xml</pre>
										</code>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>预先打包的 StockQuoteService 存档可以在本文的<a href="http://www-128.ibm.com/developerworks/cn/webservices/ws-webaxis1/#Download"><font color="#996699">下载</font></a>部分中找到。</p>
		<p>
				<b>部署</b>
		</p>
		<p>在 Axis2 中部署服务相当简单，只需将 .aar 文件复制到 servlet 容器的 axis2 Web 应用程序中的 <i>axis2/WEB-INF/services</i> 目录下即可。对于 Tomcat，此位置为 <i>$TOMCAT_HOME/webapps/axis2/WEB-INF/services</i>。 </p>
		<p>另一种部署服务的好方法是使用 Axis2 管理控制台中的 <b>Upload Service</b> 工具。请转到 http://localhost:&lt;port&gt;/axis2，然后选择 <b>Administration</b> 链接。输入用户名和密码 <b>admin/axis2</b>，然后登录。（您可以在 axis2.xml 中配置用户名/密码。)在工具部分选择 <b>Upload Service</b> 链接，再选择 <b>.aar</b> 文件，然后单击 <b>Upload</b>。就是这样简单！如果上传成功，系统将显示一条绿色成功消息。服务即被部署，而且可随时调用。如果要在远程 Axis2 服务器上部署服务，则此功能非常方便。</p>
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
										<br />
										<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
										<br />
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																		<br />
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/webservices/ws-webaxis1/#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="N10215">
						<span class="atitle">
								<font face="Arial" size="4">通过 Axis2 使用 Web 服务</font>
						</span>
				</a>
		</p>
		<p>Web 服务调用的特性由 MEP、传输协议以及客户端 API 的同步和/或异步行为决定。Axis2 当前支持 WSDL 2.0 定义的 In-Only 和 In-Out MEP。Axis2 客户端 API 支持服务的同步和异步调用。在调用 In-Out 操作时，在 API 级别和传输级别提供异步行为。API 级别异步是通过回滚获得的，它使用一个传输连接来同时传输请求和响应（例如，通过一个 HTTP 连接传输请求和响应）。在传输级别异步中，使用不同的传输连接分别发送请求和接收响应，例如使用 SMTP 进行传输时即如此。</p>
		<p>下面是使用 Axis2 客户端 API 调用 In-Only 和 In-Out 操作的详细信息。</p>
		<p>
				<a name="N10221">
						<span class="smalltitle">
								<strong>
										<font face="Arial">调用 In-Only 操作</font>
								</strong>
						</span>
				</a>
		</p>
		<p>
				<code>org.apache.axis2.clientapi.MessageSender</code> 类用于调用 In-Only 操作（如下面的<a href="http://www-128.ibm.com/developerworks/cn/webservices/ws-webaxis1/#listing3"><font color="#996699">清单 3</font></a> 所示），而 In-Only 操作调用 <code>StockQuoteService</code> 的 <code>subscribe()</code> 操作。</p>
		<br />
		<a name="listing3">
				<b>清单 3. 调用 In-Only 操作</b>
		</a>
		<br />
		<table cellspacing="0" cellpadding="5" width="572" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<code>
												<pre class="section">				
try{
  EndpointReference targetEPR = new EndpointReference(
      "http://localhost:8080/axis2/services/StockQuoteService");
          
  // Make the request message
  OMFactory fac = OMAbstractFactory.getOMFactory();
  OMNamespace omNs = fac.createOMNamespace(
      "http://www.developerworks.com/example", "example");
  OMElement payload = fac.createOMElement("subscribe", omNs);
  payload.setText("IBM"); 
          
  // Send the request
  MessageSender msgSender = new MessageSender();
  msgSender.setTo(targetEPR);
  msgSender.setSenderTransport(Constants.TRANSPORT_HTTP);
  msgSender.send("subscribe", payload);         
  }catch (AxisFault axisFault) {
      axisFault.printStackTrace();
  }
</pre>
										</code>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>
				<code>MessageSender.send()</code> 发送请求消息并将其立即返回。要使用的传输由 <code>MessageSender.setSenderTransport()</code> 指定。此示例通过 HTTP 发送消息。</p>
		<p>
				<a name="N10250">
						<span class="smalltitle">
								<strong>
										<font face="Arial">调用 In-Out 操作</font>
								</strong>
						</span>
				</a>
		</p>
		<p>使用 <code>org.apache.axis2.clientapi.Call</code> 类可以方便地调用 In-Out 操作。调用 In-Out 操作时，此 <code>Call</code> 类支持下列 4 种模式：</p>
		<ol>
				<li>
						<p>
								<b>阻塞单传输模式</b>：这是调用 In-Out Web 服务操作最简单的方式。在操作完成和接收到响应或错误之前，服务调用被阻塞。它使用一个传输连接同时发送和接收响应，如下面的<a href="http://www-128.ibm.com/developerworks/cn/webservices/ws-webaxis1/#listing4"><font color="#996699">清单 4</font></a> 所示。</p>
						<br />
						<br />
						<a name="listing4">
								<b>清单 4. 阻塞单传输模式</b>
						</a>
						<br />
						<table cellspacing="0" cellpadding="5" width="572" bgcolor="#eeeeee" border="1">
								<tbody>
										<tr>
												<td>
														<code>
																<pre class="section">						
try {
                 
  EndpointReference targetEPR = new EndpointReference(
      "http://localhost:8080/axis2/services/StockQuoteService");
               
  // Create request message
  OMFactory fac = OMAbstractFactory.getOMFactory();
  OMNamespace omNs = fac.createOMNamespace(
      "http://www.developerworks.com/example", "example");
    OMElement payload = fac.createOMElement("getQuote",omNs);
  payload.setText("IBM");

  // Create the call
  Call call = new Call();
  call.setTo(targetEPR);
			
  call.setTransportInfo(Constants.TRANSPORT_HTTP,
    Constants.TRANSPORT_HTTP, false);
  // Invoke blocking
  OMElement result = call.invokeBlocking("getQuote", payload);
               
  System.out.println("Quote ="+result.getText());
}catch (AxisFault axisFault) {
    axisFault.printStackTrace();
}
</pre>
														</code>
												</td>
										</tr>
								</tbody>
						</table>
						<br />
						<p>代码的第一部分使用 AXIOM 创建请求消息。<code>Call.setTransportInfo()</code> 设置用于发送请求和获得响应的传输。<code>Call.setTransportInfo()</code> 操作的 Boolean 参数指出是否要使用不同的传输连接来分别发送请求和接收响应。在本例中，要求用一个 HTTP 连接发送请求和接收响应。</p>
				</li>
				<li>
						<p>
								<b>非阻塞单传输模式</b>：在此调用模式中，只使用下面的一个传输连接获得非阻塞调用。如果在一个客户端应用程序中要完成多个 Web 服务调用，而且不希望每次调用都阻塞客户端，则需要此类行为。此时，如果响应可用，则调用立即返回且客户端得以回滚，如下面的<a href="http://www-128.ibm.com/developerworks/cn/webservices/ws-webaxis1/#listing5"><font color="#996699">清单 5</font></a> 所示。</p>
						<br />
						<br />
						<a name="listing5">
								<b>清单 5. 非阻塞单传输模式</b>
						</a>
						<br />
						<table cellspacing="0" cellpadding="5" width="572" bgcolor="#eeeeee" border="1">
								<tbody>
										<tr>
												<td>
														<code>
																<pre class="section">						
try {
  EndpointReference targetEPR = new EndpointReference(
      "http://localhost:8080/axis2/services/StockQuoteService");
            
  //Create the request
  OMFactory fac = OMAbstractFactory.getOMFactory();
  OMNamespace omNs = fac.createOMNamespace(
      "http://www.developerworks.com/example", "example");
  OMElement payload = fac.createOMElement("getQuote", omNs);
  payload.setText("IBM");
      
            
    // Create the call
    Call call = new Call();
    call.setTo(targetEPR);
            
    // Set the transport info.
    call.setTransportInfo(org.apache.axis2.Constants.TRANSPORT_HTTP,
      org.apache.axis2.Constants.TRANSPORT_HTTP, false);
            
  // Callback to handle the response
            
    Callback callback = new Callback() {
      
      public void onComplete(AsyncResult result) {
        System.out.println("Quote = "
          + result.getResponseEnvelope().getBody().getFirstElement()
            .getText());
      }
      
      public void reportError(Exception e) {
        e.printStackTrace();
      }
    };
            
            
  // Invoke non blocking
            
    call.invokeNonBlocking("getQuote", payload, callback);            
            
  //Wait till the callback receives the response.
            
    while (!callback.isComplete()) {
      Thread.sleep(1000);
    }
            
            
  call.close();
} catch (AxisFault axisFault) {
  axisFault.printStackTrace();
} catch (Exception ex) {
  ex.printStackTrace();
}
</pre>
														</code>
												</td>
										</tr>
								</tbody>
						</table>
						<br />
						<p>
								<code>Call.invokeNonBlocking()</code> 方法立即返回而不阻塞。<code>Call.invokeNonBlocking()</code> 采用 <code>org.apache.axis2.clientapi.CallBack</code> 的对象，如果响应来自服务，则将触发此对象。<code>CallBack</code> 有两个抽象方法 <code>onComplete(AsynchResult)</code> 和 <code>reportError(Exception)</code>，需要由具体的 <code>CallBack</code> 类实现这些方法。在服务调用正常完成后，Axis2 引擎调用 <code>onComplete()</code> 方法。在从服务器获得错误消息后，调用 <code>Callback</code> 的 <code>reportError()</code> 方法。<code>Callback.isComplete()</code> 将指出操作调用是否完成。</p>
						<p>因为上面两个方法使用一个传输连接来发送和接收消息，所以这些方法不适合长时间运行的事务。原因是在响应可用之前，传输连接可能会超时。要解决此问题，可使用两个不同的连接来分别发送请求和接收响应。但因为使用了其他传输连接来获得响应，因此需要将请求和响应关联起来。Axis2 支持 WS-Addressing，后者通过使用 &lt;wsa:MessageID&gt; 和 &lt;wsa:RelatesTo&gt; Header 可解决此问题。因此，如果使用两个传输，则支持对模块寻址，如下面两个模式所示。</p>
				</li>
				<li>
						<p>
								<b>阻塞双传输模式</b>：此模式在以下情况下非常有用：服务操作在本质上是 In-Out，但使用的传输是单向的（如 SMTP）或服务执行需要很长时间且 HTTP 连接超时。请参见下面的<a href="http://www-128.ibm.com/developerworks/cn/webservices/ws-webaxis1/listing6"><font color="#5c81a7">清单 6</font></a>。</p>
						<br />
						<br />
						<a name="listing6">
								<b>清单 6. 阻塞双传输模式</b>
						</a>
						<br />
						<table cellspacing="0" cellpadding="5" width="572" bgcolor="#eeeeee" border="1">
								<tbody>
										<tr>
												<td>
														<code>
																<pre class="section">						
try{
  EndpointReference targetEPR = new EndpointReference(
      "http://localhost:8080/axis2/services/StockQuoteService");
                
  OMFactory fac = OMAbstractFactory.getOMFactory();
  OMNamespace omNs = fac.createOMNamespace(
      "http://www.developerworks.com/example", "example");
  OMElement payload = fac.createOMElement("getQuote",omNs);
  payload.setText("IBM");
        
  Call call = new Call();
    call.setTo(targetEPR);

    call.setTransportInfo(
      Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, true);

    //Blocking Invocation
    OMElement result = call.invokeBlocking("getQuote", payload);
  System.out.println("Quote = "+result.getText());
	
}catch (AxisFault axisFault) {
    axisFault.printStackTrace();
}catch (Exception ex) {
    ex.printStackTrace();
}
</pre>
														</code>
												</td>
										</tr>
								</tbody>
						</table>
						<br />
				</li>
				<li>
						<p>
								<b>非阻塞双传输模式</b>：就 API 级别和传输级别的非阻塞而言，此模式提供了最大的灵活性，如下面的<a href="http://www-128.ibm.com/developerworks/cn/webservices/ws-webaxis1/listing7"><font color="#5c81a7">清单 7</font></a> 所示。</p>
						<br />
						<br />
						<a name="listing7">
								<b>清单 7. 非阻塞双传输模式</b>
						</a>
						<br />
						<table cellspacing="0" cellpadding="5" width="572" bgcolor="#eeeeee" border="1">
								<tbody>
										<tr>
												<td>
														<code>
																<pre class="section">						
try {
       
  EndpointReference targetEPR = new EndpointReference(
      "http://localhost:8080/axis2/services/StockQuoteService");
  OMFactory fac = OMAbstractFactory.getOMFactory();
  OMNamespace omNs = fac.createOMNamespace(
      "http://www.developerworks.com/example", "example");
  OMElement payload = fac.createOMElement("getQuote",omNs);
  payload.setText("IBM");
        
           
    Call call = new Call();
    call.setTo(targetEPR);

    call.setTransportInfo(
      Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, true);
  // Callback to handle the response
           
    Callback callback = new Callback() {
    public void onComplete(AsyncResult result) {
      System.out.println("Quote = "
          + result.getResponseEnvelope().getBody().getFirstElement()
        .getText());
      }

    public void reportError(Exception e) {
        e.printStackTrace();
      }
    };
            

  // Non-Blocking Invocation
          
    call.invokeNonBlocking("getQuote", payload, callback);
  // Wait till the callback receives the response.
          
    while (!callback.isComplete()) {
      Thread.sleep(1000);
    }
    call.close();          
}catch (AxisFault axisFault) {
      axisFault.printStackTrace();
}catch (Exception ex) {
      ex.printStackTrace();
}
</pre>
														</code>
												</td>
										</tr>
								</tbody>
						</table>
						<br />
				</li>
		</ol>
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
										<br />
										<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
										<br />
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																		<br />
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/webservices/ws-webaxis1/#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="N10319">
						<span class="atitle">
								<font face="Arial" size="4">总结</font>
						</span>
				</a>
		</p>
		<p>在这一由两部分组成的系列的第 1 部分中，您了解了 Axis2 体系结构以及如何使用不同的调用模式来部署和使用一个简单的 Web 服务。在本系列的第 2 部分中，您将详细了解该体系结构，以及如何通过添加处理程序和 Axis2 消息接收器来自定义 Axis2。您还将了解如何使用 Axis2 提供的 XMLBeans 数据绑定支持。</p>
		<br />
<img src ="http://www.blogjava.net/wuxufeng8080/aggbug/56378.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wuxufeng8080/" target="_blank">风人园</a> 2006-07-03 17:01 <a href="http://www.blogjava.net/wuxufeng8080/articles/56378.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>