﻿<?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-　　　　　　　　　　　　　礼物 ^_^ -文章分类-Axis</title><link>http://www.blogjava.net/libin2722/category/27086.html</link><description>虚其心，可解天下之问；专其心，可治天下之学；静其心，可悟天下之理；恒其心，可成天下之业。</description><language>zh-cn</language><lastBuildDate>Thu, 07 Jan 2010 00:23:00 GMT</lastBuildDate><pubDate>Thu, 07 Jan 2010 00:23:00 GMT</pubDate><ttl>60</ttl><item><title>（原）Axis2 的RPC和AXIOM两种方式</title><link>http://www.blogjava.net/libin2722/articles/308456.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Wed, 06 Jan 2010 08:23:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/308456.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/308456.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/308456.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/308456.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/308456.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: v\:* {behavior:url(#default#VML);}o\:* {behavior:url(#default#VML);}w\:* {behavior:url(#default#VML);}.shape {behavior:url(#default#VML);}						   Normal  0  false      7...&nbsp;&nbsp;<a href='http://www.blogjava.net/libin2722/articles/308456.html'>阅读全文</a><img src ="http://www.blogjava.net/libin2722/aggbug/308456.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2010-01-06 16:23 <a href="http://www.blogjava.net/libin2722/articles/308456.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sipity backend 之 web service 开发个人记录</title><link>http://www.blogjava.net/libin2722/articles/296946.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Tue, 29 Sep 2009 15:22:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/296946.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/296946.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/296946.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/296946.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/296946.html</trackback:ping><description><![CDATA[根据java代码生成wsdl文件<br />E:\workspace\workspace_telenev\telenav\sipity\target\classes&gt;java2wsdl -cp .;%cl<br />asspath% -o .\libin -sn LogonDelegateImpl -cn com.telenav.sipity.service.delegat<br />e.impl.LogonDelegateImpl<br /><br />使用wsdl文件生成java客户端代码<br /><img src ="http://www.blogjava.net/libin2722/aggbug/296946.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2009-09-29 23:22 <a href="http://www.blogjava.net/libin2722/articles/296946.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>(转)结合Axis和Ant开发Web服务</title><link>http://www.blogjava.net/libin2722/articles/296684.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Sun, 27 Sep 2009 10:05:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/296684.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/296684.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/296684.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/296684.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/296684.html</trackback:ping><description><![CDATA[本文转：http://blog.csdn.net/happlyin/archive/2003/10/25/18308.aspx<br /><br /><br /><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: 宋体;">本文结合一个简单示例讲解了怎样把</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Axis</span><span style="font-size: 10pt; font-family: 宋体;">和</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Ant</span><span style="font-size: 10pt; font-family: 宋体;">结合起来进行</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Web</span><span style="font-size: 10pt; font-family: 宋体;">服务的开发。帮助读者从简单的</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">java</span><span style="font-size: 10pt; font-family: 宋体;">源代码或者从一个服务描述文件（</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">wsdl</span><span style="font-size: 10pt; font-family: 宋体;">）开始，用</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Ant</span><span style="font-size: 10pt; font-family: 宋体;">工具进行构建，设置，并把服务部署到</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Axis</span><span style="font-size: 10pt; font-family: 宋体;">。</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><o:p> </o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: 宋体;">首先假定您熟悉</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"> AXIS </span><span style="font-size: 10pt; font-family: 宋体;">处理系统和</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Ant</span><span style="font-size: 10pt; font-family: 宋体;">工具。文中示例所需要的软件如下：</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt;"><span style="font-family: Wingdings;" lang="EN-US"><span style=""><font size="3">l</font><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">         </span></span></span><span lang="EN-US"><font size="3">Apache Axis 1.1</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt;"><span style="font-family: Wingdings;" lang="EN-US"><span style=""><font size="3">l</font><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">         </span></span></span><span lang="EN-US"><font size="3">Apache Ant 1.5.3</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt;"><span style="font-family: Wingdings;" lang="EN-US"><span style=""><font size="3">l</font><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">         </span></span></span><span lang="EN-US"><font size="3">Jarkat Tomcat 4.1.24</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: 宋体;">在开始前，假定上述软件已经安装和配置好了。</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span lang="EN-US"><o:p><font size="3"> </font></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><b style=""><span style="font-size: 12pt;" lang="EN-US">Axis</span></b><b style=""><span style="font-size: 12pt; font-family: 宋体;">和</span></b><b style=""><span style="font-size: 12pt;" lang="EN-US">Ant</span></b><b style=""><span style="font-size: 12pt; font-family: 宋体;">简介</span></b><b style=""><span style="font-size: 12pt;" lang="EN-US"><o:p></o:p></span></b></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Axis </span><span style="font-size: 10pt; font-family: 宋体;">框架是来自</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"> Apache Group </span><span style="font-size: 10pt; font-family: 宋体;">的、基于</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"> java </span><span style="font-size: 10pt; font-family: 宋体;">的、最新的</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"> SOAP </span><span style="font-size: 10pt; font-family: 宋体;">规范（</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">SOAP 1.2</span><span style="font-size: 10pt; font-family: 宋体;">）和</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"> SOAP with Attachments </span><span style="font-size: 10pt; font-family: 宋体;">规范（来自</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"> Apache Group </span><span style="font-size: 10pt; font-family: 宋体;">）的开放源代码实现。其本质上是一个</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">SOAP</span><span style="font-size: 10pt; font-family: 宋体;">引擎－－一个构建诸如客户端、服务器、网关等</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">SOAP</span><span style="font-size: 10pt; font-family: 宋体;">处理器的框架。是</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Apache SOAP</span><span style="font-size: 10pt; font-family: 宋体;">的后继项目。但是，</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Axis</span><span style="font-size: 10pt; font-family: 宋体;">使用</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">SAX</span><span style="font-size: 10pt; font-family: 宋体;">（基于事件）解析器获得了比</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Apache SOAP</span><span style="font-size: 10pt; font-family: 宋体;">早期版本</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">(</span><span style="font-size: 10pt; font-family: 宋体;">使用</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">DOM</span><span style="font-size: 10pt; font-family: 宋体;">解析</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">)</span><span style="font-size: 10pt; font-family: 宋体;">非常明显的速度优势。另外，它还具有很强的灵活性和稳定性，支持</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Web</span><span style="font-size: 10pt; font-family: 宋体;">服务描述语言</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">1.1</span><span style="font-size: 10pt; font-family: 宋体;">版。</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Apache Ant</span><span style="font-size: 10pt; font-family: 宋体;">是</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Apache</span><span style="font-size: 10pt; font-family: 宋体;">软件基金会</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">jakarta</span><span style="font-size: 10pt; font-family: 宋体;">项目中的一个子项目，是一个基于</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Java</span><span style="font-size: 10pt; font-family: 宋体;">的构建工具，类似于</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">make</span><span style="font-size: 10pt; font-family: 宋体;">，但它没有</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">make</span><span style="font-size: 10pt; font-family: 宋体;">那么复杂繁琐。</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Ant</span><span style="font-size: 10pt; font-family: 宋体;">由一些内置任务（</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">task</span><span style="font-size: 10pt; font-family: 宋体;">）和可选择的任务组成，还可以配置第三方提供的任务。它的构建配置文件基于</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">XML</span><span style="font-size: 10pt; font-family: 宋体;">的，所以容易书写和维护，而且结构清晰。</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Ant</span><span style="font-size: 10pt; font-family: 宋体;">还可以集成到一些开发环境中（例如</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">visual age,jbuilder,Elipse)</span><span style="font-size: 10pt; font-family: 宋体;">。</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><o:p><font size="3"> </font></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><b style=""><span style="font-size: 12pt;" lang="EN-US">Axis</span></b><b style=""><span style="font-size: 12pt; font-family: 宋体;">对</span></b><b style=""><span style="font-size: 12pt;" lang="EN-US">Ant</span></b><b style=""><span style="font-size: 12pt; font-family: 宋体;">的支持</span></b><b style=""><span style="font-size: 12pt;" lang="EN-US"><o:p></o:p></span></b></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Axis</span><span style="font-size: 10pt; font-family: 宋体;">为支持</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Ant</span><span style="font-size: 10pt; font-family: 宋体;">构建，提供了一个</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">axis-ant.jar</span><span style="font-size: 10pt; font-family: 宋体;">文件。该文件包含三个可选任务</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">(task)</span><span style="font-size: 10pt; font-family: 宋体;">的定义和实现：</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">axis-wsdl2java</span><span style="font-size: 10pt; font-family: 宋体;">，</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">axis-java2wsdl</span><span style="font-size: 10pt; font-family: 宋体;">和</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">axis-admin</span><span style="font-size: 10pt; font-family: 宋体;">。任务</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">axis-wsdl2java</span><span style="font-size: 10pt; font-family: 宋体;">与</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Axis</span><span style="font-size: 10pt; font-family: 宋体;">提供的工具</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">WSDL2Java</span><span style="font-size: 10pt; font-family: 宋体;">具有同样的功能，根据</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">web</span><span style="font-size: 10pt; font-family: 宋体;">服务描述文件生成对应的</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Java</span><span style="font-size: 10pt; font-family: 宋体;">源程序，它的属性设置与</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">WSDL2Java</span><span style="font-size: 10pt; font-family: 宋体;">的命令参数设置类似。而任务</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">axis-java2wsdl</span><span style="font-size: 10pt; font-family: 宋体;">则相反，它与</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Java2WSDL</span><span style="font-size: 10pt; font-family: 宋体;">工具一样，是根据已有的类文件来生成</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Web</span><span style="font-size: 10pt; font-family: 宋体;">服务描述文件。最后一个任务</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">axis-admin</span><span style="font-size: 10pt; font-family: 宋体;">是用于</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">web</span><span style="font-size: 10pt; font-family: 宋体;">服务的部署和取消部署的，对应于</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Axis</span><span style="font-size: 10pt; font-family: 宋体;">的</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">AminClient</span><span style="font-size: 10pt; font-family: 宋体;">工具。</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: 宋体;">为了使</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Ant</span><span style="font-size: 10pt; font-family: 宋体;">能够正确使用上述三个任务（</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">task</span><span style="font-size: 10pt; font-family: 宋体;">），还需要做一些配置。注意：</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Apache Ant</span><span style="font-size: 10pt; font-family: 宋体;">的版本必须是</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">1.5.1</span><span style="font-size: 10pt; font-family: 宋体;">或更高版本。</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">1</span><span style="font-size: 10pt; font-family: 宋体;">．设置系统的环境变量</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">CLASSPATH</span><span style="font-size: 10pt; font-family: 宋体;">包含</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Axis</span><span style="font-size: 10pt; font-family: 宋体;">提供的</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">axis-ant.jar</span><span style="font-size: 10pt; font-family: 宋体;">文件，或者在</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Ant</span><span style="font-size: 10pt; font-family: 宋体;">的配置文件（通常是</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">build.xml</span><span style="font-size: 10pt; font-family: 宋体;">）中设置路径包含它。例如，</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span>&lt;path id="axis.classpath"&gt;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">  </span><span style="">    </span>&lt;fileset dir="${axis.home}/lib"&gt;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span><span style="">       </span><span style="">    </span>&lt;include name="**/*.jar" /&gt;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style=""> </span><span style=""> </span><span style="">    </span>&lt;/fileset&gt;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span>&lt;/path&gt;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style=""><font size="3">    </font></span></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">2</span><span style="font-size: 10pt; font-family: 宋体;">．然后使用</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">&lt;taskdef&gt;</span><span style="font-size: 10pt; font-family: 宋体;">声明导入</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">axis-ant.jar</span><span style="font-size: 10pt; font-family: 宋体;">文件中的属性文件所定义的任务（</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">task</span><span style="font-size: 10pt; font-family: 宋体;">）列表。</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><span style="">    </span>&lt;taskdef resource="axis-tasks.properties"<o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><span style="">  </span>classpathref="axis.classpath" /&gt;<o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><span style="">  </span><span style="">   </span>3</span><span style="font-size: 10pt; font-family: 宋体;">．设置在构建过程中可能要需要的</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">java</span><span style="font-size: 10pt; font-family: 宋体;">包，例如，</span><span style="font-size: 10pt; font-family: Verdana;"><span lang="EN-US">Axis</span></span><span style="font-size: 10pt; font-family: 宋体;">所有的</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">jar</span><span style="font-size: 10pt; font-family: 宋体;">包，</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">wsdl4j.jar</span><span style="font-size: 10pt; font-family: 宋体;">，</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">junit.jar</span><span style="font-size: 10pt; font-family: 宋体;">等等。</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><span style="">  </span><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><b style=""><span style="font-size: 12pt; font-family: 宋体;">实例开发</span></b><b style=""><span style="font-size: 12pt;" lang="EN-US"><o:p></o:p></span></b></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: 宋体;">下面就用一个实例来讲解怎样把</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Ant</span><span style="font-size: 10pt; font-family: 宋体;">和</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Axis</span><span style="font-size: 10pt; font-family: 宋体;">结合来开发</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Web</span><span style="font-size: 10pt; font-family: 宋体;">服务。为了注重本文的目的，我们开发一个比较简单的</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Web</span><span style="font-size: 10pt; font-family: 宋体;">服务，它接受客户端传入的字符串数组，如果传入的参数为</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">null</span><span style="font-size: 10pt; font-family: 宋体;">，则抛出一个自定义的异常，否则把每个字符串连接起来返回给客户端。</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: 宋体;">首先定义一个</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Web</span><span style="font-size: 10pt; font-family: 宋体;">服务接口</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Hello</span><span style="font-size: 10pt; font-family: 宋体;">，如下所示：</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style=""><font size="3">  </font></span></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">  </span>package com.bidlink.hello;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">  </span>public interface Hello{</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">     </span>public String echo(String[] content ) throws<span style="">                     </span><span style="">  </span></font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">               </span>java.rmi.RemoteException,com.bidlink.hello.MyException;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">  </span>}</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style=""><font size="3">  </font></span></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><span style="">  </span></span><span style="font-size: 10pt; font-family: 宋体;">自定义异常</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">MyException</span><span style="font-size: 10pt; font-family: 宋体;">包含一个时间值，以记录异常出现的时间，如下：</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style=""><font size="3">  </font></span></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">  </span>package com.bidlink.hello;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 10.5pt;"><span lang="EN-US"><font size="3">public class MyException extends org.apache.axis.AxisFault implements java.io.Serializable{</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span>private java.util.Calendar occurTime;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style=""><font size="3">    </font></span></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span>public MyException() {</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span>}</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><o:p><font size="3"> </font></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span>public MyException(</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">           </span>java.util.Calendar occurTime) {</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">        </span>super();</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">        </span>this.occurTime = occurTime;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span>}</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><o:p><font size="3"> </font></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span>public java.util.Calendar getOccurTime() {</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">        </span>return occurTime;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span>}</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><o:p><font size="3"> </font></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span>public void setOccurTime(java.util.Calendar occurTime) {</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">        </span>this.occurTime = occurTime;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span>}<span style="">            </span></font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3">}</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><o:p><font size="3"> </font></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><font size="3"><b style=""><span lang="EN-US">1</span></b><b style=""><span style="font-family: 宋体;">．</span><span lang="EN-US">axis-java2wsdl</span></b><b style=""><span style="font-family: 宋体;">：从类文件生成服务描述文件</span><span lang="EN-US"><o:p></o:p></span></b></font></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: 宋体;">编译上面定义的两个文件</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Hell.java</span><span style="font-size: 10pt; font-family: 宋体;">和</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">MyException.java</span><span style="font-size: 10pt; font-family: 宋体;">。接着编写</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Ant</span><span style="font-size: 10pt; font-family: 宋体;">的配置文件</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">build.xml</span><span style="font-size: 10pt; font-family: 宋体;">（文件详细信息请查看示例源代码），使用</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">axis-java2wsdl</span><span style="font-size: 10pt; font-family: 宋体;">任务根据类</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Hello</span><span style="font-size: 10pt; font-family: 宋体;">来生成</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Web</span><span style="font-size: 10pt; font-family: 宋体;">服务描述文件</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">hello.wsdl</span><span style="font-size: 10pt; font-family: 宋体;">。任务具体配置如下：</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span>&lt;axis-java2wsdl classname="com.bidlink.hello.Hello"</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">                        </span>location="http://localhost:8080/axis/services/Hello"</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">                        </span>namespace="http://hello.bidlink.com"</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">                        </span>output="hello.wsdl"</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">                        </span>style="RPC"</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">                        </span>extraclasses="com.bidlink.hello.MyException"&gt;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span><span style="">     </span>&lt;classpath&gt;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">             </span>&lt;pathelement path="${dist}"/&gt;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">         </span>&lt;/classpath&gt;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">        </span>&lt;/axis-java2wsdl&gt;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style=""><font size="3">        </font></span></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: 宋体;">其中，</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">&lt;pathelement path="${dist}"/&gt;</span><span style="font-size: 10pt; font-family: 宋体;">指出</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Hello.class</span><span style="font-size: 10pt; font-family: 宋体;">和</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">MyException.class</span><span style="font-size: 10pt; font-family: 宋体;">文件的位置。</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: 宋体;">运行命令</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">ant java2wsdl</span><span style="font-size: 10pt; font-family: 宋体;">，构建出</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Web</span><span style="font-size: 10pt; font-family: 宋体;">服务描述文件</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">hello.wsdl</span><span style="font-size: 10pt; font-family: 宋体;">。</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><font size="3"><b style=""><span lang="EN-US">2</span></b><b style=""><span style="font-family: 宋体;">．</span><span lang="EN-US">axis-wsdkl2java</span></b><b style=""><span style="font-family: 宋体;">：从服务描述文件生成服务源程序</span><span lang="EN-US"><o:p></o:p></span></b></font></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: 宋体;">下面讲解怎样根据刚刚得到的</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">hello.wsdl</span><span style="font-size: 10pt; font-family: 宋体;">文件生成服务所需要的</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">java</span><span style="font-size: 10pt; font-family: 宋体;">源程序。在这里需要用到任务</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">axis-wsdl2java</span><span style="font-size: 10pt; font-family: 宋体;">。任务属性设置如下：</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">     </span>&lt;axis-wsdl2java all="true" </font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">   </span><span style=""> </span><span style="">              </span><span style="">   </span>url="hello.wsdl"</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span><span style="">              </span><span style="">   </span>deployscope="Request"</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span><span style="">              </span><span style="">   </span>output="${gensrc}"</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span><span style="">              </span><span style="">   </span>serverside="true"</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span><span style="">              </span><span style="">   </span>skeletondeploy="false"</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span><span style="">              </span><span style="">   </span>testcase="true"</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span><span style="">              </span><span style="">   </span>noimports="false"</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span><span style="">              </span><span style="">   </span>typemappingversion="1.2"&gt;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style=""><font size="3">        </font></span></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">        </span>&lt;/axis-wsdl2java&gt; </font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span lang="EN-US"><font size="3"><span style="">  </span><span style="">    </span></font></span><span style="font-size: 10pt; font-family: 宋体;">运行</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">ant wsdl2java</span><span style="font-size: 10pt; font-family: 宋体;">，根据</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">axis-wsdl2java</span><span style="font-size: 10pt; font-family: 宋体;">任务的属性配置生成相应的</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">java</span><span style="font-size: 10pt; font-family: 宋体;">源程序，本例所生成的文件包括：服务端服务接口文件</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Hello.java</span><span style="font-size: 10pt; font-family: 宋体;">及其实现</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">HelloSoapBindingImpl.java</span><span style="font-size: 10pt; font-family: 宋体;">，以及客户端的</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">HelloService.java</span><span style="font-size: 10pt; font-family: 宋体;">，</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">HelloServiceLocator.java</span><span style="font-size: 10pt; font-family: 宋体;">，</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">HelloServiceLocator.java</span><span style="font-size: 10pt; font-family: 宋体;">和客户端存根文件</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">HelloSoapBindingStub.java</span><span style="font-size: 10pt; font-family: 宋体;">。又因为属性</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">testcase="true"</span><span style="font-size: 10pt; font-family: 宋体;">，所以还生成了测试文件</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">HelloServiceTestCase.java</span><span style="font-size: 10pt; font-family: 宋体;">。当然，自定义异常</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">MyException</span><span style="font-size: 10pt; font-family: 宋体;">也是重新生成的。</span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><font size="3"><b style=""><span lang="EN-US">3</span></b><b style=""><span style="font-family: 宋体;">．</span><span lang="EN-US">axis-admin</span></b><b style=""><span style="font-family: 宋体;">：向</span><span lang="EN-US">Axis</span></b><b style=""><span style="font-family: 宋体;">部署</span><span lang="EN-US">Hello</span></b><b style=""><span style="font-family: 宋体;">服务</span><span lang="EN-US"><o:p></o:p></span></b></font></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: 宋体;">服务源程序生成后，需要根据服务的功能修改</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">HelloSoapBindingImpl.java</span><span style="font-size: 10pt; font-family: 宋体;">文件，以真正实现该</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Web</span><span style="font-size: 10pt; font-family: 宋体;">服务。修改如下：</span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">  </span>/**</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style=""> </span>* HelloSoapBindingImpl.java</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style=""> </span>*</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style=""> </span>* This file was auto-generated from WSDL</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style=""> </span>* by the Apache Axis WSDL2Java emitter.</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style=""> </span>*/</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><o:p><font size="3"> </font></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3">package com.bidlink.hello;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><o:p><font size="3"> </font></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3">public class HelloSoapBindingImpl implements com.bidlink.hello.Hello{</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span>public java.lang.String echo(java.lang.String[] in0) throws java.rmi.RemoteException, com.bidlink.hello.MyException {</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">        </span>if(in0 == null)</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">           </span>throw new MyException(java.util.Calendar.getInstance());</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style=""><font size="3">           </font></span></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style=""><font size="3">        </font></span></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">        </span>String retStr = "";</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">        </span>for(int i=0; i&lt; in0.length; i++)</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">           </span>retStr += in0[i];</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">        </span>return retStr;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span>}</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><o:p><font size="3"> </font></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3">}</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style=""><font size="3">    </font></span></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: 宋体;">编译所有的生成的源程序，最后使用</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">axis-admin</span><span style="font-size: 10pt; font-family: 宋体;">任务向</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Axis</span><span style="font-size: 10pt; font-family: 宋体;">部署</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Hello Web</span><span style="font-size: 10pt; font-family: 宋体;">服务。</span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span>&lt;axis-admin</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">       </span><span style="">    </span>port="${target.port}"</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">    </span><span style="">       </span><span style="">    </span>hostname="${target.server}"</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">            </span>failonerror="true"</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">            </span>servletpath="${target.appname}/services/AdminService"</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">            </span>debug="true"</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font size="3"><span style="">            </span>xmlfile="deploy.wsdd"/&gt;</font></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span lang="EN-US"><span style=""><font size="3">       </font></span></span><span style="font-size: 10pt; font-family: 宋体;">运行</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">ant deploy</span><span style="font-size: 10pt; font-family: 宋体;">，部署</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Hello</span><span style="font-size: 10pt; font-family: 宋体;">服务。</span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><font size="3"><span lang="EN-US"><span style="">   </span><b style=""><span style=""> </span></b></span><b style=""><span style="font-size: 12pt; font-family: 宋体;">测试</span></b></font><b style=""><span style="font-size: 12pt;" lang="EN-US"><o:p></o:p></span></b></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: 宋体;">现在可以测试所部署的</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Web</span><span style="font-size: 10pt; font-family: 宋体;">服务</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">hello</span><span style="font-size: 10pt; font-family: 宋体;">。可以通过浏览器，也可以利用刚才生成的测试文件</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">HelloServiceTestCase.java</span><span style="font-size: 10pt; font-family: 宋体;">来进行该项工作。如果利用测试文件</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">HelloServiceTestCase.java</span><span style="font-size: 10pt; font-family: 宋体;">，那么还需要对它进行稍作修改。具体来说，就是添加一个</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">main</span><span style="font-size: 10pt; font-family: 宋体;">函数，然后修改所生成的测试方法。</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style=""><font size="3">   </font></span></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><font size="3"><b style=""><span style="font-family: 宋体;">参考资料</span></b><span lang="EN-US"><o:p></o:p></span></font></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><font size="3"><span lang="EN-US">1</span><span style="font-family: 宋体;">．</span></font><span style="font-size: 10pt; font-family: 宋体;">阅读</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Apache Axis</span><span style="font-size: 10pt; font-family: 宋体;">开发指导文档</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">2</span><span style="font-size: 10pt; font-family: 宋体;">．查看</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Apache Ant</span><span style="font-size: 10pt; font-family: 宋体;">文档手册</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"><a href="http://ant.apache.org/manual/index.html">http://ant.apache.org/manual/index.html</a><o:p></o:p></span></p><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">3<a href="http://www.csdn.net/editor/%E8%AF%B7%E6%9F%A5%E7%9C%8Bhttp:/nagoya.apache.org/wiki/apachewiki.cgi?AxisProjectPages/AxisAntTasks"><span style="color: windowtext; font-family: 宋体; text-decoration: none;">．</span>http://nagoya.apache.org/wiki/apachewiki.cgi?AxisProjectPages/AxisAntTasks</a></span><span style="font-size: 10pt; font-family: 宋体;">得到更多关于</span><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">Axis-Ant</span><span style="font-size: 10pt; font-family: 宋体;">任务的信息。</span><br /><img src ="http://www.blogjava.net/libin2722/aggbug/296684.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2009-09-27 18:05 <a href="http://www.blogjava.net/libin2722/articles/296684.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>（转）牛人的WebService笔记</title><link>http://www.blogjava.net/libin2722/articles/296331.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Thu, 24 Sep 2009 10:37:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/296331.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/296331.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/296331.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/296331.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/296331.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 转载：http://www.blogjava.net/pixysoft/archive/2007/09/07.htmlOops! Axis quick start ! part 3 -- stub比较难的一部分前提条件：axis安装路径 C:\ericsson\javaextend\axis-1_4项目名称：axisdemo已经有的类：com.service.myService.java配置文件：...&nbsp;&nbsp;<a href='http://www.blogjava.net/libin2722/articles/296331.html'>阅读全文</a><img src ="http://www.blogjava.net/libin2722/aggbug/296331.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2009-09-24 18:37 <a href="http://www.blogjava.net/libin2722/articles/296331.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>（转）WebService大讲堂之Axis2(10)：使用soapmonitor模块监视soap请求与响应消息 </title><link>http://www.blogjava.net/libin2722/articles/296166.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Wed, 23 Sep 2009 06:43:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/296166.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/296166.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/296166.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/296166.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/296166.html</trackback:ping><description><![CDATA[
		<span style="FONT-FAMILY: 宋体">在</span>Axis2<span style="FONT-FAMILY: 宋体">中提供了一个</span>Axis2<span style="FONT-FAMILY: 宋体">模块（</span>soapmonitor<span style="FONT-FAMILY: 宋体">），该模块实现了与</span><a class="titlelink" id="Editor_Results_rprSelectionList_ctl03_LinkTitle" href="/nokiaguy/archive/2009/04/archive/2009/nokiaguy/archive/2009/02/archive/2009/02/archive/2009/02/16/254826.html">《WebService大讲堂之Axis2(9)：编写Axis2模块（Module）》</a><span style="FONT-FAMILY: 宋体">中实现的</span>logging<span style="FONT-FAMILY: 宋体">模块相同的功能，所不同的是，</span>logging<span style="FONT-FAMILY: 宋体">模块直接将</span>SOAP<span style="FONT-FAMILY: 宋体">请求与响应消息输出到</span>Tomcat<span style="FONT-FAMILY: 宋体">控制台中，而</span>soapmonitor<span style="FONT-FAMILY: 宋体">模块利用</span>applet<span style="FONT-FAMILY: 宋体">直接在页面中输出</span>SOAP<span style="FONT-FAMILY: 宋体">请求和响应消息。</span><p>    <span style="FONT-FAMILY: 宋体">下面是配置和使用</span>soapmonitor<span style="FONT-FAMILY: 宋体">模块的步骤：    <br /></span></p><p><strong><span style="FONT-FAMILY: 宋体">第</span>1<span style="FONT-FAMILY: 宋体">步：部署</span>Applet<span style="FONT-FAMILY: 宋体">和</span>Servlet</strong></p><p>    <span style="FONT-FAMILY: 宋体">由于</span>axis2<span style="FONT-FAMILY: 宋体">默认情况下已经自带了</span>soapmonitor<span style="FONT-FAMILY: 宋体">模块，因此，</span>soapmonitor<span style="FONT-FAMILY: 宋体">模块并不需要单独安装。但</span>applet<span style="FONT-FAMILY: 宋体">所涉及到的相应的</span>.class<span style="FONT-FAMILY: 宋体">文件需要安装一下。在</span>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps\axis2\WEB-INF\lib<span style="FONT-FAMILY: 宋体">目录中找到</span>soapmonitor-1.4.1.jar<span style="FONT-FAMILY: 宋体">文件，将该文件解压。虽然</span>applet<span style="FONT-FAMILY: 宋体">并不需要</span>soapmonitor-1.4.1.jar<span style="FONT-FAMILY: 宋体">文件中所有的</span>.class<span style="FONT-FAMILY: 宋体">文件，但为了方便，读者也可以直接将解压目录中的</span>org<span style="FONT-FAMILY: 宋体">目录复制到</span>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps\axis2<span style="FONT-FAMILY: 宋体">目录中，</span>Applet<span style="FONT-FAMILY: 宋体">所需的</span>.class<span style="FONT-FAMILY: 宋体">文件需要放在这个目录。然后再将</span>org<span style="FONT-FAMILY: 宋体">目录复制到</span>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps\axis2\WEB-INF\classes<span style="FONT-FAMILY: 宋体">目录中，</span>soapmonitor<span style="FONT-FAMILY: 宋体">模块中的</span>Servlet<span style="FONT-FAMILY: 宋体">所对应的</span>.class<span style="FONT-FAMILY: 宋体">文件需要放在这个目录。<br /></span></p><p><strong><span style="FONT-FAMILY: 宋体">第</span>2<span style="FONT-FAMILY: 宋体">步：配置</span>Servlet</strong></p><p>    <span style="FONT-FAMILY: 宋体">打开</span>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps\axis2\WEB-INF\web.xml<span style="FONT-FAMILY: 宋体">文件，在其中加入如下的内容：<br /></span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">servlet</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">servlet-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">SOAPMonitorService</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">servlet-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">servlet-class</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        org.apache.axis2.soapmonitor.servlet.SOAPMonitorService<br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">servlet-class</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">init-param</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">param-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">SOAPMonitorPort</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">param-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">param-value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">5001</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">param-value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">init-param</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">load-on-startup</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">load-on-startup</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">servlet</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">servlet-mapping</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">servlet-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">SOAPMonitorService</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">servlet-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">url-pattern</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">/SOAPMonitor</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">url-pattern</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">servlet-mapping</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span></div><p></p><p><strong><span style="FONT-FAMILY: 宋体">第</span>3<span style="FONT-FAMILY: 宋体">步：在</span>services.xml<span style="FONT-FAMILY: 宋体">文件中引用</span>soapmonitor<span style="FONT-FAMILY: 宋体">模块</span></strong></p>    <span style="FONT-FAMILY: 宋体">与引用logging模块一样，引用soapmonitor模块也需要使用&lt;module&gt;元素，引用soapmonitor模块的services.xml文件的内容如下：<br /></span><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">service </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="myService"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        使用logging和soapmonitor模块<br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #008000">&lt;!--</span><span style="COLOR: #008000">  引用logging模块  </span><span style="COLOR: #008000">--&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">module </span><span style="COLOR: #ff0000">ref</span><span style="COLOR: #0000ff">="logging"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #008000">&lt;!--</span><span style="COLOR: #008000">  引用soapmonitor模块  </span><span style="COLOR: #008000">--&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">module </span><span style="COLOR: #ff0000">ref</span><span style="COLOR: #0000ff">="soapmonitor"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">parameter </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="ServiceClass"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        service.MyService   <br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">parameter</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceivers</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceiver </span><span style="COLOR: #ff0000">mep</span><span style="COLOR: #0000ff">="http://www.w3.org/2004/08/wsdl/in-out"</span><span style="COLOR: #ff0000"><br />            class</span><span style="COLOR: #0000ff">="org.apache.axis2.rpc.receivers.RPCMessageReceiver"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">messageReceivers</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">service</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span></div><p>    <span style="FONT-FAMILY: 宋体">由于</span>soapmonitor<span style="FONT-FAMILY: 宋体">模块已经在</span>axis2.xml<span style="FONT-FAMILY: 宋体">进行配置了，因此，在本例中不需要再对</span>axis2.xml<span style="FONT-FAMILY: 宋体">文件进行配置了。    <br /></span></p><p><strong><span style="FONT-FAMILY: 宋体">第</span>4<span style="FONT-FAMILY: 宋体">步：使用</span>soapmonitor<span style="FONT-FAMILY: 宋体">模块</span></strong></p><span style="FONT-FAMILY: 宋体">    启动Tomcat后，在浏览器中输入如下的URL：<br /><br /><a href="http://localhost:8080/axis2/SOAPMonitor">http://localhost:8080/axis2/SOAPMonitor<br /><br /></a></span><a href="http://localhost:8080/axis2/SOAPMonitor"></a><p>    <span style="FONT-FAMILY: 宋体">在浏览器中将出现</span>soapmonitor<span style="FONT-FAMILY: 宋体">所带的</span>Applet<span style="FONT-FAMILY: 宋体">的界面，当访问</span>MyService<span style="FONT-FAMILY: 宋体">的</span>getGreeting<span style="FONT-FAMILY: 宋体">方法时，在</span>Tomcat<span style="FONT-FAMILY: 宋体">控制台与</span>Applet<span style="FONT-FAMILY: 宋体">中都显示了相应的</span>SOAP<span style="FONT-FAMILY: 宋体">请求和响应消息。如图</span>1<span style="FONT-FAMILY: 宋体">和图</span>2<span style="FONT-FAMILY: 宋体">分别是调用了两次</span>getGreeting<span style="FONT-FAMILY: 宋体">方法后输出的</span>SOAP<span style="FONT-FAMILY: 宋体">请求和响应消息。<br /><div align="center"><img alt="" src="http://www.blogjava.net/images/blogjava_net/nokiaguy/axis2_10/01.jpg" /><br /><br />图1<br /></div><br /><div align="center"><img alt="" src="http://www.blogjava.net/images/blogjava_net/nokiaguy/axis2_10/022.jpg" /><br /><br />图2<br /></div></span></p><p></p><p>    <span style="FONT-FAMILY: 宋体">如果读者想让</span>logging<span style="FONT-FAMILY: 宋体">和</span>soapmonitor<span style="FONT-FAMILY: 宋体">模块监视部署在</span>Axis2<span style="FONT-FAMILY: 宋体">中的所有</span>WebService<span style="FONT-FAMILY: 宋体">，可以在</span>axis2.xml<span style="FONT-FAMILY: 宋体">文件中使用</span>&lt;module&gt;<span style="FONT-FAMILY: 宋体">元素来引用这两个模块，代码如下：</span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #000000">    </span><span style="COLOR: #008000">&lt;!--</span><span style="COLOR: #008000">  引用logging模块  </span><span style="COLOR: #008000">--&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">module </span><span style="COLOR: #ff0000">ref</span><span style="COLOR: #0000ff">="logging"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #008000">&lt;!--</span><span style="COLOR: #008000">  引用soapmonitor模块  </span><span style="COLOR: #008000">--&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">module </span><span style="COLOR: #ff0000">ref</span><span style="COLOR: #0000ff">="soapmonitor"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span></div><br /><img src ="http://www.blogjava.net/libin2722/aggbug/296166.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2009-09-23 14:43 <a href="http://www.blogjava.net/libin2722/articles/296166.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>（转）WebService大讲堂之Axis2(8)：异步调用WebService </title><link>http://www.blogjava.net/libin2722/articles/296164.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Wed, 23 Sep 2009 06:42:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/296164.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/296164.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/296164.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/296164.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/296164.html</trackback:ping><description><![CDATA[
		<span style="FONT-FAMILY: 宋体">在前面几篇文章中都是使用同步方式来调用</span>WebService<span style="FONT-FAMILY: 宋体">。也就是说，如果被调用的</span>WebService<span style="FONT-FAMILY: 宋体">方法长时间不返回，客户端将一直被阻塞，直到该方法返回为止。使用同步方法来调用</span>WebService<span style="FONT-FAMILY: 宋体">虽然很直观，但当</span>WebService<span style="FONT-FAMILY: 宋体">方法由于各种原因需要很长时间才能返回的话，就会使客户端程序一直处于等待状态，这样用户是无法忍受的。</span><br />    <span style="FONT-FAMILY: 宋体">当然，我们很容易就可以想到解决问题的方法，这就是多线程。解决问题的基本方法是将访问</span>WebService<span style="FONT-FAMILY: 宋体">的任务交由一个或多个线程来完成，而主线程并不负责访问</span>WebService<span style="FONT-FAMILY: 宋体">。这样即使被访问的</span>WebService<span style="FONT-FAMILY: 宋体">方法长时间不返回，客户端仍然可以做其他的工作。我们可以管这种通过多线程访问</span>WebService<span style="FONT-FAMILY: 宋体">的方式称为异步访问。</span><br />    <span style="FONT-FAMILY: 宋体">虽然直接使用多线程可以很好地解决这个问题，但比较麻烦。幸好</span>Axis2<span style="FONT-FAMILY: 宋体">的客户端提供了异步访问</span>WebService<span style="FONT-FAMILY: 宋体">的功能。</span><br />    RPCServiceClient<span style="FONT-FAMILY: 宋体">类提供了一个</span>invokeNonBlocking<span style="FONT-FAMILY: 宋体">方法可以通过异步的方式来访问</span>WebService<span style="FONT-FAMILY: 宋体">。下面先来建立一个</span>WebService<span>。<br /><span>    </span>MyService</span><span style="FONT-FAMILY: 宋体">是一个</span>WebService<span style="FONT-FAMILY: 宋体">类，代码如下：<br /></span><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> service;<br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> MyService<br />{<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> String getName()<br />    {<br />        </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"><br />        {            <br />            System.out.println(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">getName方法正在执行<img alt="" src="http://www.blogjava.net/images/dot.gif" /></span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  延迟5秒</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">            Thread.sleep(</span><span style="COLOR: #000000">5000</span><span style="COLOR: #000000">);<br />        }<br />        </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (Exception e)<br />        {        <br />        }<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">火星</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />    }<br />}<br /></span></div><p>    <span style="FONT-FAMILY: 宋体">为了模拟需要一定时间才返回的</span>WebService<span style="FONT-FAMILY: 宋体">方法，在</span>getName<span style="FONT-FAMILY: 宋体">方法中使用了</span>sleep<span style="FONT-FAMILY: 宋体">方法来延迟</span>5<span style="FONT-FAMILY: 宋体">秒。</span><br />    <span style="FONT-FAMILY: 宋体">下面是</span>MyService<span style="FONT-FAMILY: 宋体">类的配置代码：<br /></span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #008000">&lt;!--</span><span style="COLOR: #008000">  services.xml  </span><span style="COLOR: #008000">--&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">service </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="myService"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        异步调用演示<br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">parameter </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="ServiceClass"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        service.MyService   <br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">parameter</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceivers</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceiver </span><span style="COLOR: #ff0000">mep</span><span style="COLOR: #0000ff">="http://www.w3.org/2004/08/wsdl/in-out"</span><span style="COLOR: #ff0000"><br />            class</span><span style="COLOR: #0000ff">="org.apache.axis2.rpc.receivers.RPCMessageReceiver"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">messageReceivers</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">service</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span></div><p></p><p>    <span style="FONT-FAMILY: 宋体">从上面的配置代码可以看出，</span>MyService<span style="FONT-FAMILY: 宋体">的配置方式与前几章的</span>WebService<span style="FONT-FAMILY: 宋体">的配置方式完全一样，也就是说，</span>MyService<span style="FONT-FAMILY: 宋体">只是一个普通的</span>WebService<span style="FONT-FAMILY: 宋体">。</span><br />    <span style="FONT-FAMILY: 宋体">下面是异步调用</span>MyService<span style="FONT-FAMILY: 宋体">的</span>Java<span style="FONT-FAMILY: 宋体">客户端代码：<br /><br /></span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> client;<br /><br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> javax.xml.namespace.QName;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.addressing.EndpointReference;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.client.Options;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.context.MessageContext;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.rpc.client.RPCServiceClient;<br /><br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> RPCAsyncClient<br />{<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> main(String[] args) </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception<br />    {<br />        RPCServiceClient serviceClient </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> RPCServiceClient();<br />        Options options </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> serviceClient.getOptions();<br />        EndpointReference targetEPR </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> EndpointReference(<br />                </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">http://localhost:8080/axis2/services/myService</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        options.setTo(targetEPR);<br />        Object[] opAddEntryArgs </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Object[]{};<br />        QName opAddEntry </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> QName(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">http://service</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">getName</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        serviceClient.invokeNonBlocking(opAddEntry, opAddEntryArgs,<br />                </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> org.apache.axis2.client.async.AxisCallback()<br />                {<br />                    @Override<br />                    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> onComplete()<br />                    {<br />                    }<br />                    @Override<br />                    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> onError(Exception arg0)<br />                    {<br />                    }                    }<br />                    @Override<br />                    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> onFault(MessageContext arg0)<br />                    {<br />                    }<br />                    @Override<br />                    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> onMessage(MessageContext mc)<br />                    {<br />                        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  输出返回值</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">                        System.out.println(mc.getEnvelope().getFirstElement()<br />                                .getFirstElement().getFirstElement().getText());<br />                    }<br />                });<br />        System.out.println(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">异步调用！</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  阻止程序退出</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        System.in.read();<br />    }<br />}  <br /></span></div><p></p><p>    <span style="FONT-FAMILY: 宋体">从上面的代码可以看出，</span>invokeNonBlocking<span style="FONT-FAMILY: 宋体">方法有三个参数，前两个参数分别指定了要调用的方法及方法参数的相关信息，而最后一个参数并不是方法返回值的类型信息，而是一个实现</span>org.apache.axis2.client.async.AxisCallback<span style="FONT-FAMILY: 宋体">接口的类的对象实例。在本例中隐式实现了</span>AxisCallback<span style="FONT-FAMILY: 宋体">接口。在</span>AxisCallback<span style="FONT-FAMILY: 宋体">接口中有四个方法需要实现，其中当被异步调用的方法返回时</span>onMessage<span style="FONT-FAMILY: 宋体">方法被调用。当运行上面的程序后，将输出如下的信息：</span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #000000">异步调用！<br />火星</span></div><p>    <span style="FONT-FAMILY: 宋体">虽然上面的例子可以实现异步调用，但比较麻烦。为了更方便地实现异步调用，可以使用</span>wsdl2java<span style="FONT-FAMILY: 宋体">命令的</span>-a<span style="FONT-FAMILY: 宋体">参数生成可异步调用的</span>Stub<span style="FONT-FAMILY: 宋体">类。下面的命令可生成同步和异步调用的客户端代码（两个类），其中</span>-s<span style="FONT-FAMILY: 宋体">表示生成同步调用代码，</span>-a<span style="FONT-FAMILY: 宋体">表示生成异步调用代码。</span><span><br /></span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #000000">%AXIS2_HOME%\bin\wsdl2java -uri http://localhost:</span><span style="COLOR: #000000">8080</span><span style="COLOR: #000000">/axis2/services/myService?wsdl -p client -s -a -o stub</span></div><p>    <span style="FONT-FAMILY: 宋体">在执行上面的命令后，将生成两个类：</span>MyServiceStub<span style="FONT-FAMILY: 宋体">和</span>MyServiceCallbackHandler<span style="FONT-FAMILY: 宋体">类，其中</span>MyServiceStub<span style="FONT-FAMILY: 宋体">类负责同步和异步调用</span>WebService<span style="FONT-FAMILY: 宋体">，</span>MyServiceCallbackHandler<span style="FONT-FAMILY: 宋体">类是一个抽象类，也是一个回调类，当使用异步方式调用</span>WebService<span style="FONT-FAMILY: 宋体">方法时，如果方法返回，则</span>MyServiceCallbackHandler<span style="FONT-FAMILY: 宋体">类的</span>receiveResultgetName<span style="FONT-FAMILY: 宋体">方法被调用。下面是使用</span>MyServiceStub<span style="FONT-FAMILY: 宋体">类异步访问</span>WebService<span style="FONT-FAMILY: 宋体">的代码：</span><br /></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> client;<br /><br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> client.MyServiceStub.GetNameResponse;<br /><br /></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> MyCallback </span><span style="COLOR: #0000ff">extends</span><span style="COLOR: #000000"> MyServiceCallbackHandler<br />{<br />    @Override<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> receiveResultgetName(GetNameResponse result)<br />    {<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  输出getName方法的返回结果</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        System.out.println(result.get_return());<br />    }<br />}<br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> StubClient<br />{<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> main(String[] args) </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception  <br />    {<br />        MyServiceStub stub </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> MyServiceStub();        <br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  异步调用WebService</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        stub.startgetName(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> MyCallback());<br />        System.out.println(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">异步调用！</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        System.in.read();    <br />    } <br />}<br /></span></div><p></p><p>   <span style="FONT-FAMILY: 宋体">执行上面的程序后，将输出如下的信息：    <br /></span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #000000">异步调用！<br />火星<br /></span></div><span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Times New Roman'"><br />      </span><span style="FONT-FAMILY: 宋体">在.net中也可以使用异步的方式来调用WebService，如在C#中可使用如下的代码来异步调用getName方法：<br /></span><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  回调方法</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> getNameCompletedEvent(object sender, WSC.asyn.getNameCompletedEventArgs e)<br />{<br />    listBox1.Items.Add( e.Result.@</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">);<br />}<br /></span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> button1_Click(object sender, EventArgs e)<br />{          <br />    async.myService my </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> WSC.async.myService();<br />    my.getNameCompleted </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> WSC.async.getNameCompletedEventHandler(getNameCompletedEvent);<br />     my.getNameAsync();<br />     MessageBox.Show(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">完成调用</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />}<br /></span></div><p>    <span style="FONT-FAMILY: 宋体">其中</span>async<span style="FONT-FAMILY: 宋体">是引用</span>MyService<span style="FONT-FAMILY: 宋体">的服务名。要注意的是，在</span>C#<span style="FONT-FAMILY: 宋体">中不能在同一个</span>WebService<span style="FONT-FAMILY: 宋体">实例的</span>getName<span style="FONT-FAMILY: 宋体">方法未返回之前，再次调用该实例的</span>getName<span style="FONT-FAMILY: 宋体">方法，否则将抛出异常。如下面的代码会抛出一个异常：</span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #000000">    async.myService my </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> WSC.async.myService();<br />    my.getNameCompleted </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> WSC.async.getNameCompletedEventHandler(getNameCompletedEvent);<br />    my.getNameAsync();<br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  将抛出异常</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">    my.getNameAsync();<br /></span></div><p></p><p>    <span style="FONT-FAMILY: 宋体">但不同的</span>WebService<span style="FONT-FAMILY: 宋体">实例的方法可以在方法未返回时调用，如下面的代码是可以正常工作的：</span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #000000">asyn.myService my </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> WSC.asyn.myService();<br />my.getNameAsync();<br />my.getNameCompleted </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> WSC.asyn.getNameCompletedEventHandler(getNameCompletedEvent);<br />asyn.myService my1 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> WSC.asyn.myService();<br />my1.getNameCompleted </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> WSC.asyn.getNameCompletedEventHandler(getNameCompletedEvent);<br />my1.getNameAsync();</span></div><br /><img src ="http://www.blogjava.net/libin2722/aggbug/296164.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2009-09-23 14:42 <a href="http://www.blogjava.net/libin2722/articles/296164.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>（转）WebService大讲堂之Axis2(9)：编写Axis2模块（Module） </title><link>http://www.blogjava.net/libin2722/articles/296165.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Wed, 23 Sep 2009 06:42:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/296165.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/296165.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/296165.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/296165.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/296165.html</trackback:ping><description><![CDATA[Axis2<span style="FONT-FAMILY: 宋体">可以通过模块（</span>Module<span style="FONT-FAMILY: 宋体">）进行扩展。</span>Axis2<span style="FONT-FAMILY: 宋体">模块至少需要有两个类，这两个类分别实现了</span>Module<span style="FONT-FAMILY: 宋体">和</span>Handler<span style="FONT-FAMILY: 宋体">接口。开发和使用一个</span>Axis2<span style="FONT-FAMILY: 宋体">模块的步骤如下：</span><p>1. <span style="FONT-FAMILY: 宋体">编写实现</span>Module<span style="FONT-FAMILY: 宋体">接口的类。</span>Axis2<span style="FONT-FAMILY: 宋体">模块在进行初始化、销毁等动作时会调用该类中相应的方法）。</span></p><p>2. <span style="FONT-FAMILY: 宋体">编写实现</span>Handler<span style="FONT-FAMILY: 宋体">接口的类。该类是</span>Axis2<span style="FONT-FAMILY: 宋体">模块的业务处理类。</span></p><p>3. <span style="FONT-FAMILY: 宋体">编写</span>module.xml<span style="FONT-FAMILY: 宋体">文件。该文件放在</span>META-INF<span style="FONT-FAMILY: 宋体">目录中，用于配置</span>Axis2<span style="FONT-FAMILY: 宋体">模块。</span></p><p>4. <span style="FONT-FAMILY: 宋体">在</span>axis2.xml<span style="FONT-FAMILY: 宋体">文件中配置</span>Axis2<span style="FONT-FAMILY: 宋体">模块。</span></p><p>5. <span style="FONT-FAMILY: 宋体">在</span>services.xml<span style="FONT-FAMILY: 宋体">文件中配置</span>Axis2<span style="FONT-FAMILY: 宋体">模块。每一个</span>Axis2<span style="FONT-FAMILY: 宋体">模块都需要使用</span>&lt;module&gt;<span style="FONT-FAMILY: 宋体">元素引用才能使用。</span></p><p>6. <span style="FONT-FAMILY: 宋体">发布</span>Axis2<span style="FONT-FAMILY: 宋体">模块。需要使用</span>jar<span style="FONT-FAMILY: 宋体">命令将</span>Axis2<span style="FONT-FAMILY: 宋体">模块压缩成</span>.mar<span style="FONT-FAMILY: 宋体">包（文件扩展名必须是</span>.mar<span style="FONT-FAMILY: 宋体">），然后将</span>.mar<span style="FONT-FAMILY: 宋体">文件放在</span></p><p>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps\axis2\WEB-INF\modules<span style="FONT-FAMILY: 宋体">目录中。    <br />    先来编写一个WebService类，代码如下：<br /></span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> service;<br /><br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> MyService<br />{<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> String getGreeting(String name)<br />    {<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">您好 </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> name;<br />    }<br />}<br /></span></div><p></p><p>    <span style="FONT-FAMILY: 宋体">下面我们来编写一个记录请求和响应</span>SOAP<span style="FONT-FAMILY: 宋体">消息的</span>Axis2<span style="FONT-FAMILY: 宋体">模块。当客户端调用</span>WebService<span style="FONT-FAMILY: 宋体">方法时，该</span>Axis2<span style="FONT-FAMILY: 宋体">模块会将请求和响应</span>SOAP<span style="FONT-FAMILY: 宋体">消息输出到</span>Tomcat<span style="FONT-FAMILY: 宋体">控制台上。</span></p><p><strong><span style="FONT-FAMILY: 宋体">第</span>1<span style="FONT-FAMILY: 宋体">步：编写</span>LoggingModule<span style="FONT-FAMILY: 宋体">类</span></strong></p><p><span><span>    </span>LoggingModule</span><span style="FONT-FAMILY: 宋体">类实现了</span>Module<span style="FONT-FAMILY: 宋体">接口，代码如下：</span></p><span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Times New Roman'"></span><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> module;<br /><br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.AxisFault;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.context.ConfigurationContext;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.description.AxisDescription;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.description.AxisModule;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.modules.Module;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.neethi.Assertion;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.neethi.Policy;<br /><br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> LoggingModule </span><span style="COLOR: #0000ff">implements</span><span style="COLOR: #000000"> Module<br />{<br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> initialize the module</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> init(ConfigurationContext configContext, AxisModule module)<br />            </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> AxisFault<br />    {<br />        System.out.println(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">init</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />    }<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> engageNotify(AxisDescription axisDescription) </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> AxisFault<br />    {<br />    }<br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> shutdown the module</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> shutdown(ConfigurationContext configurationContext)<br />            </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> AxisFault<br />    {<br />        System.out.println(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">shutdown</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />    }<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> String[] getPolicyNamespaces()<br />    {<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">;<br />    }<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> applyPolicy(Policy policy, AxisDescription axisDescription)<br />            </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> AxisFault<br />    {<br />    }<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">boolean</span><span style="COLOR: #000000"> canSupportAssertion(Assertion assertion)<br />    {<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br />    }<br />}<br /></span></div><span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Times New Roman'"></span><p>    <span style="FONT-FAMILY: 宋体">在本例中</span>LoggingModule<span style="FONT-FAMILY: 宋体">类并没实现实际的功能，但该类必须存在。当</span>Tomcat<span style="FONT-FAMILY: 宋体">启动时会装载该</span>Axis2<span style="FONT-FAMILY: 宋体">模块，同时会调用</span>LoggingModule<span style="FONT-FAMILY: 宋体">类的</span>init<span style="FONT-FAMILY: 宋体">方法，并在</span>Tomcat<span style="FONT-FAMILY: 宋体">控制台中输出“</span>init<span style="FONT-FAMILY: 宋体">”。</span></p><p><strong><span style="FONT-FAMILY: 宋体">第</span>2<span style="FONT-FAMILY: 宋体">步：编写</span>LogHandler<span style="FONT-FAMILY: 宋体">类<br /></span></strong></p><p><span><span>    </span>LogHandler</span><span style="FONT-FAMILY: 宋体">类实现了</span>Handler<span style="FONT-FAMILY: 宋体">接口，代码如下：<br /></span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> module;<br /><br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.AxisFault;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.context.MessageContext;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.engine.Handler;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.handlers.AbstractHandler;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.commons.logging.Log;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.commons.logging.LogFactory;<br /><br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> LogHandler </span><span style="COLOR: #0000ff">extends</span><span style="COLOR: #000000"> AbstractHandler </span><span style="COLOR: #0000ff">implements</span><span style="COLOR: #000000"> Handler<br />{<br />    </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">final</span><span style="COLOR: #000000"> Log log </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> LogFactory.getLog(LogHandler.</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">);<br />    </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> String name;<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> String getName()<br />    {<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> name;<br />    }<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> InvocationResponse invoke(MessageContext msgContext)<br />            </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> AxisFault<br />    {<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  向Tomcat控制台输出请求和响应SOAP消息</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        log.info(msgContext.getEnvelope().toString());<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> InvocationResponse.CONTINUE;<br />    }<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> revoke(MessageContext msgContext)<br />    {<br />        log.info(msgContext.getEnvelope().toString());<br />    }<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> setName(String name)<br />    {<br />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.name </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> name;<br />    }<br />}<br /></span></div><p></p><p><span><span>    </span>LogHandler</span><span style="FONT-FAMILY: 宋体">类的核心方法是</span>invoke<span style="FONT-FAMILY: 宋体">，当使用该</span>Axis2<span style="FONT-FAMILY: 宋体">模块的</span>WebService<span style="FONT-FAMILY: 宋体">的方法被调用时，</span>LogHandler<span style="FONT-FAMILY: 宋体">类的</span>invoke<span style="FONT-FAMILY: 宋体">方法被调用。    </span><span><br /><br /></span><strong><span style="FONT-FAMILY: 宋体">第</span>3<span style="FONT-FAMILY: 宋体">步：编写</span>module.xml<span style="FONT-FAMILY: 宋体">文件    <br /></span></strong></p>    <span style="FONT-FAMILY: 宋体">在META-INF目录中建立一个module.xml文件，内容如下：<br /></span><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">module </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="logging"</span><span style="COLOR: #ff0000"> class</span><span style="COLOR: #0000ff">="module.LoggingModule"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">InFlow</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">handler </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="InFlowLogHandler"</span><span style="COLOR: #ff0000"> class</span><span style="COLOR: #0000ff">="module.LogHandler"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">order </span><span style="COLOR: #ff0000">phase</span><span style="COLOR: #0000ff">="loggingPhase"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">handler</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">InFlow</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">OutFlow</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">handler </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="OutFlowLogHandler"</span><span style="COLOR: #ff0000"> class</span><span style="COLOR: #0000ff">="module.LogHandler"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">order </span><span style="COLOR: #ff0000">phase</span><span style="COLOR: #0000ff">="loggingPhase"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"> <br />        </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">handler</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">OutFlow</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">OutFaultFlow</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">handler </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="FaultOutFlowLogHandler"</span><span style="COLOR: #ff0000"> class</span><span style="COLOR: #0000ff">="module.LogHandler"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">order </span><span style="COLOR: #ff0000">phase</span><span style="COLOR: #0000ff">="loggingPhase"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">handler</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">OutFaultFlow</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">InFaultFlow</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">handler </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="FaultInFlowLogHandler"</span><span style="COLOR: #ff0000"> class</span><span style="COLOR: #0000ff">="module.LogHandler"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">order </span><span style="COLOR: #ff0000">phase</span><span style="COLOR: #0000ff">="loggingPhase"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">handler</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">InFaultFlow</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">module</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span></div><p><strong><span style="FONT-FAMILY: 宋体">第</span>4<span style="FONT-FAMILY: 宋体">步：在</span>axis2.xml<span style="FONT-FAMILY: 宋体">文件中配置</span>Axis2<span style="FONT-FAMILY: 宋体">模块</span></strong></p><p>    <span style="FONT-FAMILY: 宋体">打开</span>axis2.xml<span style="FONT-FAMILY: 宋体">文件，分别在如下四个</span>&lt;phaseOrder&gt;<span style="FONT-FAMILY: 宋体">元素中加入</span><span>&lt;phase name="loggingPhase"/&gt;</span><span style="FONT-FAMILY: 宋体">：<br /></span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">phaseOrder </span><span style="COLOR: #ff0000">type</span><span style="COLOR: #0000ff">="InFlow"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    <img alt="" src="http://www.blogjava.net/images/dot.gif" /> <img alt="" src="http://www.blogjava.net/images/dot.gif" /><br /></span><span style="COLOR: #0000ff">    &lt;</span><span style="COLOR: #800000">phase </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="soapmonitorPhase"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">    &lt;</span><span style="COLOR: #800000">phase </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="loggingPhase"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">phaseOrder</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">phaseOrder </span><span style="COLOR: #ff0000">type</span><span style="COLOR: #0000ff">="OutFlow"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    <img alt="" src="http://www.blogjava.net/images/dot.gif" /> <img alt="" src="http://www.blogjava.net/images/dot.gif" /><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">phase </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="Security"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">phase </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="loggingPhase"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">phaseOrder</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">phaseOrder </span><span style="COLOR: #ff0000">type</span><span style="COLOR: #0000ff">="InFaultFlow"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    <img alt="" src="http://www.blogjava.net/images/dot.gif" /> <img alt="" src="http://www.blogjava.net/images/dot.gif" /><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">phase </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="soapmonitorPhase"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">phase </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="loggingPhase"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">phaseOrder</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">phaseOrder </span><span style="COLOR: #ff0000">type</span><span style="COLOR: #0000ff">="OutFaultFlow"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    <img alt="" src="http://www.blogjava.net/images/dot.gif" /> <img alt="" src="http://www.blogjava.net/images/dot.gif" /><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">phase </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="Security"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">phase </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="loggingPhase"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">phaseOrder</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span></div><p></p><p><strong><span style="FONT-FAMILY: 宋体">第</span>5<span style="FONT-FAMILY: 宋体">步：在</span>services.xml<span style="FONT-FAMILY: 宋体">文件中引用</span>logging<span style="FONT-FAMILY: 宋体">模块</span></strong></p><p>    services.xml<span style="FONT-FAMILY: 宋体">文件的内容如下：</span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">service </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="myService"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        使用logging模块<br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #008000">&lt;!--</span><span style="COLOR: #008000">  引用logging模块  </span><span style="COLOR: #008000">--&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">module </span><span style="COLOR: #ff0000">ref</span><span style="COLOR: #0000ff">="logging"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">parameter </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="ServiceClass"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        service.MyService   <br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">parameter</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceivers</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceiver </span><span style="COLOR: #ff0000">mep</span><span style="COLOR: #0000ff">="http://www.w3.org/2004/08/wsdl/in-out"</span><span style="COLOR: #ff0000"><br />            class</span><span style="COLOR: #0000ff">="org.apache.axis2.rpc.receivers.RPCMessageReceiver"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">messageReceivers</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">service</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span></div><p><strong><span style="FONT-FAMILY: 宋体">第</span>6<span style="FONT-FAMILY: 宋体">步：发布</span>logging<span style="FONT-FAMILY: 宋体">模块</span></strong></p><p>    <span style="FONT-FAMILY: 宋体">到现在为止，我们应用可以建立两个发行包：</span>logging.mar<span style="FONT-FAMILY: 宋体">和</span>service.aar<span style="FONT-FAMILY: 宋体">。其中</span>logging.mar<span style="FONT-FAMILY: 宋体">文件是</span>Axis2<span style="FONT-FAMILY: 宋体">模块的发行包，该包的目录结构如下：</span></p><p>logging.mar</p><p><span><span>    </span>module\LoggingModule.class</span></p><p><span><span>    </span>module\LogHandler.class</span></p><p><span><span>    </span>META-INF\module.xml</span></p><p><span><span>    </span>service.aar</span><span style="FONT-FAMILY: 宋体">文件是本例编写的</span>WebService<span style="FONT-FAMILY: 宋体">发行包，该包的目录结构如下：</span></p><p>service.aar</p><p><span><span>    </span>service\MyService.class</span></p><p><span><span>    </span>META-INF\services.xml</span></p><p>    <span style="FONT-FAMILY: 宋体">将</span>logging.mar<span style="FONT-FAMILY: 宋体">文件放在</span>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps\axis2\WEB-INF\modules<span style="FONT-FAMILY: 宋体">目录中，将</span>service.aar<span style="FONT-FAMILY: 宋体">文件放在</span>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps\axis2\WEB-INF\services<span style="FONT-FAMILY: 宋体">目录中。要注意的是，如果</span>modules<span style="FONT-FAMILY: 宋体">目录中包含了</span>modules.list<span style="FONT-FAMILY: 宋体">文件，</span>Axis2<span style="FONT-FAMILY: 宋体">会只装载在该文件中引用的</span>Axis2<span style="FONT-FAMILY: 宋体">模块，因此，必须在该文件中引用</span>logging<span style="FONT-FAMILY: 宋体">模块，该文件的内容如下：</span></p><p>addressing-1.4.1.mar</p><p>soapmonitor-1.4.1.mar</p><p>ping-1.4.1.mar</p><p>mex-1.4.1.mar</p><p>axis2-scripting-1.4.1.mar</p><p>logging.mar</p><p>    <span style="FONT-FAMILY: 宋体">如果</span>modules<span style="FONT-FAMILY: 宋体">目录中不包含</span>modules.list<span style="FONT-FAMILY: 宋体">文件，则</span>Axis2<span style="FONT-FAMILY: 宋体">会装载</span>modules<span style="FONT-FAMILY: 宋体">文件中的所有</span>Axis2<span style="FONT-FAMILY: 宋体">模块。</span></p><p>    <span style="FONT-FAMILY: 宋体">现在启动</span>Tomcat<span style="FONT-FAMILY: 宋体">，使用如下的</span>C#<span style="FONT-FAMILY: 宋体">代码调用</span>MyService<span style="FONT-FAMILY: 宋体">的</span>getGreeting<span style="FONT-FAMILY: 宋体">方法则会在</span>Tomcat<span style="FONT-FAMILY: 宋体">控制台中输出相应的请求和响应</span>SOAP<span style="FONT-FAMILY: 宋体">消息。<br /></span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  async是引用MyService的服务名</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">async.myService my </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> WSC.asyn.myService();<br />MessageBox.Show(my.getGreeting(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">中国</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br />MessageBox.Show(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">完成调用</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /></span></div><p></p><p>    <span style="FONT-FAMILY: 宋体">在执行上面的代码后，在</span>Tomcat<span style="FONT-FAMILY: 宋体">控制台中输出的信息如下</span><span style="FONT-FAMILY: 宋体">图所示。<br /><img alt="" src="http://www.blogjava.net/images/blogjava_net/nokiaguy/axis2_9/01.jpg" /><br /><br /></span></p><img src ="http://www.blogjava.net/libin2722/aggbug/296165.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2009-09-23 14:42 <a href="http://www.blogjava.net/libin2722/articles/296165.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>（转）WebService大讲堂之Axis2(7)：将Spring的装配JavaBean发布成WebService </title><link>http://www.blogjava.net/libin2722/articles/296163.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Wed, 23 Sep 2009 06:41:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/296163.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/296163.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/296163.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/296163.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/296163.html</trackback:ping><description><![CDATA[
		<span style="FONT-FAMILY: 宋体">在现今的</span>Web<span style="FONT-FAMILY: 宋体">应用中经常使用</span>Spring<span style="FONT-FAMILY: 宋体">框架来装载</span>JavaBean<span style="FONT-FAMILY: 宋体">。如果要想将某些在</span>Spring<span style="FONT-FAMILY: 宋体">中装配的</span>JavaBean<span style="FONT-FAMILY: 宋体">发布成</span>WebService<span style="FONT-FAMILY: 宋体">，使用</span>Axis2<span style="FONT-FAMILY: 宋体">的</span>Spring<span style="FONT-FAMILY: 宋体">感知功能是非常容易做到的。</span><br />    <span style="FONT-FAMILY: 宋体">在本文的例子中，除了</span>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps\axis2<span style="FONT-FAMILY: 宋体">目录及该目录中的相关库外，还需要</span>Spring<span style="FONT-FAMILY: 宋体">框架中的</span>spring.jar<span style="FONT-FAMILY: 宋体">文件，将该文件复制到</span>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps\axis2\WEB-INF\lib<span style="FONT-FAMILY: 宋体">目录中。</span><br />    <span style="FONT-FAMILY: 宋体">下面先建立一个</span>JavaBean<span style="FONT-FAMILY: 宋体">（该</span>JavaBean<span style="FONT-FAMILY: 宋体">最终要被发布成</span>WebService<span style="FONT-FAMILY: 宋体">），代码如下：<br /></span><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> service;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> entity.Person;<br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> SpringService<br />{<br />    </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> String name;<br />    </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> String job;<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> setName(String name)<br />    {<br />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.name </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> name;<br />    }<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> setJob(String job)<br />    {<br />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.job </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> job;<br />    }<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> Person getPerson()<br />    {<br />        Person person </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Person();<br />        person.setName(name);<br />        person.setJob(job);<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> person;<br />    }<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> String getGreeting(String name)<br />    {<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">hello </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> name;<br />    }<br />}</span></div><p></p><p>    <span style="FONT-FAMILY: 宋体">其中</span>Person<span style="FONT-FAMILY: 宋体">也是一个</span>JavaBean<span style="FONT-FAMILY: 宋体">，代码如下：</span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> entity;<br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> Person<br />{<br />    </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> String name;<br />    </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> String job;<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> String getName()<br />    {<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> name;<br />    }<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> setName(String name)<br />    {<br />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.name </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> name;<br />    }<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> String getJob()<br />    {<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> job;<br />    }<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> setJob(String job)<br />    {<br />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.job </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> job;<br />    }<br />}<br /></span></div><p></p><p>    <span style="FONT-FAMILY: 宋体">将上面两个</span>Java<span style="FONT-FAMILY: 宋体">源文件编译后，放到</span>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps\axis2\WEB-INF\classes<span style="FONT-FAMILY: 宋体">目录中。</span></p><p><span style="FONT-FAMILY: 宋体">    在</span>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps\axis2\WEB-INF\web.xml文件中加入下面的内容：</p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">listener</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">listener-class</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">org.springframework.web.context.ContextLoaderListener</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">listener-class</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">listener</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">context-param</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />      </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">param-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">contextConfigLocation</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">param-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />      </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">param-value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">/WEB-INF/applicationContext.xml</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">param-value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">context-param</span><span style="COLOR: #0000ff">&gt;</span></div><p>    <span style="FONT-FAMILY: 宋体">在</span>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps\axis2\WEB-INF<span style="FONT-FAMILY: 宋体">目录中建立一个</span>applicationContext.xml<span style="FONT-FAMILY: 宋体">文件，该文件是</span>Spring<span style="FONT-FAMILY: 宋体">框架用于装配</span>JavaBean<span style="FONT-FAMILY: 宋体">的配置文件，内容如下：<br /></span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">&lt;?</span><span style="COLOR: #ff00ff">xml version="1.0" encoding="UTF-8"</span><span style="COLOR: #0000ff">?&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">beans </span><span style="COLOR: #ff0000">xmlns</span><span style="COLOR: #0000ff">="http://www.springframework.org/schema/beans"</span><span style="COLOR: #ff0000"><br />        xmlns:xsi</span><span style="COLOR: #0000ff">="http://www.w3.org/2001/XMLSchema-instance"</span><span style="COLOR: #ff0000"><br />        xmlns:aop</span><span style="COLOR: #0000ff">="http://www.springframework.org/schema/aop"</span><span style="COLOR: #ff0000"><br />        xmlns:tx</span><span style="COLOR: #0000ff">="http://www.springframework.org/schema/tx"</span><span style="COLOR: #ff0000"><br />        xsi:schemaLocation</span><span style="COLOR: #0000ff">="<br />            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd<br />            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd<br />            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />  </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">bean </span><span style="COLOR: #ff0000">id</span><span style="COLOR: #0000ff">="springService"</span><span style="COLOR: #ff0000"> class</span><span style="COLOR: #0000ff">="service.SpringService"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />     </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="name"</span><span style="COLOR: #ff0000"> value</span><span style="COLOR: #0000ff">="姚明"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />     </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="job"</span><span style="COLOR: #ff0000"> value</span><span style="COLOR: #0000ff">="职业男篮"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"> <br />  </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">bean</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">   <br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">beans</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span></div><p></p><p>    <span style="FONT-FAMILY: 宋体">在</span>applicationContext.xml<span style="FONT-FAMILY: 宋体">文件中装配了</span>service.SpringService<span style="FONT-FAMILY: 宋体">类，并被始化了</span>name<span style="FONT-FAMILY: 宋体">和</span>job<span style="FONT-FAMILY: 宋体">属性。在配置完</span>SpringService<span style="FONT-FAMILY: 宋体">类后，就可以直接在程序中</span>FileSystemXmlApplicationContext<span style="FONT-FAMILY: 宋体">类或其他类似功能的类读取</span>applicationContext.xml<span style="FONT-FAMILY: 宋体">文件中的内容，并获得</span>SpringService<span style="FONT-FAMILY: 宋体">类的对象实例。但现在我们并不这样做，而是将</span>SpringService<span style="FONT-FAMILY: 宋体">类发布成</span>WebService<span style="FONT-FAMILY: 宋体">。</span></p><p>    <span style="FONT-FAMILY: 宋体">在</span>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps\axis2\WEB-INF\lib<span style="FONT-FAMILY: 宋体">目录中有一个</span>axis2-spring-1.4.1.jar<span style="FONT-FAMILY: 宋体">文件，该文件用于将被装配</span>JavaBean<span style="FONT-FAMILY: 宋体">的发布成</span>WebService<span style="FONT-FAMILY: 宋体">。在</span>D<span style="FONT-FAMILY: 宋体">盘建立一个</span>axi2-spring-ws<span style="FONT-FAMILY: 宋体">目录，并在该目录中建立一个</span>META-INF<span style="FONT-FAMILY: 宋体">子目录。在</span>META-INF<span style="FONT-FAMILY: 宋体">目录中建立一个</span>services.xml<span style="FONT-FAMILY: 宋体">文件，内容如下：<br /></span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">service </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="springService"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        Spring aware<br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">parameter </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="ServiceObjectSupplier"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier<br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">parameter</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">parameter </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="SpringBeanName"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        springService<br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">parameter</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceivers</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceiver </span><span style="COLOR: #ff0000">mep</span><span style="COLOR: #0000ff">="http://www.w3.org/2004/08/wsdl/in-out"</span><span style="COLOR: #ff0000"><br />            class</span><span style="COLOR: #0000ff">="org.apache.axis2.rpc.receivers.RPCMessageReceiver"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">messageReceivers</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">service</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">     <br /></span></div><p></p><p>    <span style="FONT-FAMILY: 宋体">在</span>Windows<span style="FONT-FAMILY: 宋体">控制台进入</span>axi2-spring-ws<span style="FONT-FAMILY: 宋体">目录，并使用</span>jar<span style="FONT-FAMILY: 宋体">命令将</span>axi2-spring-ws<span style="FONT-FAMILY: 宋体">目录中的内容打包成</span>axi2-spring-ws.aar<span style="FONT-FAMILY: 宋体">，然后将该文件复制到</span>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps\axis2\WEB-INF\services<span style="FONT-FAMILY: 宋体">目录中，启动</span>Tomcat<span style="FONT-FAMILY: 宋体">后，就可以访问该</span>WebService<span style="FONT-FAMILY: 宋体">了，访问方式与前面几篇文章的访问方式相同。获得</span>wsdl<span style="FONT-FAMILY: 宋体">内容的</span>URL<span style="FONT-FAMILY: 宋体">如下：<br /><br /><a href="http://localhost:8080/axis2/services/springService?wsdl">http://localhost:8080/axis2/services/springService?wsdl<br /></a></span><a href="http://localhost:8080/axis2/services/springService?wsdl"></a><br /><span style="FONT-FAMILY: 宋体">    在将</span>Spring<span style="FONT-FAMILY: 宋体">中的装配</span>JavaBean<span style="FONT-FAMILY: 宋体">发布成</span>WebService<span style="FONT-FAMILY: 宋体">需要注意以下几点：</span></p><p><span><span>    </span>1. </span><span style="FONT-FAMILY: 宋体">由</span>JavaBean<span style="FONT-FAMILY: 宋体">编译生成的</span>.class<span style="FONT-FAMILY: 宋体">文件需要放在</span>WEB-INF\classes<span style="FONT-FAMILY: 宋体">目录中，或打成</span>.jar<span style="FONT-FAMILY: 宋体">包后放在</span>WEB-INF\lib<span style="FONT-FAMILY: 宋体">目录中，而</span>WEB-INF\services<span style="FONT-FAMILY: 宋体">目录中的</span>.aar<span style="FONT-FAMILY: 宋体">包中不需要包含</span>.class<span style="FONT-FAMILY: 宋体">文件，而只需要包含一个</span>META-INF<span style="FONT-FAMILY: 宋体">目录，并在该目录中包含一个</span>services.xml<span style="FONT-FAMILY: 宋体">文件即可。</span></p><p><span><span>    </span>2. services.xml</span><span style="FONT-FAMILY: 宋体">的配置方法与前几篇文章的配置方法类似，只是并不需要使用</span>ServiceClass<span style="FONT-FAMILY: 宋体">参数指定要发布成</span>WebService<span style="FONT-FAMILY: 宋体">的</span>Java<span style="FONT-FAMILY: 宋体">类，而是要指定在</span>applicationContext.xml<span style="FONT-FAMILY: 宋体">文件中的装配</span>JavaBean<span style="FONT-FAMILY: 宋体">的名称（</span>SpringBeanName<span style="FONT-FAMILY: 宋体">参数）。</span></p><p><span><span>    </span>3. </span><span style="FONT-FAMILY: 宋体">在</span>services.xml<span style="FONT-FAMILY: 宋体">文件中需要通过</span>ServiceObjectSupplier<span style="FONT-FAMILY: 宋体">参数指定</span>SpringServletContextObjectSupplier<span style="FONT-FAMILY: 宋体">类来获得</span>Spring<span style="FONT-FAMILY: 宋体">的</span>ApplicationContext<span style="FONT-FAMILY: 宋体">对象。<br /></span></p><img src ="http://www.blogjava.net/libin2722/aggbug/296163.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2009-09-23 14:41 <a href="http://www.blogjava.net/libin2722/articles/296163.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>（转）WebService大讲堂之Axis2(5)：会话（Session）管理 </title><link>http://www.blogjava.net/libin2722/articles/296161.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Wed, 23 Sep 2009 06:40:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/296161.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/296161.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/296161.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/296161.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/296161.html</trackback:ping><description><![CDATA[
		<p style="TEXT-INDENT: 21.75pt">WebService<span style="FONT-FAMILY: 宋体">给人最直观的感觉就是由一个个方法组成，并在客户端通过</span>SOAP<span style="FONT-FAMILY: 宋体">协议调用这些方法。这些方法可能有返回值，也可能没有返回值。虽然这样可以完成一些工具，但这些被调用的方法是孤立的，当一个方法被调用后，在其他的方法中无法获得这个方法调用后的状态，也就是说无法保留状态。</span></p>
		<p style="TEXT-INDENT: 21.75pt">
				<span style="FONT-FAMILY: 宋体">读者可以想象，这对于一个完整的应用程序，无法保留状态，就意味着只依靠</span>WebService<span style="FONT-FAMILY: 宋体">很难完成全部的工作。例如，一个完整的应用系统都需要进行登录，这在</span>Web<span style="FONT-FAMILY: 宋体">应用中使用</span>Session<span style="FONT-FAMILY: 宋体">来保存用户登录状态，而如果用</span>WebService<span style="FONT-FAMILY: 宋体">的方法来进行登录处理，无法保存登录状态是非常令人尴尬的。当然，这也可以通过其他的方法来解决，如在服务端使用</span>static<span style="FONT-FAMILY: 宋体">变量来保存用户状态，并发送一个</span>id<span style="FONT-FAMILY: 宋体">到客户端，通过在服务端和客户端传递这个</span>id<span style="FONT-FAMILY: 宋体">来取得相应的用户状态。这非常类似于</span>Web<span style="FONT-FAMILY: 宋体">应用中通过</span>Session<span style="FONT-FAMILY: 宋体">和</span>Cookie<span style="FONT-FAMILY: 宋体">来管理用户状态。但这就需要由开发人员做很多工作，不过幸好</span>Axis2<span style="FONT-FAMILY: 宋体">为我们提供了</span>WebService<span style="FONT-FAMILY: 宋体">状态管理的功能。</span></p>
		<p style="TEXT-INDENT: 21.75pt">
				<span style="FONT-FAMILY: 宋体">使用</span>Axis2<span style="FONT-FAMILY: 宋体">来管理</span>WebService<span style="FONT-FAMILY: 宋体">的状态基本上对于开发人员是透明的。在</span>WebService<span style="FONT-FAMILY: 宋体">类需要使用</span>org.apache.axis2.context.MessageContext<span style="FONT-FAMILY: 宋体">和</span>org.apache.axis2.context.ServiceContext<span style="FONT-FAMILY: 宋体">类来保存与获得保存在服务端的状态信息，这有些象使用</span>HttpSession<span style="FONT-FAMILY: 宋体">接口的</span>getAttribute<span style="FONT-FAMILY: 宋体">和</span>setAttribute<span style="FONT-FAMILY: 宋体">方法获得与设置</span>Session<span style="FONT-FAMILY: 宋体">域属性。</span></p>
		<p style="TEXT-INDENT: 21.75pt">
				<span style="FONT-FAMILY: 宋体">除此之外，还需要修改</span>services.xml<span style="FONT-FAMILY: 宋体">文件的内容，为</span>&lt;service&gt;<span style="FONT-FAMILY: 宋体">元素加一个</span>scope<span style="FONT-FAMILY: 宋体">属性，该属性有四个可取的值：</span><span>Application, SOAPSession, TransportSession, Request</span><span style="FONT-FAMILY: 宋体">，不过要注意一下，虽然</span>Axis2<span style="FONT-FAMILY: 宋体">的官方文档将这四个值的单词首字母和缩写字母都写成了大写，但经笔者测试，必须全部小写才有效，也就是这四个值应为：</span>application<span style="FONT-FAMILY: 宋体">、</span>soapsession<span style="FONT-FAMILY: 宋体">、</span>transportsession<span style="FONT-FAMILY: 宋体">、</span>request<span style="FONT-FAMILY: 宋体">，其中</span>request<span style="FONT-FAMILY: 宋体">为</span>scope<span style="FONT-FAMILY: 宋体">属性的默认值。读者可以选择使用</span>transportsession<span style="FONT-FAMILY: 宋体">和</span>application<span style="FONT-FAMILY: 宋体">分别实现同一个</span>WebService<span style="FONT-FAMILY: 宋体">类和跨</span>WebService<span style="FONT-FAMILY: 宋体">类的会话管理。</span></p>
		<p style="TEXT-INDENT: 21.75pt">
				<span style="FONT-FAMILY: 宋体">在客户端需要使用</span>setManageSession(true)<span style="FONT-FAMILY: 宋体">打开</span>Session<span style="FONT-FAMILY: 宋体">管理功能。</span></p>
		<p style="TEXT-INDENT: 21.75pt">
				<span style="FONT-FAMILY: 宋体">综上所述，实现同一个</span>WebService<span style="FONT-FAMILY: 宋体">的</span>Session<span style="FONT-FAMILY: 宋体">管理需要如下三步：</span></p>
		<p style="TEXT-INDENT: 21.75pt">1. <span style="FONT-FAMILY: 宋体">使用</span>MessageContext<span style="FONT-FAMILY: 宋体">和</span><strong>ServiceContext</strong><span style="FONT-FAMILY: 宋体">获得与设置</span>key-value<span style="FONT-FAMILY: 宋体">对。</span></p>
		<p style="TEXT-INDENT: 21.75pt">2. <span style="FONT-FAMILY: 宋体">为要进行</span>Session<span style="FONT-FAMILY: 宋体">管理的</span>WebService<span style="FONT-FAMILY: 宋体">类所对应的</span>&lt;service&gt;<span style="FONT-FAMILY: 宋体">元素添加一个</span>scope<span style="FONT-FAMILY: 宋体">属性，并将该属性值设为</span><strong>transportsession</strong><span style="FONT-FAMILY: 宋体">。</span></p>
		<p style="TEXT-INDENT: 21.75pt">3. <span style="FONT-FAMILY: 宋体">在客户端使用</span>setManageSession(true)<span style="FONT-FAMILY: 宋体">打开</span>Session<span style="FONT-FAMILY: 宋体">管理功能。</span></p>
		<p style="TEXT-INDENT: 21.75pt">
				<span style="FONT-FAMILY: 宋体">下面是一个在同一个</span>WebService<span style="FONT-FAMILY: 宋体">类中管理</span>Session<span style="FONT-FAMILY: 宋体">的例子。</span><br /><br />先建立一个WebService类，代码如下：<br /></p>
		<span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Times New Roman'">
				<br />
		</span>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->
				<span style="COLOR: #0000ff">package</span>
				<span style="COLOR: #000000"> service;<br /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> org.apache.axis2.context.ServiceContext;<br /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> org.apache.axis2.context.MessageContext;<br /></span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> LoginService<br />{<br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">boolean</span>
				<span style="COLOR: #000000"> login(String username, String password)<br />    {<br />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">bill</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">.equals(username) </span>
				<span style="COLOR: #000000">&amp;&amp;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">1234</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">.equals(password))<br />        {<br />            </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">  第1步：设置key-value对</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">            MessageContext mc </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> MessageContext.getCurrentMessageContext();<br />            ServiceContext sc </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> mc.getServiceContext();<br />            sc.setProperty(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">login</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">成功登录</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);    <br />            </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">true</span>
				<span style="COLOR: #000000">;<br />        }<br />        </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000">
						<br />        {<br />            </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">false</span>
				<span style="COLOR: #000000">;<br />        }<br />    }<br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> String getLoginMsg()<br />    {<br />        </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">  第1步：获得key-value对中的value</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">        MessageContext mc </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> MessageContext.getCurrentMessageContext();<br />        ServiceContext sc </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> mc.getServiceContext();<br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> (String)sc.getProperty(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">login</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);    <br />    }<br />}<br /></span>
		</div>
		<meta content="Word.Document" name="ProgId" />
		<meta content="Microsoft Word 11" name="Generator" />
		<meta content="Microsoft Word 11" name="Originator" />
		<link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List" />
		<style>
				<!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
		</style>
		<p style="TEXT-INDENT: 21.75pt">
				<span style="FONT-FAMILY: 宋体">在</span>LoginService<span style="FONT-FAMILY: 宋体">类中有两个方法：</span>login<span style="FONT-FAMILY: 宋体">和</span>getLoginMsg<span style="FONT-FAMILY: 宋体">，如果</span>login<span style="FONT-FAMILY: 宋体">方法登录成功，会将“成功登录”字符串保存在</span>ServiceContext<span style="FONT-FAMILY: 宋体">对象中。如果在</span>login<span style="FONT-FAMILY: 宋体">方法返回</span>true<span style="FONT-FAMILY: 宋体">后调用</span>getLoginMsg<span style="FONT-FAMILY: 宋体">方法，就会返回“成功登录”。</span></p>
		<p style="TEXT-INDENT: 21.75pt">
				<span style="FONT-FAMILY: 宋体">下面是</span>LoginService<span style="FONT-FAMILY: 宋体">类的配置代码（</span>services.xml<span style="FONT-FAMILY: 宋体">）：<br /></span></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->
				<span style="COLOR: #008000">&lt;!--</span>
				<span style="COLOR: #008000">  第2步：添加scope属性  </span>
				<span style="COLOR: #008000">--&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">service </span>
				<span style="COLOR: #ff0000">name</span>
				<span style="COLOR: #0000ff">="loginService"</span>
				<span style="COLOR: #ff0000"> scope</span>
				<span style="COLOR: #0000ff">="transportsession"</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />    </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">description</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />        登录服务<br />        </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">description</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />    </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">parameter </span>
				<span style="COLOR: #ff0000">name</span>
				<span style="COLOR: #0000ff">="ServiceClass"</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />        service.LoginService<br />        </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">parameter</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />    </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">messageReceivers</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">messageReceiver </span>
				<span style="COLOR: #ff0000">mep</span>
				<span style="COLOR: #0000ff">="http://www.w3.org/2004/08/wsdl/in-out"</span>
				<span style="COLOR: #ff0000">
						<br />            class</span>
				<span style="COLOR: #0000ff">="org.apache.axis2.rpc.receivers.RPCMessageReceiver"</span>
				<span style="COLOR: #ff0000"> </span>
				<span style="COLOR: #0000ff">/&gt;</span>
				<span style="COLOR: #000000">
						<br />    </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">messageReceivers</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">service</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
		</div>
		<p style="TEXT-INDENT: 21.75pt">
		</p>
		<meta content="Word.Document" name="ProgId" />
		<meta content="Microsoft Word 11" name="Generator" />
		<meta content="Microsoft Word 11" name="Originator" />
		<link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List" />
		<style>
				<!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
		</style>
		<p style="TEXT-INDENT: 21.75pt">
				<span style="FONT-FAMILY: 宋体">使用如下的命令生成客户端使用的</span>stub<span style="FONT-FAMILY: 宋体">类：<br /></span></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->
				<span style="COLOR: #000000">%AXIS2_HOME%\bin\wsdl2java -uri http://localhost:</span>
				<span style="COLOR: #000000">8080</span>
				<span style="COLOR: #000000">/axis2/services/loginService?wsdl -p client -s -o stub</span>
		</div>
		<p style="TEXT-INDENT: 21.75pt">
		</p>
		<meta content="Word.Document" name="ProgId" />
		<meta content="Microsoft Word 11" name="Generator" />
		<meta content="Microsoft Word 11" name="Originator" />
		<link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List" />
		<style>
				<!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
		</style>
		<p style="TEXT-INDENT: 21.75pt">
				<span style="FONT-FAMILY: 宋体">在</span>stub\src\client<span style="FONT-FAMILY: 宋体">目录中生成了一个</span>LoginServiceStub.java<span style="FONT-FAMILY: 宋体">类，在该类中找到如下的构造句方法：<br /></span></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> LoginServiceStub(org.apache.axis2.context.ConfigurationContext configurationContext,<br />        java.lang.String targetEndpoint, </span>
				<span style="COLOR: #0000ff">boolean</span>
				<span style="COLOR: #000000"> useSeparateListener)<br />        </span>
				<span style="COLOR: #0000ff">throws</span>
				<span style="COLOR: #000000"> org.apache.axis2.AxisFault <br />{<br />    <img alt="" src="http://www.blogjava.net/images/dot.gif" /> <img alt="" src="http://www.blogjava.net/images/dot.gif" /><br />    _serviceClient.getOptions().setSoapVersionURI(<br />                                 org.apache.axiom.soap.SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);<br />}<br /></span>
		</div>
		<p style="TEXT-INDENT: 21.75pt">
		</p>
		<p style="TEXT-INDENT: 21.75pt">
		</p>
		<meta content="Word.Document" name="ProgId" />
		<meta content="Microsoft Word 11" name="Generator" />
		<meta content="Microsoft Word 11" name="Originator" />
		<style>
				<!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
		</style>
		<span style="FONT-FAMILY: 宋体">在该方法中最后添加如下的代码：<br /></span>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">  第3步：打开客户端的Session管理功能</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">_serviceClient.getOptions().setManageSession(</span>
				<span style="COLOR: #0000ff">true</span>
				<span style="COLOR: #000000">);</span>
		</div>
		<meta content="Word.Document" name="ProgId" />
		<meta content="Microsoft Word 11" name="Generator" />
		<meta content="Microsoft Word 11" name="Originator" />
		<link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List" />
		<style>
				<!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
		</style>
		<p style="TEXT-INDENT: 21.75pt">
				<span style="FONT-FAMILY: 宋体">下面的客户端代码使用</span>LoginServiceStub<span style="FONT-FAMILY: 宋体">对象访问了刚才建立的</span>WebService<span style="FONT-FAMILY: 宋体">：<br /></span></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->
				<span style="COLOR: #000000">LoginServiceStub stub </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> LoginServiceStub();<br />LoginServiceStub.Login login </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> LoginServiceStub.Login();<br />login.setUsername(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">bill</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />login.setPassword(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">1234</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br /></span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">(stub.login(login).local_return)<br />{<br />    System.out.println(stub.getLoginMsg().local_return);<br />}<br /></span>
		</div>
		<p style="TEXT-INDENT: 21.75pt">
		</p>
		<meta content="Word.Document" name="ProgId" />
		<meta content="Microsoft Word 11" name="Generator" />
		<meta content="Microsoft Word 11" name="Originator" />
		<link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List" />
		<style>
				<!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
		</style>
		<p style="TEXT-INDENT: 21.75pt">
				<span style="FONT-FAMILY: 宋体">运行上面的代码后，会输出“成功登录”信息。<br /></span>
		</p>
<img src ="http://www.blogjava.net/libin2722/aggbug/296161.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2009-09-23 14:40 <a href="http://www.blogjava.net/libin2722/articles/296161.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>（转）WebService大讲堂之Axis2(6)：跨服务会话(Session)管理 </title><link>http://www.blogjava.net/libin2722/articles/296162.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Wed, 23 Sep 2009 06:40:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/296162.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/296162.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/296162.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/296162.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/296162.html</trackback:ping><description><![CDATA[
		<p style="TEXT-INDENT: 21.75pt">
				<span style="FONT-FAMILY: 宋体">在</span>
				<a id="homepage1_HomePageDays_DaysList_ctl05_DayItem_DayList_ctl00_TitleUrl" href="/nokiaguy/archive/2009/04/archive/2009/nokiaguy/archive/2009/nokiaguy/archive/2009/nokiaguy/archive/2009/01/26/252564.html">《WebService大讲堂之Axis2(5)：会话（Session）管理》</a>
				<span style="FONT-FAMILY: 宋体">一文中介绍了如何使用</span>Axis2<span style="FONT-FAMILY: 宋体">来管理同一个服务的会话，但对于一个复杂的系统，不可能只有一个</span>WebService<span style="FONT-FAMILY: 宋体">服务，例如，至少会有一个管理用户的</span>WebService<span style="FONT-FAMILY: 宋体">（用户登录和注册）以及处理业务的</span>WebService<span style="FONT-FAMILY: 宋体">。象这种情况，就必须在多个</span>WebService<span style="FONT-FAMILY: 宋体">服务之间共享会话状态，也称为跨服务会话</span>(Session)<span style="FONT-FAMILY: 宋体">管理。实现跨服务会话管理与实现同一个服务的会话管理的步骤类似，但仍然有一些差别，实现跨服务会话管理的步骤如下：</span></p>
		<p style="TEXT-INDENT: 21.75pt">
				<span style="FONT-FAMILY: 宋体">实现跨服务的</span>Session<span style="FONT-FAMILY: 宋体">管理需要如下三步：</span></p>
		<p style="TEXT-INDENT: 21.75pt">1. <span style="FONT-FAMILY: 宋体">使用</span>MessageContext<span style="FONT-FAMILY: 宋体">和</span><strong>ServiceGroupContext</strong><span style="FONT-FAMILY: 宋体">获得与设置</span>key-value<span style="FONT-FAMILY: 宋体">对。</span></p>
		<p style="TEXT-INDENT: 21.75pt">2. <span style="FONT-FAMILY: 宋体">为要进行</span>Session<span style="FONT-FAMILY: 宋体">管理的</span>WebService<span style="FONT-FAMILY: 宋体">类所对应的</span>&lt;service&gt;<span style="FONT-FAMILY: 宋体">元素添加一个</span>scope<span style="FONT-FAMILY: 宋体">属性，并将该属性值设为</span><strong>application</strong><span style="FONT-FAMILY: 宋体">。</span></p>
		<p style="TEXT-INDENT: 21.75pt">3. <span style="FONT-FAMILY: 宋体">在客户端使用</span>setManageSession(true)<span style="FONT-FAMILY: 宋体">打开</span>Session<span style="FONT-FAMILY: 宋体">管理功能。</span></p>
		<p style="TEXT-INDENT: 21.75pt">
				<span style="FONT-FAMILY: 宋体">从上面的步骤可以看出，实现跨服务会话管理与实现同一个服务的会话管理在前两步上存在着差异，而第</span>3<span style="FONT-FAMILY: 宋体">步是完全一样的。下面是一个跨服务的会话管理的实例。在这个例子中有两个</span>WebService<span style="FONT-FAMILY: 宋体">类：</span>LoginService<span style="FONT-FAMILY: 宋体">和</span>SearchService<span style="FONT-FAMILY: 宋体">，代码如下：<strong><br /><br />LoginService.java</strong><br /></span></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #0000ff">package</span>
				<span style="COLOR: #000000"> service;<br /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> org.apache.axis2.context.MessageContext;<br /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> org.apache.axis2.context.ServiceGroupContext;<br /></span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> LoginService<br />{<br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">boolean</span>
				<span style="COLOR: #000000"> login(String username, String password)<br />    {        <br />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">bill</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">.equals(username) </span>
				<span style="COLOR: #000000">&amp;&amp;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">1234</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">.equals(password))<br />        {<br />            </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">  第1步：设置key-value对</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">            MessageContext mc </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> MessageContext.getCurrentMessageContext();<br />            ServiceGroupContext sgc </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> mc.getServiceGroupContext();<br />            sgc.setProperty(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">login</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">成功登录</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);    <br />            </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">true</span>
				<span style="COLOR: #000000">;<br />        }<br />        </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000">
						<br />        {<br />            </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">false</span>
				<span style="COLOR: #000000">;<br />        }<br />    }    <br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> String getLoginMsg()<br />    {<br />       </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">  第1步：获得key-value对中的value</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">        MessageContext mc </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> MessageContext.getCurrentMessageContext();<br />        ServiceGroupContext sgc </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">  mc.getServiceGroupContext();<br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> (String)sgc.getProperty(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">login</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);    <br />    }<br />}<br /></span>
		</div>
		<p>
				<br />
				<strong>SearchService.java</strong>
				<br />
		</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->
				<span style="COLOR: #0000ff">package</span>
				<span style="COLOR: #000000"> service;<br /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> org.apache.axis2.context.MessageContext;<br /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> org.apache.axis2.context.ServiceGroupContext;<br /></span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> SearchService<br />{<br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> String findByName(String name)<br />    {<br />        </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">  第1步：获得key-value对中的value</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">        MessageContext mc </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> MessageContext.getCurrentMessageContext();<br />        ServiceGroupContext sgc </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">  mc.getServiceGroupContext();                <br />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000"> (sgc.getProperty(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">login</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">) </span>
				<span style="COLOR: #000000">!=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">null</span>
				<span style="COLOR: #000000">)<br />            </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">找到的数据&lt;</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> name </span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">;<br />        </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000">
						<br />            </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">用户未登录</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">;<br />    }<br />}<br /></span>
		</div>
		<meta content="Word.Document" name="ProgId" />
		<meta content="Microsoft Word 11" name="Generator" />
		<meta content="Microsoft Word 11" name="Originator" />
		<link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List" />
		<style>
				<!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
		</style>
		<p style="TEXT-INDENT: 21.75pt">services.xml<span style="FONT-FAMILY: 宋体">文件中的配置代码如下：<br /></span></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">serviceGroup</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />    </span>
				<span style="COLOR: #008000">&lt;!--</span>
				<span style="COLOR: #008000">  第2步：添加scope属性，并设置属性值为application </span>
				<span style="COLOR: #008000">--&gt;</span>
				<span style="COLOR: #000000">
						<br />    </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">service </span>
				<span style="COLOR: #ff0000">name</span>
				<span style="COLOR: #0000ff">="loginService"</span>
				<span style="COLOR: #ff0000"> scope</span>
				<span style="COLOR: #0000ff">="application"</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">description</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />            登录服务<br />        </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">description</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">parameter </span>
				<span style="COLOR: #ff0000">name</span>
				<span style="COLOR: #0000ff">="ServiceClass"</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />            service.LoginService<br />        </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">parameter</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">messageReceivers</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />            </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">messageReceiver </span>
				<span style="COLOR: #ff0000">mep</span>
				<span style="COLOR: #0000ff">="http://www.w3.org/2004/08/wsdl/in-out"</span>
				<span style="COLOR: #ff0000">
						<br />                class</span>
				<span style="COLOR: #0000ff">="org.apache.axis2.rpc.receivers.RPCMessageReceiver"</span>
				<span style="COLOR: #ff0000"> </span>
				<span style="COLOR: #0000ff">/&gt;</span>
				<span style="COLOR: #000000">
						<br />        </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">messageReceivers</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />    </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">service</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />    </span>
				<span style="COLOR: #008000">&lt;!--</span>
				<span style="COLOR: #008000">  第2步：添加scope属性，并设置属性值为application </span>
				<span style="COLOR: #008000">--&gt;</span>
				<span style="COLOR: #000000">
						<br />    </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">service </span>
				<span style="COLOR: #ff0000">name</span>
				<span style="COLOR: #0000ff">="searchService"</span>
				<span style="COLOR: #ff0000"> scope</span>
				<span style="COLOR: #0000ff">="application"</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">description</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />            搜索服务<br />        </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">description</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">parameter </span>
				<span style="COLOR: #ff0000">name</span>
				<span style="COLOR: #0000ff">="ServiceClass"</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />            service.SearchService<br />        </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">parameter</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">messageReceivers</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />            </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">messageReceiver </span>
				<span style="COLOR: #ff0000">mep</span>
				<span style="COLOR: #0000ff">="http://www.w3.org/2004/08/wsdl/in-out"</span>
				<span style="COLOR: #ff0000">
						<br />                class</span>
				<span style="COLOR: #0000ff">="org.apache.axis2.rpc.receivers.RPCMessageReceiver"</span>
				<span style="COLOR: #ff0000"> </span>
				<span style="COLOR: #0000ff">/&gt;</span>
				<span style="COLOR: #000000">
						<br />        </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">messageReceivers</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />    </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">service</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">serviceGroup</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
		</div>
		<p style="TEXT-INDENT: 21.75pt">
				<br />
		</p>
		<meta content="Word.Document" name="ProgId" />
		<meta content="Microsoft Word 11" name="Generator" />
		<meta content="Microsoft Word 11" name="Originator" />
		<link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List" />
		<style>
				<!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
		</style>
		<p style="TEXT-INDENT: 21.75pt">
				<span style="FONT-FAMILY: 宋体">第</span>3<span style="FONT-FAMILY: 宋体">步与</span><a id="homepage1_HomePageDays_DaysList_ctl05_DayItem_DayList_ctl00_TitleUrl" href="/nokiaguy/archive/2009/04/archive/2009/nokiaguy/archive/2009/nokiaguy/archive/2009/nokiaguy/archive/2009/01/26/252564.html">《WebService大讲堂之Axis2(5)：会话（Session）管理》</a>一文中<span style="FONT-FAMILY: 宋体">介绍的方法类似。<br /></span></p>
		<meta content="Word.Document" name="ProgId" />
		<meta content="Microsoft Word 11" name="Generator" />
		<meta content="Microsoft Word 11" name="Originator" />
		<link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List" />
		<style>
				<!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
		</style>
		<p style="TEXT-INDENT: 21.75pt">
				<span style="FONT-FAMILY: 宋体">下面是使用两个</span>stub<span style="FONT-FAMILY: 宋体">类的对象实例访问上面实现的两个</span>WebService<span style="FONT-FAMILY: 宋体">的客户端代码：<br /></span></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->
				<span style="COLOR: #000000">LoginServiceStub stub </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> LoginServiceStub();<br />LoginServiceStub.Login login </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> LoginServiceStub.Login();<br />login.setUsername(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">bill</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />login.setPassword(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">1234</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br /></span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">(stub.login(login).local_return)<br />{<br />    System.out.println(stub.getLoginMsg().local_return);<br />    SearchServiceStub searchStub </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> SearchServiceStub();<br />    SearchServiceStub.FindByName fbn </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> SearchServiceStub.FindByName();<br />    fbn.setName(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">abc</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />    System.out.println(searchStub.findByName(fbn).local_return); <br />}<br /></span>
		</div>
		<p style="TEXT-INDENT: 21.75pt">
		</p>
		<p style="TEXT-INDENT: 21.75pt">
		</p>
		<meta content="Word.Document" name="ProgId" />
		<meta content="Microsoft Word 11" name="Generator" />
		<meta content="Microsoft Word 11" name="Originator" />
		<link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C03%5Cclip_filelist.xml" rel="File-List" />
		<style>
				<!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
		</style>
		<p style="TEXT-INDENT: 21.75pt">
				<span style="FONT-FAMILY: 宋体">在执行上面的代码后，将输出如下的信息：</span>
				<br />
		</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->
				<span style="COLOR: #000000">成功登录<br /><br />找到的数据</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">abc</span>
				<span style="COLOR: #000000">&gt;</span>
				<br />
		</div>
		<p style="TEXT-INDENT: 21.75pt">
		</p>
		<p style="TEXT-INDENT: 21.75pt">读者可以将scope属性值改成transportsession，看看会输出什么！<br /><br />    实际上，Axis2的会话管理也是通过Cookie实现的，与Web应用中的Session管理类似。如果读者使用C#访问支持会话（在同一个服务中的会话管理）的WebService，需要指定一个CookieContainer对象，代码如下：<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->
				<span style="COLOR: #000000">service.loginService ls </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> service.loginService();<br />System.Net.CookieContainer cc </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> System.Net.CookieContainer();<br />ls.CookieContainer </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> cc;<br /></span>
				<span style="COLOR: #0000ff">bool</span>
				<span style="COLOR: #000000"> r, rs;<br />ls.login(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">bill</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">1234</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #0000ff">out</span>
				<span style="COLOR: #000000"> @r, </span>
				<span style="COLOR: #0000ff">out</span>
				<span style="COLOR: #000000"> rs);<br /></span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000"> (r)<br />{<br />    MessageBox.Show(ls.getLoginMsg().@return);<br />}<br /></span>
		</div>
		<p style="TEXT-INDENT: 21.75pt">
		</p>
		<p style="TEXT-INDENT: 21.75pt">
		</p>
		<p style="TEXT-INDENT: 21.75pt">
		</p>
		<meta content="Word.Document" name="ProgId" />
		<meta content="Microsoft Word 11" name="Generator" />
		<meta content="Microsoft Word 11" name="Originator" />
		<style>
				<!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
		</style>
		<span style="FONT-FAMILY: 宋体">如果是访问跨服务的支持会话的</span>WebService<span style="FONT-FAMILY: 宋体">，则不需要指定</span>CookieContainer<span style="FONT-FAMILY: 宋体">对象，代码如下：<br /><br /></span><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #000000">service.loginService ls </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> service.loginService();<br /></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000"> r, rs;<br />ls.login(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">bill</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">1234</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #0000ff">out</span><span style="COLOR: #000000"> @r, </span><span style="COLOR: #0000ff">out</span><span style="COLOR: #000000"> rs);<br /></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (r)<br />{<br />    service1.searchService ss </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> service1.searchService();<br />    MessageBox.Show(ss.findByName(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">abc</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br />}<br /></span></div><p style="TEXT-INDENT: 21.75pt"></p><meta content="Word.Document" name="ProgId" /><meta content="Microsoft Word 11" name="Generator" /><meta content="Microsoft Word 11" name="Originator" /><link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C08%5Cclip_filelist.xml" rel="File-List" /><style><!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
--></style><p style="TEXT-INDENT: 21.75pt"><span style="FONT-FAMILY: 宋体">如果读者使用</span>delphi<span style="FONT-FAMILY: 宋体">（本文使用的是</span>delphi2009<span style="FONT-FAMILY: 宋体">，其他的</span>delphi<span style="FONT-FAMILY: 宋体">版本请读者自行测试）调用支持会话的</span>WebService<span style="FONT-FAMILY: 宋体">时有一些差别。经笔者测试，使用</span>delphi<span style="FONT-FAMILY: 宋体">调用</span>WebService<span style="FONT-FAMILY: 宋体">，将</span>scope<span style="FONT-FAMILY: 宋体">属性值设为</span>transportsession<span style="FONT-FAMILY: 宋体">和</span>application<span style="FONT-FAMILY: 宋体">都可以实现跨服务的会话管理，这一点和</span>Java<span style="FONT-FAMILY: 宋体">与</span>C#<span style="FONT-FAMILY: 宋体">不同，</span>Java<span style="FONT-FAMILY: 宋体">和</span>C#<span style="FONT-FAMILY: 宋体">必须将</span>scope<span style="FONT-FAMILY: 宋体">属性值设为</span>application<span style="FONT-FAMILY: 宋体">才支持跨服务会话管理。在</span>delphi<span style="FONT-FAMILY: 宋体">中不需要象</span>C#<span style="FONT-FAMILY: 宋体">指定一个</span>CookieContainer<span style="FONT-FAMILY: 宋体">或其他类似的对象，而只需要象访问普通的</span>WebService<span style="FONT-FAMILY: 宋体">一样访问支持会话的</span>WebService<span style="FONT-FAMILY: 宋体">即可。<br /><br /></span></p><img src ="http://www.blogjava.net/libin2722/aggbug/296162.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2009-09-23 14:40 <a href="http://www.blogjava.net/libin2722/articles/296162.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>（转）WebService大讲堂之Axis2(4)：二进制文件传输 </title><link>http://www.blogjava.net/libin2722/articles/296160.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Wed, 23 Sep 2009 06:39:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/296160.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/296160.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/296160.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/296160.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/296160.html</trackback:ping><description><![CDATA[在《<a id="viewpost1_TitleUrl" href="/nokiaguy/archive/2009/04/archive/2009/nokiaguy/archive/2009/nokiaguy/archive/2009/01/archive/2009/01/04/249805.html">WebService大讲堂之Axis2（2）：复合类型数据的传递</a><span style="FONT-FAMILY: 宋体">》中讲过，如果要传递二进制文件（如图像、音频文件等），可以使用</span>byte[]<span style="FONT-FAMILY: 宋体">作为数据类型进行传递，然后客户端使用</span>RPC<span style="FONT-FAMILY: 宋体">方式进行调用。这样做只是其中的一种方法，除此之外，在客户端还可以使用</span>wsdl2java<span style="FONT-FAMILY: 宋体">命令生成相应的</span>stub<span style="FONT-FAMILY: 宋体">类来调用</span>WebService<span style="FONT-FAMILY: 宋体">，</span>wsdl2java<span style="FONT-FAMILY: 宋体">命令的用法详见《</span><a id="viewpost1_TitleUrl" href="/nokiaguy/archive/2009/04/archive/2009/nokiaguy/archive/2009/nokiaguy/archive/2009/01/archive/2009/01/02/249556.html">WebService大讲堂之Axis2（1）：用POJO实现0配置的WebService</a><span style="FONT-FAMILY: 宋体">》。</span><br />    WebService<span style="FONT-FAMILY: 宋体">类中包含</span>byte[]<span style="FONT-FAMILY: 宋体">类型参数的方法在</span>wsdl2java<span style="FONT-FAMILY: 宋体">生成的</span>stub<span style="FONT-FAMILY: 宋体">类中对应的数据类型不再是</span>byte[]<span style="FONT-FAMILY: 宋体">类型，而是</span>javax.activation.DataHandler<span style="FONT-FAMILY: 宋体">。</span>DataHandler<span style="FONT-FAMILY: 宋体">类是专门用来映射</span>WebService<span style="FONT-FAMILY: 宋体">二进制类型的。<br />    在</span>WebService<span style="FONT-FAMILY: 宋体">类中除了可以使用</span>byte[]<span style="FONT-FAMILY: 宋体">作为传输二进制的数据类型外，也可以使用</span>javax.activation.DataHandler<span style="FONT-FAMILY: 宋体">作为数据类型。</span><span style="FONT-FAMILY: 宋体">不管是使用</span>byte[]<span style="FONT-FAMILY: 宋体">，还是使用</span>javax.activation.DataHandler<span style="FONT-FAMILY: 宋体">作为</span>WebService<span style="FONT-FAMILY: 宋体">方法的数据类型，使用</span>wsdl2java<span style="FONT-FAMILY: 宋体">命令生成的</span>stub<span style="FONT-FAMILY: 宋体">类中相应方法的类型都是</span>javax.activation.DataHandler<span style="FONT-FAMILY: 宋体">。而象使用</span>.net<span style="FONT-FAMILY: 宋体">、</span>delphi<span style="FONT-FAMILY: 宋体">生成的</span>stub<span style="FONT-FAMILY: 宋体">类的相应方法类型都是</span>byte[]<span style="FONT-FAMILY: 宋体">。这是由于</span>javax.activation.DataHandler<span style="FONT-FAMILY: 宋体">类是</span>Java<span style="FONT-FAMILY: 宋体">特有的，对于其他语言和技术来说，并不认识</span>javax.activation.DataHandler<span style="FONT-FAMILY: 宋体">类，因此，也只有使用最原始的</span>byte[]<span style="FONT-FAMILY: 宋体">了。<br />    下面是一个上传二进制文件的例子，</span>WebService<span style="FONT-FAMILY: 宋体">类的代码如下：<br /><br /></span><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> service;<br /><br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> java.io.InputStream;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> java.io.OutputStream;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> java.io.FileOutputStream;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> javax.activation.DataHandler;<br /><br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> FileService<br />{<br />   </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  使用byte[]类型参数上传二进制文件</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">boolean</span><span style="COLOR: #000000"> uploadWithByte(</span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[] file, String filename)<br />    {<br />         FileOutputStream fos </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">;<br />         </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"><br />         {                          <br />             fos </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> FileOutputStream(filename);    <br />             fos.write(file);<br />             fos.close();<br />         }<br />         </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (Exception e)<br />         {<br />             </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br />         }<br />         </span><span style="COLOR: #0000ff">finally</span><span style="COLOR: #000000"><br />         {<br />             </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (fos </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">)<br />             {<br />                 </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"><br />                 {<br />                     fos.close();<br />                 }<br />                 </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (Exception e)<br />                 {<br />                 }<br />             }<br />         }<br />         </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br />    }<br />    </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> writeInputStreamToFile(InputStream is, OutputStream os) </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception<br />    {<br />         </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> n </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br />         </span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[] buffer </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">8192</span><span style="COLOR: #000000">];<br />         </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">((n </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> is.read(buffer)) </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br />         {<br />             os.write(buffer, </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">, n);<br />         }<br />    }<br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  使用DataHandler类型参数上传文件</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">boolean</span><span style="COLOR: #000000"> uploadWithDataHandler(DataHandler file, String filename)<br />    {<br />        <br />         FileOutputStream fos </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">;<br />         </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"><br />         {            <br />             fos </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> FileOutputStream(filename);   <br />             </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  可通过DataHandler类的getInputStream方法读取上传数据</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">             writeInputStreamToFile(file.getInputStream(), fos);<br />             fos.close();<br />         }<br />         </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (Exception e)<br />         {<br />             </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br />         }<br />         </span><span style="COLOR: #0000ff">finally</span><span style="COLOR: #000000"><br />         {<br />             </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (fos </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">)<br />             {<br />                 </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"><br />                 {<br />                     fos.close();<br />                 }<br />                 </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (Exception e)<br />                 {<br />                 }<br />             }<br />         }<br />         </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br />    }<br />}<br /></span></div><p style="TEXT-INDENT: 21pt"></p><p style="TEXT-INDENT: 21pt"><span style="FONT-FAMILY: 宋体">上面代码在</span>services.xml<span style="FONT-FAMILY: 宋体">文件的配置代码如下：<br /></span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">service </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="fileService"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        文件服务<br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">parameter </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="ServiceClass"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        service.FileService <br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">parameter</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceivers</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceiver </span><span style="COLOR: #ff0000">mep</span><span style="COLOR: #0000ff">="http://www.w3.org/2004/08/wsdl/in-out"</span><span style="COLOR: #ff0000"><br />            class</span><span style="COLOR: #0000ff">="org.apache.axis2.rpc.receivers.RPCMessageReceiver"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">messageReceivers</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">service</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span></div><p style="TEXT-INDENT: 21pt"><span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体"><br />    如果使用</span><span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Times New Roman'">wsdl2java</span><span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体">命令生成调用</span><span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Times New Roman'">Java</span><span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体">客户端代码，则需要创建</span><span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Times New Roman'">DataHandler</span><span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体">类的对象实例，代码如下：<br /><br /></span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #000000">DataHandler dh </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> DataHandler(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> FileDataSource(imagePath));</span></div><p style="TEXT-INDENT: 21pt"></p><p style="TEXT-INDENT: 21pt">wsdl2java<span style="FONT-FAMILY: 宋体">命令会为每一个方法生成一个封装方法参数的类，类名为方法名（第一个字符大写），如</span>uploadWithByte<span style="FONT-FAMILY: 宋体">方法生成的类名为</span>UploadWithByte<span style="FONT-FAMILY: 宋体">。如果要设置</span>file<span style="FONT-FAMILY: 宋体">参数的值，可以使用</span>UploadWithByte<span style="FONT-FAMILY: 宋体">类的</span>setFile<span style="FONT-FAMILY: 宋体">方法，代码如下：</span></p><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #000000">UploadWithByte uwb </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> UPloadWithByte();<br />uwb.setFile(dh);<br /></span></div><br /><p style="TEXT-INDENT: 21pt"><span style="FONT-FAMILY: 宋体">最后是调用</span>uploadWithByte<span style="FONT-FAMILY: 宋体">方法，代码如下（</span>FileServiceStub<span style="FONT-FAMILY: 宋体">为</span>wsdl2java<span style="FONT-FAMILY: 宋体">生成的</span>stub<span style="FONT-FAMILY: 宋体">类名）：</span></p><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #000000">FileServiceStub fss </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> FileServiceStub();<br />fss.uploadWithByte(uwb);<br /></span></div><p style="TEXT-INDENT: 21pt"></p><p style="TEXT-INDENT: 21pt"><span style="FONT-FAMILY: 宋体">如果使用</span>C#<span style="FONT-FAMILY: 宋体">调用</span>FileService<span style="FONT-FAMILY: 宋体">，则</span>file<span style="FONT-FAMILY: 宋体">参数类型均为</span>byte[]<span style="FONT-FAMILY: 宋体">，代码如下：</span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #000000">MemoryStream ms </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> MemoryStream();<br />Bitmap bitmap </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Bitmap(picUpdateImage.Image);<br />bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);<br />service.fileService fs </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> WSC.service.fileService();<br />fs.uploadWithDataHandler(ms.ToArray());<br />fs.uploadWithByte(ms.ToArray());</span> </div><p style="TEXT-INDENT: 21pt"><span style="FONT-FAMILY: 宋体">其中</span>picUpdateImage<span style="FONT-FAMILY: 宋体">为</span>c#<span style="FONT-FAMILY: 宋体">中加载图像文件的</span>picturebox<span style="FONT-FAMILY: 宋体">控件。<br /></span></p><img src ="http://www.blogjava.net/libin2722/aggbug/296160.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2009-09-23 14:39 <a href="http://www.blogjava.net/libin2722/articles/296160.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>（转）WebService大讲堂之Axis2（2）：复合类型数据的传递 </title><link>http://www.blogjava.net/libin2722/articles/296158.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Wed, 23 Sep 2009 06:38:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/296158.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/296158.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/296158.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/296158.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/296158.html</trackback:ping><description><![CDATA[
		<span style="FONT-FAMILY: 宋体">在实际的应用中，不仅需要使用</span>WebService<span style="FONT-FAMILY: 宋体">来传递简单类型的数据，有时也需要传递更复杂的数据，这些数据可以被称为复合类型的数据。数组与类（接口）是比较常用的复合类型。在</span>Axis2<span style="FONT-FAMILY: 宋体">中可以直接使用将</span>WebService<span style="FONT-FAMILY: 宋体">方法的参数或返回值类型声明成数组或类（接口）。但要注意，在定义数组类型时只能使用一维数组，如果想传递多维数组，可以使用分隔符进行分隔，如下面的代码所示：</span><p>String[] strArray = new String[]<span>{ "</span><span style="FONT-FAMILY: 宋体">自行车</span>,<span style="FONT-FAMILY: 宋体">飞机</span>,<span style="FONT-FAMILY: 宋体">火箭</span>","<span style="FONT-FAMILY: 宋体">中国</span>,<span style="FONT-FAMILY: 宋体">美国</span>,<span style="FONT-FAMILY: 宋体">德国</span>", "<span style="FONT-FAMILY: 宋体">超人</span>,<span style="FONT-FAMILY: 宋体">蜘蛛侠</span>,<span style="FONT-FAMILY: 宋体">钢铁侠</span>" } ;</p><p>    <span style="FONT-FAMILY: 宋体">上面的代码可以看作是一个</span>3*3<span style="FONT-FAMILY: 宋体">的二维数组。</span></p><p>    <span style="FONT-FAMILY: 宋体">在传递类的对象实例时，除了直接将数组类型声明成相应的类或接口，也可以将对象实例进行序列化，也就是说，将一个对象实例转换成字节数组进行传递，然后接收方再进行反序列化，还原这个对象实例。</span></p><p>    <span style="FONT-FAMILY: 宋体">下面的示例代码演示了如何传递数组与类（接口）类型的数据，并演示如何使用字节数组上传图像。本示例的客户端代码使用</span>Java<span style="FONT-FAMILY: 宋体">和</span>C#<span style="FONT-FAMILY: 宋体">编写。要完成这个例子需要如下几步：</span><span><br /><br /></span></p><p><strong><span style="FONT-FAMILY: 宋体">一、实现服务端代码<br /><br /></span></strong></p><meta content="Word.Document" name="ProgId" /><meta content="Microsoft Word 11" name="Generator" /><meta content="Microsoft Word 11" name="Originator" /><link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List" /><style><!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
--></style><p>    ComplexTypeService<span style="FONT-FAMILY: 宋体">是一个</span>WebService<span style="FONT-FAMILY: 宋体">类，该类的代码如下：<br /></span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> java.io.FileOutputStream;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> data.DataForm;<br /><br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> ComplexTypeService<br />{<br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  上传图像，imageByte参数表示上传图像文件的字节，<br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  length参数表示图像文件的字节长度（该参数值可能小于imageByte的数组长度）</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">boolean</span><span style="COLOR: #000000"> uploadImageWithByte(</span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[] imageByte, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> length)<br />    {<br />        FileOutputStream fos </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">;<br />        </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"><br />        {<br />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  将上传的图像保存在D盘的test1.jpg文件中</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">            fos </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> FileOutputStream(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">d:\\test1.jpg</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  开始写入图像文件的字节</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">            fos.write(imageByte, </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">, length);<br />            fos.close();<br />        }<br />        </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (Exception e)<br />        {<br />            </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br />        }<br />        </span><span style="COLOR: #0000ff">finally</span><span style="COLOR: #000000"><br />        {<br />            </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (fos </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">)<br />            {<br />                </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"><br />                {<br />                    fos.close();<br />                }<br />                </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (Exception e)<br />                {<br /><br />                }<br />            }<br />        }<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br />    }<br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  返回一维字符串数组</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> String[] getArray()<br />    {<br />        String[] strArray </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> String[]{ </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">自行车</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">飞机</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">火箭</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> };<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> strArray;<br />    } <br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  返回二维字符串数组</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> String[] getMDArray()<br />    {<br />        String[] strArray </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> String[]{ </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">自行车,飞机,火箭</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">中国,美国,德国</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">超人,蜘蛛侠,钢铁侠</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> } ;<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> strArray;<br />    }<br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  返回DataForm类的对象实例</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> DataForm getDataForm()<br />    {<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> DataForm();<br />    }<br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  将DataForm类的对象实例序列化，并返回序列化后的字节数组</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[] getDataFormBytes() </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception <br />    {<br />        java.io.ByteArrayOutputStream baos </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> java.io.ByteArrayOutputStream();<br />        java.io.ObjectOutputStream oos </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> java.io.ObjectOutputStream(baos);<br />        oos.writeObject(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> DataForm());        <br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> baos.toByteArray();<br />    }    <br />}<br /></span></div><p>  
</p><meta content="Word.Document" name="ProgId" /><meta content="Microsoft Word 11" name="Generator" /><meta content="Microsoft Word 11" name="Originator" /><link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List" /><style><!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
--></style><p><strong><span style="FONT-FAMILY: 宋体">二、实现</span>DataForm</strong><strong><span style="FONT-FAMILY: 宋体">类</span></strong></p><p><span><span>    </span>DataForm</span><span style="FONT-FAMILY: 宋体">是要返回的对象实例所对应的类，该类的实现代码如下：</span><br /></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> data;<br /><br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> DataForm </span><span style="COLOR: #0000ff">implements</span><span style="COLOR: #000000"> java.io.Serializable<br />{<br />    </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> String name </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">bill</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />    </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> age </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">20</span><span style="COLOR: #000000">;<br /><br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> String getName()<br />    {<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> name;<br />    }<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> setName(String name)<br />    {<br />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.name </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> name;<br />    }<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> getAge()<br />    {<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> age;<br />    }<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> setAge(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> age)<br />    {<br />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.age </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> age;<br />    }<br />}<br /></span></div><p></p><meta content="Word.Document" name="ProgId" /><meta content="Microsoft Word 11" name="Generator" /><meta content="Microsoft Word 11" name="Originator" /><link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List" /><style><!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
--></style><p><strong><span style="FONT-FAMILY: 宋体">三、发布</span>WebService</strong></p><p>    <span style="FONT-FAMILY: 宋体">由于本示例的</span>WebService<span style="FONT-FAMILY: 宋体">类使用了一个</span>Java<span style="FONT-FAMILY: 宋体">类（</span>DataForm<span style="FONT-FAMILY: 宋体">类），因此，在发布</span>WebService<span style="FONT-FAMILY: 宋体">之前，需要先将</span>DataForm.class<span style="FONT-FAMILY: 宋体">文件复制到</span>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps\axis2\WEB-INF\classes\data<span style="FONT-FAMILY: 宋体">目录中，然后将</span>ComplexTypeService.class<span style="FONT-FAMILY: 宋体">文件复制到</span>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps\axis2\WEB-INF\pojo<span style="FONT-FAMILY: 宋体">目录中，最后启动</span>Tomcat<span style="FONT-FAMILY: 宋体">（如果</span>Tomcat<span style="FONT-FAMILY: 宋体">已经启动，由于增加了一个</span>DataForm<span style="FONT-FAMILY: 宋体">类，因此，需要重新启动</span>Tomcat<span style="FONT-FAMILY: 宋体">）。</span></p><p><strong><span style="FONT-FAMILY: 宋体">四、使用</span>Java</strong><strong><span style="FONT-FAMILY: 宋体">编写调用</span>WebService</strong><strong><span style="FONT-FAMILY: 宋体">的客户端代码</span></strong></p><p>    <span style="FONT-FAMILY: 宋体">在客户端仍然使用了</span>RPC<span style="FONT-FAMILY: 宋体">的调用方式，代码如下：<br /></span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> client;<br /><br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> javax.xml.namespace.QName;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.addressing.EndpointReference;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.client.Options;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.rpc.client.RPCServiceClient;<br /><br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> ComplexTypeRPCClient<br />{<br /><br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> main(String[] args) </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception<br />    {<br />        RPCServiceClient serviceClient </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> RPCServiceClient();<br />        Options options </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> serviceClient.getOptions();<br />        EndpointReference targetEPR </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> EndpointReference(<br />                </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">http://localhost:8080/axis2/services/ComplexTypeService</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        options.setTo(targetEPR);<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 下面的代码调用uploadImageWithByte方法上传图像文件</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        </span><span style="COLOR: #008000">////////////////////////////////////////</span><span style="COLOR: #008000">/<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 打开图像文件，确定图像文件的大小</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        java.io.File file </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> java.io.File(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">f:\\images.jpg</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        java.io.FileInputStream fis </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> java.io.FileInputStream(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">f:\\images.jpg</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 创建保存要上传的图像文件内容的字节数组</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[] buffer </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">) file.length()];<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 将图像文件的内容读取buffer数组中</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> n </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> fis.read(buffer);<br />        System.out.println(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">文件长度：</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> file.length());<br />        Object[] opAddEntryArgs </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Object[]{ buffer, n };<br />        Class[] classes </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Class[]{ Boolean.</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> };<br />        QName opAddEntry </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> QName(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">http://ws.apache.org/axis2</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">uploadImageWithByte</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        fis.close();<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 开始上传图像文件，并输出uploadImageWithByte方法的返回传</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        System.out.println(serviceClient.invokeBlocking(opAddEntry,opAddEntryArgs, classes)[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]);<br />        </span><span style="COLOR: #008000">////////////////////////////////////////</span><span style="COLOR: #008000">/<br />        <br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 下面的代码调用了getArray方法，并返回一维String数组</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        </span><span style="COLOR: #008000">////////////////////////////////////////</span><span style="COLOR: #008000">/  </span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        opAddEntry </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> QName(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">http://ws.apache.org/axis2</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">getArray</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        String[] strArray </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (String[]) serviceClient.invokeBlocking(opAddEntry, </span><span style="COLOR: #0000ff"><br />                            new</span><span style="COLOR: #000000"> Object[]{}, </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Class[]{String[].</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> })[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];<br />        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (String s : strArray)<br />            System.out.print(s </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">  </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        System.out.println();<br />        </span><span style="COLOR: #008000">////////////////////////////////////////</span><span style="COLOR: #008000">/ <br />        <br /><br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 下面的代码调用了getMDArray方法，并返回一维String数组</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        </span><span style="COLOR: #008000">////////////////////////////////////////</span><span style="COLOR: #008000">/  </span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        opAddEntry </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> QName(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">http://ws.apache.org/axis2</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">getMDArray</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        strArray </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (String[]) serviceClient.invokeBlocking(opAddEntry, </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Object[]{}, </span><span style="COLOR: #0000ff"><br />                                                          new</span><span style="COLOR: #000000"> Class[]{String[].</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">})[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];<br />        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (String s : strArray)<br />        {<br />            String[] array </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> s.split(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />            </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(String ss: array)<br />                System.out.print(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> ss </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&gt; </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />            System.out.println();<br />        }<br />        System.out.println();<br />        </span><span style="COLOR: #008000">////////////////////////////////////////</span><span style="COLOR: #008000">/ <br /><br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 下面的代码调用了getDataForm方法，并返回DataForm对象实例</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        </span><span style="COLOR: #008000">////////////////////////////////////////</span><span style="COLOR: #008000">/  </span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        opAddEntry </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> QName(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">http://ws.apache.org/axis2</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">getDataForm</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        data.DataForm df </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (data.DataForm) serviceClient.invokeBlocking(opAddEntry, </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Object[]{},<br />                                                                  </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Class[]{data.DataForm.</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">})[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];<br />        System.out.println(df.getAge());<br />        </span><span style="COLOR: #008000">////////////////////////////////////////</span><span style="COLOR: #008000">/<br />        <br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 下面的代码调用了getDataFormBytes方法，并返回字节数组，最后将返回的字节数组反序列化后，转换成DataForm对象实例</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        </span><span style="COLOR: #008000">////////////////////////////////////////</span><span style="COLOR: #008000">/          </span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        opAddEntry </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> QName(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">http://ws.apache.org/axis2</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">getDataFormBytes</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        buffer </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[]) serviceClient.invokeBlocking(opAddEntry, </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Object[]{}, </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Class[]{</span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[].</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">})[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];<br />        java.io.ObjectInputStream ois </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> java.io.ObjectInputStream(<br />                </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> java.io.ByteArrayInputStream(buffer));<br />        df </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (data.DataForm) ois.readObject();<br />        System.out.println(df.getName());<br />        </span><span style="COLOR: #008000">//////////////////////////////////////////<br /></span><span style="COLOR: #000000">    }<br />}<br /></span></div><p></p><meta content="Word.Document" name="ProgId" /><meta content="Microsoft Word 11" name="Generator" /><meta content="Microsoft Word 11" name="Originator" /><link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List" /><style><!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
--></style><p>    <span style="FONT-FAMILY: 宋体">运行上面的程序，将输出如下的内容：</span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #000000">文件长度：</span><span style="COLOR: #000000">3617</span><span style="COLOR: #000000"><br /><br />true<br /><br />自行车 飞机 火箭 <br /><br /></span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">自行车</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">飞机</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">火箭</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /><br /></span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">中国</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">美国</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">德国</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /><br /></span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">超人</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">蜘蛛侠</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">钢铁侠</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /><br /></span><span style="COLOR: #000000">20</span><span style="COLOR: #000000"><br /><br />bill</span></div><p><strong><span style="FONT-FAMILY: 宋体">五、使用</span>C#</strong><strong><span style="FONT-FAMILY: 宋体">编写调用</span>WebService</strong><strong><span style="FONT-FAMILY: 宋体">的客户端代码</span></strong></p><p>    <span style="FONT-FAMILY: 宋体">在</span>Visual Studio<span style="FONT-FAMILY: 宋体">中使用</span>WebService<span style="FONT-FAMILY: 宋体">就简单得多。假设引用</span>WebService<span style="FONT-FAMILY: 宋体">时的引用名为</span>complexType<span style="FONT-FAMILY: 宋体">，则下面的代码调用了</span>uploadImageWithByte<span style="FONT-FAMILY: 宋体">方法来上传图像文件。在</span>Visual Studio<span style="FONT-FAMILY: 宋体">引用</span>WebService<span style="FONT-FAMILY: 宋体">时，</span>uploadImageWithByte<span style="FONT-FAMILY: 宋体">方法多了两个</span>out<span style="FONT-FAMILY: 宋体">参数，在使用时要注意。<br /><br /></span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #000000">complexType.ComplexTypeService cts </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> WSC.complexType.ComplexTypeService();<br />System.IO.FileStream fs </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> System.IO.FileStream(</span><span style="COLOR: #000000">@"</span><span style="COLOR: #000000">f:\images.jpg</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, System.IO.FileMode.Open);<br /></span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[] buffer </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[fs.Length];<br />fs.Read(buffer, </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">, (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">)fs.Length);<br /></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000"> r;<br /></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000"> rs;<br />cts.uploadImageWithByte( buffer, (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">)fs.Length, </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">, </span><span style="COLOR: #0000ff">out</span><span style="COLOR: #000000"> r, </span><span style="COLOR: #0000ff">out</span><span style="COLOR: #000000"> rs);<br /></span></div><meta content="Word.Document" name="ProgId" /><meta content="Microsoft Word 11" name="Generator" /><meta content="Microsoft Word 11" name="Originator" /><link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List" /><style><!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
--></style><p>    <span style="FONT-FAMILY: 宋体">在获得二维数组时，可以将数据加载到</span>DataGridView<span style="FONT-FAMILY: 宋体">或其他类似的控件中，代码如下：<br /></span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #000000">String[] strArray </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> cts.getMDArray();<br /></span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; i </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> strArray.Length; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br />{<br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  用正则表达式将带分隔符的字符串转换成String数组</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">    String[] columns </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> strArray[i].Split(</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">);<br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  如果DataGridView的表头不存在，向DataGridView控件添加三个带表头的列</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (dataGridView1.Columns.Count </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br />        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> j </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; j </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> columns.Length; j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br />            dataGridView1.Columns.Add(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">column</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> (j </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">).ToString(), </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">列</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> (j </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">).ToString());<br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  添加行</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">    dataGridView1.Rows.Add(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br />    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> j </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; j </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> columns.Length; j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br />    {<br />        dataGridView1.Rows[i].Cells[j].Value </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> columns[j];                       <br />    }                <br />}<br /></span></div><p></p><meta content="Word.Document" name="ProgId" /><meta content="Microsoft Word 11" name="Generator" /><meta content="Microsoft Word 11" name="Originator" /><link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List" /><style><!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
--></style><p>    <span style="FONT-FAMILY: 宋体">向</span>DataGridView<span style="FONT-FAMILY: 宋体">控件添加数据后的效果如图</span>1<span style="FONT-FAMILY: 宋体">所示。<br /><br /><div align="center"><img height="238" alt="" src="http://www.blogjava.net/images/blogjava_net/nokiaguy/axis2_2/01.jpg" width="352" /><br /><br />图1  <br /></div></span></p><p></p><p></p><meta content="Word.Document" name="ProgId" /><meta content="Microsoft Word 11" name="Generator" /><meta content="Microsoft Word 11" name="Originator" /><link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List" /><style><!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
layout-grid:15.6pt;}
div.Section1
{page:Section1;}
--></style><p>    <span style="FONT-FAMILY: 宋体">对于其他的</span>WebService<span style="FONT-FAMILY: 宋体">方法的调用都非常简单，读者可以自己做这个实验。</span></p><p>    <span style="FONT-FAMILY: 宋体">要注意的是，由于</span>.net<span style="FONT-FAMILY: 宋体">和</span>java<span style="FONT-FAMILY: 宋体">序列化和反序列化的差异，通过序列化的方式传递对象实例只使用于客户端与服务端为同一种语言或技术的情况，如客户端和服务端都使用</span>Java<span style="FONT-FAMILY: 宋体">来编写。</span></p>    如果读者要上传大文件，应尽量使用FTP的方式来传递，而只通过WebService方法来传递文件名等信息。这样有助于提高传输效率。<br /><br /><img src ="http://www.blogjava.net/libin2722/aggbug/296158.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2009-09-23 14:38 <a href="http://www.blogjava.net/libin2722/articles/296158.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>（转）WebService大讲堂之Axis2(3)：使用services.xml文件发布WebService </title><link>http://www.blogjava.net/libin2722/articles/296159.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Wed, 23 Sep 2009 06:38:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/296159.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/296159.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/296159.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/296159.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/296159.html</trackback:ping><description><![CDATA[用Axis2<span style="FONT-FAMILY: 宋体">实现</span>Web Service<span style="FONT-FAMILY: 宋体">，虽然可以将</span>POJO<span style="FONT-FAMILY: 宋体">类放在</span>axis2\WEB-INF\pojo<span style="FONT-FAMILY: 宋体">目录中直接发布成</span>Web Service<span style="FONT-FAMILY: 宋体">，这样做不需要进行任何配置，但这些</span>POJO<span style="FONT-FAMILY: 宋体">类不能在任何包中。这似乎有些不方便，为此，</span>Axis2<span style="FONT-FAMILY: 宋体">也允许将带包的</span>POJO<span style="FONT-FAMILY: 宋体">类发布成</span>Web Service<span style="FONT-FAMILY: 宋体">。<br />    先实现一个</span>POJO<span style="FONT-FAMILY: 宋体">类，代码如下：<br /></span><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> service;<br /><br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> MyService<br />{<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> String getGreeting(String name)<br />    {<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">您好 </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> name;<br />    }<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> update(String data)<br />    {<br />        System.out.println(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> data </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&gt;已经更新</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />    }<br />}<br /></span></div><p style="TEXT-INDENT: 21.75pt"></p><p style="TEXT-INDENT: 21.75pt"><span style="FONT-FAMILY: 宋体">这个类有两个方法，这两个方法都需要发布成</span>Web Service<span style="FONT-FAMILY: 宋体">方法。这种方式和直接放在</span>pojo<span style="FONT-FAMILY: 宋体">目录中的</span>POJO<span style="FONT-FAMILY: 宋体">类不同。要想将</span>MyService<span style="FONT-FAMILY: 宋体">类发布成</span>Web Service<span style="FONT-FAMILY: 宋体">，需要一个</span>services.xml<span style="FONT-FAMILY: 宋体">文件，这个文件需要放在</span>META-INF<span style="FONT-FAMILY: 宋体">目录中，该文件的内容如下：</span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">service </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="myService"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        Web Service例子<br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">parameter </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="ServiceClass"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        service.MyService  <br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">parameter</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceivers</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceiver </span><span style="COLOR: #ff0000">mep</span><span style="COLOR: #0000ff">="http://www.w3.org/2004/08/wsdl/in-out"</span><span style="COLOR: #ff0000"><br />            class</span><span style="COLOR: #0000ff">="org.apache.axis2.rpc.receivers.RPCMessageReceiver"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceiver </span><span style="COLOR: #ff0000">mep</span><span style="COLOR: #0000ff">="http://www.w3.org/2004/08/wsdl/in-only"</span><span style="COLOR: #ff0000"><br />            class</span><span style="COLOR: #0000ff">="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">messageReceivers</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">service</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span></div><p style="TEXT-INDENT: 21.75pt"></p><p style="TEXT-INDENT: 21.75pt"><span style="FONT-FAMILY: 宋体">其中</span>&lt;service&gt;<span style="FONT-FAMILY: 宋体">元素用于发布</span>Web Service<span style="FONT-FAMILY: 宋体">，一个</span>&lt;service&gt;<span style="FONT-FAMILY: 宋体">元素只能发布一个</span>WebService<span style="FONT-FAMILY: 宋体">类，</span>name<span style="FONT-FAMILY: 宋体">属性表示</span>WebService<span style="FONT-FAMILY: 宋体">名，如下面的</span>URL<span style="FONT-FAMILY: 宋体">可以获得这个</span>WebService<span style="FONT-FAMILY: 宋体">的</span>WSDL<span style="FONT-FAMILY: 宋体">内容：<br /><br /></span></p><a href="http://localhost:8080/axis2/services/myService?wsdl">http://localhost:8080/axis2/services/myService?wsdl</a><br /><br /><p style="MARGIN-LEFT: 21pt; TEXT-INDENT: 0.75pt"><span style="FONT-FAMILY: 宋体">其中</span>name<span style="FONT-FAMILY: 宋体">属性名就是上面</span>URL<span style="FONT-FAMILY: 宋体">中</span>"?"<span style="FONT-FAMILY: 宋体">和</span>"/"<span style="FONT-FAMILY: 宋体">之间的部分。</span></p><p style="TEXT-INDENT: 21.75pt">&lt;description&gt;<span style="FONT-FAMILY: 宋体">元素表示当前</span>Web Service<span style="FONT-FAMILY: 宋体">的描述，</span>&lt;parameter&gt;<span style="FONT-FAMILY: 宋体">元素用于设置</span>WebService<span style="FONT-FAMILY: 宋体">的参数，在这里用于设置</span>WebService<span style="FONT-FAMILY: 宋体">对应的类名。在这里最值得注意的是</span>&lt;messageReceivers&gt;<span style="FONT-FAMILY: 宋体">元素，该元素用于设置处理</span>WebService<span style="FONT-FAMILY: 宋体">方法的处理器。例如，</span>getGreeting<span style="FONT-FAMILY: 宋体">方法有一个返回值，因此，需要使用可处理输入输出的</span>RPCMessageReceiver<span style="FONT-FAMILY: 宋体">类，而</span>update<span style="FONT-FAMILY: 宋体">方法没有返回值，因此，需要使用只能处理输入的</span>RPCInOnlyMessageReceiver<span style="FONT-FAMILY: 宋体">类。</span></p><p style="TEXT-INDENT: 21.75pt"><span style="FONT-FAMILY: 宋体">使用这种方式发布</span>WebService<span style="FONT-FAMILY: 宋体">，必须打包成</span>.aar<span style="FONT-FAMILY: 宋体">文件，</span>..aar<span style="FONT-FAMILY: 宋体">文件实际上就是改变了扩展名的</span>.jar<span style="FONT-FAMILY: 宋体">文件。在现在建立了两个文件：</span>MyService.java<span style="FONT-FAMILY: 宋体">和</span>services.xml<span style="FONT-FAMILY: 宋体">。将</span>MyService.java<span style="FONT-FAMILY: 宋体">编译，生成</span>MyService.class<span style="FONT-FAMILY: 宋体">。</span>services.xml<span style="FONT-FAMILY: 宋体">和</span>MyService.class<span style="FONT-FAMILY: 宋体">文件的位置如下：</span></p><p style="MARGIN-LEFT: 21pt; TEXT-INDENT: 0.75pt"><span>D:\ws\service\MyService.class</span></p><p style="TEXT-INDENT: 21.75pt"><span>D:\ws\META-INF\services.xml<br /><br />    </span><span style="FONT-FAMILY: 宋体">在</span>windows<span style="FONT-FAMILY: 宋体">控制台中进入</span>ws<span style="FONT-FAMILY: 宋体">目录，并输入如下的命令生成</span>.aar<span style="FONT-FAMILY: 宋体">文件（实际上，.jar文件也可以发布webservice，但axis2官方文档中建议使用.aar文件发布webservice）：</span><span><br /></span></p><p style="TEXT-INDENT: 21.75pt"><span>jar cvf ws.aar .<br /><br />    </span><span style="FONT-FAMILY: 宋体">最后将</span>ws.aar<span style="FONT-FAMILY: 宋体">文件复制到</span>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps\axis2\WEB-INF\services<span style="FONT-FAMILY: 宋体">目录中，启动</span>Tomcat<span style="FONT-FAMILY: 宋体">后，就可以调用这个</span>WebService<span style="FONT-FAMILY: 宋体">了。调用的方法和</span><a id="viewpost1_TitleUrl" href="/nokiaguy/archive/2009/04/archive/2009/nokiaguy/archive/2009/nokiaguy/archive/2009/01/archive/2009/01/02/249556.html">《WebService大讲堂之Axis2（1）：用POJO实现0配置的WebService》</a><span style="FONT-FAMILY: 宋体">所讲的方法类似。</span></p><p style="TEXT-INDENT: 21.75pt"><span style="FONT-FAMILY: 宋体">另外</span>services.xml<span style="FONT-FAMILY: 宋体">文件中也可以直接指定</span>WebService<span style="FONT-FAMILY: 宋体">类的方法，如可以用下面的配置代码来发布</span>WebService<span style="FONT-FAMILY: 宋体">：</span></p><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">service </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="myService"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        Web Service例子<br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">parameter </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="ServiceClass"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        service.MyService  <br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">parameter</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">operation </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="getGreeting"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceiver </span><span style="COLOR: #ff0000">class</span><span style="COLOR: #0000ff">="org.apache.axis2.rpc.receivers.RPCMessageReceiver"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">operation</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">operation </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="update"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceiver<br />            </span><span style="COLOR: #ff0000">class</span><span style="COLOR: #0000ff">="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">operation</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">service</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span></div><br /><p style="TEXT-INDENT: 21.75pt"><span style="FONT-FAMILY: 宋体">上面的配置代码前面的部分和以前的</span>services.xml<span style="FONT-FAMILY: 宋体">文件的内容相同，但后面使用了</span>&lt;operation&gt;<span style="FONT-FAMILY: 宋体">元素来指定每一个</span>WebService<span style="FONT-FAMILY: 宋体">方法，并单独指定了处理每一个方法的处理器。对于客户端来说，调用使用这两个</span>services.xml<span style="FONT-FAMILY: 宋体">文件发布的</span>WebService<span style="FONT-FAMILY: 宋体">并没有太大我区别，只是使用第二个</span>services.xml<span style="FONT-FAMILY: 宋体">文件发布</span>WebServices<span style="FONT-FAMILY: 宋体">后，在使用</span>wsdl2java<span style="FONT-FAMILY: 宋体">命令或使用</span>C#<span style="FONT-FAMILY: 宋体">、</span>delphi<span style="FONT-FAMILY: 宋体">等生成客户端的</span>stub<span style="FONT-FAMILY: 宋体">时，</span>update<span style="FONT-FAMILY: 宋体">方法的</span>String<span style="FONT-FAMILY: 宋体">类型被封装在了</span>update<span style="FONT-FAMILY: 宋体">类中，在传递</span>update<span style="FONT-FAMILY: 宋体">方法的参数时需要建立</span>update<span style="FONT-FAMILY: 宋体">类的对象实例。而使用第一个</span>services.xml<span style="FONT-FAMILY: 宋体">文件发布的</span>WebService<span style="FONT-FAMILY: 宋体">在生成</span>stub<span style="FONT-FAMILY: 宋体">时直接可以为</span>update<span style="FONT-FAMILY: 宋体">方法传递</span>String<span style="FONT-FAMILY: 宋体">类型的参数。从这一点可以看出，这两种方法生成的</span>WSDL<span style="FONT-FAMILY: 宋体">有一定的区别。但实际上，如果客户端程序使用第一个</span>services.xml<span style="FONT-FAMILY: 宋体">文件发布的</span>WebService<span style="FONT-FAMILY: 宋体">生成</span>stub<span style="FONT-FAMILY: 宋体">类时（这时</span>update<span style="FONT-FAMILY: 宋体">方法的参数是</span>String<span style="FONT-FAMILY: 宋体">），在服务端又改为第二个</span>services.xml<span style="FONT-FAMILY: 宋体">文件来发布</span>WebService<span style="FONT-FAMILY: 宋体">，这时客户端并不需要再重新生成</span>stub<span style="FONT-FAMILY: 宋体">类，而可以直接调用</span>update<span style="FONT-FAMILY: 宋体">方法。也就是说，服务端使用什么样的方式发布</span>WebService<span style="FONT-FAMILY: 宋体">，对客户端并没有影响。</span></p><p style="TEXT-INDENT: 21.75pt"><span style="FONT-FAMILY: 宋体">如果想发布多个</span>WebService<span style="FONT-FAMILY: 宋体">，可以使用</span>&lt;serviceGroup&gt;<span style="FONT-FAMILY: 宋体">元素，如再建立一个</span>MyService1<span style="FONT-FAMILY: 宋体">类，代码如下：<br /></span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> service<br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> MyService1<br />{<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> String getName()  <br />    { <br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">bill</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />    }<br />}<br /></span></div><p style="TEXT-INDENT: 21.75pt"></p><p style="TEXT-INDENT: 21.75pt"><span style="FONT-FAMILY: 宋体">在</span>services.xml<span style="FONT-FAMILY: 宋体">文件中可以使用如下的配置代码来配置</span>MyService<span style="FONT-FAMILY: 宋体">和</span>MyService1<span style="FONT-FAMILY: 宋体">类：</span></p><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">serviceGroup</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">    &lt;</span><span style="COLOR: #800000">service </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="myService"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            Web Service例子<br />        </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">parameter </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="ServiceClass"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            service.MyService  <br />        </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">parameter</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceivers</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceiver </span><span style="COLOR: #ff0000">mep</span><span style="COLOR: #0000ff">="http://www.w3.org/2004/08/wsdl/in-out"</span><span style="COLOR: #ff0000"><br />                class</span><span style="COLOR: #0000ff">="org.apache.axis2.rpc.receivers.RPCMessageReceiver"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceiver </span><span style="COLOR: #ff0000">mep</span><span style="COLOR: #0000ff">="http://www.w3.org/2004/08/wsdl/in-only"</span><span style="COLOR: #ff0000"><br />                class</span><span style="COLOR: #0000ff">="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">messageReceivers</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">    &lt;/</span><span style="COLOR: #800000">service</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">    &lt;</span><span style="COLOR: #800000">service </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="myService1"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            Web Service例子<br />       </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">parameter </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="ServiceClass"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            service.MyService1  <br />        </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">parameter</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />         </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceivers</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />           </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceiver </span><span style="COLOR: #ff0000">mep</span><span style="COLOR: #0000ff">="http://www.w3.org/2004/08/wsdl/in-out"</span><span style="COLOR: #ff0000"><br />                class</span><span style="COLOR: #0000ff">="org.apache.axis2.rpc.receivers.RPCMessageReceiver"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />           </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">messageReceiver </span><span style="COLOR: #ff0000">mep</span><span style="COLOR: #0000ff">="http://www.w3.org/2004/08/wsdl/in-only"</span><span style="COLOR: #ff0000"><br />                class</span><span style="COLOR: #0000ff">="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">messageReceivers</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">    &lt;/</span><span style="COLOR: #800000">service</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">serviceGroup</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span></div><br /><img src ="http://www.blogjava.net/libin2722/aggbug/296159.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2009-09-23 14:38 <a href="http://www.blogjava.net/libin2722/articles/296159.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>(转)WebService大讲堂之Axis2（1）：用POJO实现0配置的WebService </title><link>http://www.blogjava.net/libin2722/articles/296142.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Wed, 23 Sep 2009 03:52:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/296142.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/296142.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/296142.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/296142.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/296142.html</trackback:ping><description><![CDATA[Axis2<span style="FONT-FAMILY: 宋体">是一套崭新的</span>WebService<span style="FONT-FAMILY: 宋体">引擎，该版本是对</span>Axis1.x<span style="FONT-FAMILY: 宋体">重新设计的产物。</span>Axis2<span style="FONT-FAMILY: 宋体">不仅支持</span>SOAP1.1<span style="FONT-FAMILY: 宋体">和</span>SOAP1.2<span style="FONT-FAMILY: 宋体">，还集成了非常流行的</span>REST WebService<span style="FONT-FAMILY: 宋体">，同时还支持</span>Spring<span style="FONT-FAMILY: 宋体">、</span>JSON<span style="FONT-FAMILY: 宋体">等技术。这些都将在后面的系列教程中讲解。在本文中主要介绍了如何使用</span>Axis2<span style="FONT-FAMILY: 宋体">开发一个不需要任何配置文件的</span>WebService<span style="FONT-FAMILY: 宋体">，并在客户端使用</span>Java<span style="FONT-FAMILY: 宋体">和</span>C#<span style="FONT-FAMILY: 宋体">调用这个</span>WebService<span style="FONT-FAMILY: 宋体">。</span><p><strong><span style="FONT-FAMILY: 宋体">一、</span>Axis2</strong><strong><span style="FONT-FAMILY: 宋体">的下载和安装</span></strong></p><p>    <span style="FONT-FAMILY: 宋体">读者可以从如下的网址下载</span>Axis2<span style="FONT-FAMILY: 宋体">的最新版本：</span></p><p>    <a href="http://ws.apache.org/axis2/">http://ws.apache.org/axis2/</a><br /></p><p>    <span style="FONT-FAMILY: 宋体">在本文使用了目前</span>Axis2<span style="FONT-FAMILY: 宋体">的最新版本</span>1.4.1<span style="FONT-FAMILY: 宋体">。读者可以下载如下两个</span>zip<span style="FONT-FAMILY: 宋体">包：</span></p><p>    axis2-1.4.1-bin.zip</p><p>    axis2-1.4.1-war.zip</p><p>    <span style="FONT-FAMILY: 宋体">其中</span>axis2-1.4.1-bin.zip<span style="FONT-FAMILY: 宋体">文件中包含了</span>Axis2<span style="FONT-FAMILY: 宋体">中所有的</span>jar<span style="FONT-FAMILY: 宋体">文件</span>, axis2-1.4.1-war.zip<span style="FONT-FAMILY: 宋体">文件用于将</span>WebService<span style="FONT-FAMILY: 宋体">发布到</span>Web<span style="FONT-FAMILY: 宋体">容器中。</span></p><p>    <span style="FONT-FAMILY: 宋体">将</span>axis2-1.4.1-war.zip<span style="FONT-FAMILY: 宋体">文件解压到相应的目录，将目录中的</span>axis2.war<span style="FONT-FAMILY: 宋体">文件放到</span>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps<span style="FONT-FAMILY: 宋体">目录中（本文使用的</span>Tomcat<span style="FONT-FAMILY: 宋体">的版本是</span>6.x<span style="FONT-FAMILY: 宋体">），并启动</span>Tomcat<span style="FONT-FAMILY: 宋体">。</span></p><p>    <span style="FONT-FAMILY: 宋体">在浏览器地址栏中输入如下的</span>URL<span style="FONT-FAMILY: 宋体">：</span></p><p>    <a href="http://localhost:8080/axis2/">http://localhost:8080/axis2/</a><br /></p><p>    <span style="FONT-FAMILY: 宋体">如果在浏览器中显示出如图</span>1<span style="FONT-FAMILY: 宋体">所示的页面，则表示</span>Axis2<span style="FONT-FAMILY: 宋体">安装成功。<br /></span></p><div align="center"><img height="410" alt="" src="http://www.blogjava.net/images/blogjava_net/nokiaguy/axis2_1/01.jpg" width="708" /><br /><br />图1<br /></div><p></p><meta content="Word.Document" name="ProgId" /><meta content="Microsoft Word 11" name="Generator" /><meta content="Microsoft Word 11" name="Originator" /><style><!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
--></style><strong><span style="FONT-FAMILY: 宋体">二、编写和发布WebService</span></strong><p>  <span style="FONT-FAMILY: 宋体">对于用</span>Java<span style="FONT-FAMILY: 宋体">实现的服务程序给人的印象就是需要进行大量的配置，不过这一点在</span>Axis2<span style="FONT-FAMILY: 宋体">中将被终结。在</span>Axis2<span style="FONT-FAMILY: 宋体">中不需要进行任何的配置，就可以直接将一个简单的</span>POJO<span style="FONT-FAMILY: 宋体">发布成</span>WebService<span style="FONT-FAMILY: 宋体">。其中</span>POJO<span style="FONT-FAMILY: 宋体">中所有的</span>public<span style="FONT-FAMILY: 宋体">方法将被发布成</span>WebService<span style="FONT-FAMILY: 宋体">方法。</span></p><p>    <span style="FONT-FAMILY: 宋体">下面我们来实现一个简单的</span>POJO<span style="FONT-FAMILY: 宋体">，代码如下：</span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> SimpleService<br />{<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> String getGreeting(String name)<br />    {<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">你好 </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> name;<br />    }    <br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> getPrice()<br />    {<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> java.util.Random().nextInt(</span><span style="COLOR: #000000">1000</span><span style="COLOR: #000000">);<br />    }    <br />}<br /></span></div><p></p><meta content="Word.Document" name="ProgId" /><meta content="Microsoft Word 11" name="Generator" /><meta content="Microsoft Word 11" name="Originator" /><link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C02%5Cclip_filelist.xml" rel="File-List" /><style><!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
--></style><p>    <span style="FONT-FAMILY: 宋体">在</span>SimpleService<span style="FONT-FAMILY: 宋体">类中有两个方法，由于这两个方法都是</span>public<span style="FONT-FAMILY: 宋体">方法，因此，它们都将作为</span>WebService<span style="FONT-FAMILY: 宋体">方法被发布。</span></p><p>    <span style="FONT-FAMILY: 宋体">编译</span>SimpleService<span style="FONT-FAMILY: 宋体">类后，将</span>SimpleService.class<span style="FONT-FAMILY: 宋体">文件放到</span>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps\axis2\WEB-INF\pojo<span style="FONT-FAMILY: 宋体">目录中（如果没有</span>pojo<span style="FONT-FAMILY: 宋体">目录，则建立该目录）。现在我们已经成功将</span>SimpleService<span style="FONT-FAMILY: 宋体">类发布成了</span>WebService<span style="FONT-FAMILY: 宋体">。在浏览器地址栏中输入如下的</span>URL<span style="FONT-FAMILY: 宋体">：</span></p><p><a href="http://localhost:8080/axis2/services/listServices">http://localhost:8080/axis2/services/listServices</a><br /></p><p>    <span style="FONT-FAMILY: 宋体">这时当前页面将显示所有在</span>Axis2<span style="FONT-FAMILY: 宋体">中发布的</span>WebService<span style="FONT-FAMILY: 宋体">，如图</span>2<span style="FONT-FAMILY: 宋体">所示。<br /><div align="center"><img height="400" alt="" src="http://www.blogjava.net/images/blogjava_net/nokiaguy/axis2_1/02.jpg" width="691" /><br /><span style="FONT-FAMILY: 宋体"><br />图2</span><br /></div></span></p><p></p><p></p><meta content="Word.Document" name="ProgId" /><meta content="Microsoft Word 11" name="Generator" /><meta content="Microsoft Word 11" name="Originator" /><style><!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
--></style>
    <span style="FONT-FAMILY: 宋体">在浏览器地址栏中输入如下的两个</span>URL<span style="FONT-FAMILY: 宋体">来分别测试</span>getGreeting<span style="FONT-FAMILY: 宋体">和</span>getPrice<span style="FONT-FAMILY: 宋体">方法：</span><p><a href="http://localhost:8080/axis2/services/SimpleService/getGreeting?name=bill">http://localhost:8080/axis2/services/SimpleService/getGreeting?name=bill</a><br /></p><p><a href="http://localhost:8080/axis2/services/SimpleService/getPrice">http://localhost:8080/axis2/services/SimpleService/getPrice</a><br /><br />    <span style="FONT-FAMILY: 宋体">图</span>3<span style="FONT-FAMILY: 宋体">和图</span>4<span style="FONT-FAMILY: 宋体">分别显示了</span>getGreeting<span style="FONT-FAMILY: 宋体">和</span>getPrice<span style="FONT-FAMILY: 宋体">方法的测试结果。<br /><div align="center"><img height="391" alt="" src="http://www.blogjava.net/images/blogjava_net/nokiaguy/axis2_1/03.jpg" width="523" /></div></span></p><p></p><p align="center"><span style="FONT-FAMILY: 宋体">图3  getGreeting方法的测试结果</span></p><p><span style="FONT-FAMILY: 宋体"><div align="center"><img alt="" src="http://www.blogjava.net/images/blogjava_net/nokiaguy/axis2_1/04.jpg" /></div></span></p><p></p><p align="center"><span style="FONT-FAMILY: 宋体">图4  getPrice方法的测试结果</span></p><p></p><meta content="Word.Document" name="ProgId" /><meta content="Microsoft Word 11" name="Generator" /><meta content="Microsoft Word 11" name="Originator" /><link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C06%5Cclip_filelist.xml" rel="File-List" /><style><!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
--></style><p>    <span style="FONT-FAMILY: 宋体">在编写、发布和测试</span>0<span style="FONT-FAMILY: 宋体">配置的</span>WebService<span style="FONT-FAMILY: 宋体">时应注意如下几点：</span></p><p><span><span>    </span>1. POJO</span><span style="FONT-FAMILY: 宋体">类不能使用</span>package<span style="FONT-FAMILY: 宋体">关键字声明包。</span></p><p><span><span>    </span>2. Axis2</span><span style="FONT-FAMILY: 宋体">在默认情况下可以热发布</span>WebService<span style="FONT-FAMILY: 宋体">，也就是说，将</span>WebService<span style="FONT-FAMILY: 宋体">的</span>.class<span style="FONT-FAMILY: 宋体">文件复制到</span>pojo<span style="FONT-FAMILY: 宋体">目录中时，</span>Tomcat<span style="FONT-FAMILY: 宋体">不需要重新启动就可以自动发布</span>WebService<span style="FONT-FAMILY: 宋体">。如果想取消</span>Axis2<span style="FONT-FAMILY: 宋体">的热发布功能，可以打开</span>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps\axis2\WEB-INF\conf\axis2.xml<span style="FONT-FAMILY: 宋体">，找到如下的配置代码：</span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">parameter </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="hotdeployment"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">true</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">parameter</span><span style="COLOR: #0000ff">&gt;</span></div><p></p><p></p><p></p><p>    <span style="FONT-FAMILY: 宋体">将</span>true<span style="FONT-FAMILY: 宋体">改为</span>false<span style="FONT-FAMILY: 宋体">即可。要注意的是，</span>Axis2<span style="FONT-FAMILY: 宋体">在默认情况下虽然是热发布，但并不是热更新，也就是说，一旦成功发布了</span>WebService<span style="FONT-FAMILY: 宋体">，再想更新该</span>WebService<span style="FONT-FAMILY: 宋体">，就必须重启</span>Tomcat<span style="FONT-FAMILY: 宋体">。这对于开发人员调试</span>WebService<span style="FONT-FAMILY: 宋体">非常不方便，因此，在开发</span>WebService<span style="FONT-FAMILY: 宋体">时，可以将</span>Axis2<span style="FONT-FAMILY: 宋体">设为热更新。在</span>axis2.xml<span style="FONT-FAMILY: 宋体">文件中找到</span><span>&lt;parameter name="hotupdate"&gt;false&lt;/parameter&gt;</span><span style="FONT-FAMILY: 宋体">，将</span>false<span style="FONT-FAMILY: 宋体">改为</span>true<span style="FONT-FAMILY: 宋体">即可。</span></p><p><span><span>    </span>3. </span><span style="FONT-FAMILY: 宋体">在浏览器中测试</span>WebService<span style="FONT-FAMILY: 宋体">时，如果</span>WebService<span style="FONT-FAMILY: 宋体">方法有参数，需要使用</span>URL<span style="FONT-FAMILY: 宋体">的请求参数来指定该</span>WebService<span style="FONT-FAMILY: 宋体">方法参数的值，请求参数名与方法参数名要一致，例如，要测试</span>getGreeting<span style="FONT-FAMILY: 宋体">方法，请求参数名应为</span>name<span style="FONT-FAMILY: 宋体">，如上面的</span>URL<span style="FONT-FAMILY: 宋体">所示。</span></p><p><span><span>    </span>4. </span><span style="FONT-FAMILY: 宋体">发布</span>WebService<span style="FONT-FAMILY: 宋体">的</span>pojo<span style="FONT-FAMILY: 宋体">目录只是默认的，如果读者想在其他的目录发布</span>WebService<span style="FONT-FAMILY: 宋体">，可以打开</span>axis2.xml<span style="FONT-FAMILY: 宋体">文件，并在</span>&lt;axisconfig&gt;<span style="FONT-FAMILY: 宋体">元素中添加如下的子元素：</span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">deployer </span><span style="COLOR: #ff0000">extension</span><span style="COLOR: #0000ff">=".class"</span><span style="COLOR: #ff0000"> directory</span><span style="COLOR: #0000ff">="my"</span><span style="COLOR: #ff0000"> class</span><span style="COLOR: #0000ff">="org.apache.axis2.deployment.POJODeployer"</span><span style="COLOR: #0000ff">/&gt;</span></div><p></p><p></p><p></p><p>    <span style="FONT-FAMILY: 宋体">上面的配置允许在</span>&lt;Tomcat<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;\webapps\axis2\WEB-INF\my<span style="FONT-FAMILY: 宋体">目录中发布</span>WebService<span style="FONT-FAMILY: 宋体">。例如，将本例中的</span>SimpleService.class<span style="FONT-FAMILY: 宋体">复制到</span>my<span style="FONT-FAMILY: 宋体">目录中也可以成功发布（但要删除</span>pojo<span style="FONT-FAMILY: 宋体">目录中的</span>SimpleService.class<span style="FONT-FAMILY: 宋体">，否则</span>WebService<span style="FONT-FAMILY: 宋体">会重名）。</span></p><p></p><meta content="Word.Document" name="ProgId" /><meta content="Microsoft Word 11" name="Generator" /><meta content="Microsoft Word 11" name="Originator" /><link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C08%5Cclip_filelist.xml" rel="File-List" /><style><!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
--></style><p><strong><span style="FONT-FAMILY: 宋体">三、</span></strong><strong><span style="FONT-FAMILY: 宋体">用</span>Java</strong><strong><span style="FONT-FAMILY: 宋体">实现调用</span>WebService</strong><strong><span style="FONT-FAMILY: 宋体">的客户端程序</span></strong></p><p>    WebService<span style="FONT-FAMILY: 宋体">是为程序服务的，只在浏览器中访问</span>WebService<span style="FONT-FAMILY: 宋体">是没有意义的。因此，在本节使用</span>Java<span style="FONT-FAMILY: 宋体">实现了一个控制台程序来调用上一节发布的</span>WebService<span style="FONT-FAMILY: 宋体">。调用</span>WebService<span style="FONT-FAMILY: 宋体">的客户端代码如下：</span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> client;<br /><br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> javax.xml.namespace.QName;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.addressing.EndpointReference;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.client.Options;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.rpc.client.RPCServiceClient;<br /><br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> RPCClient<br />{<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> main(String[] args) </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception  <br />    {<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  使用RPC方式调用WebService        </span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        RPCServiceClient serviceClient </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> RPCServiceClient();<br />        Options options </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> serviceClient.getOptions();<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  指定调用WebService的URL</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        EndpointReference targetEPR </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> EndpointReference(<br />                </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">http://localhost:8080/axis2/services/SimpleService</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        options.setTo(targetEPR);<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  指定getGreeting方法的参数值</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        Object[] opAddEntryArgs </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Object[] {</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">超人</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">};<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  指定getGreeting方法返回值的数据类型的Class对象</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        Class[] classes </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Class[] {String.</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">};<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  指定要调用的getGreeting方法及WSDL文件的命名空间</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        QName opAddEntry </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> QName(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">http://ws.apache.org/axis2</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">getGreeting</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  调用getGreeting方法并输出该方法的返回值</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        System.out.println(serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes)[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]);<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  下面是调用getPrice方法的代码，这些代码与调用getGreeting方法的代码类似</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        classes </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Class[] {</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">.</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">};<br />        opAddEntry </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> QName(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">http://ws.apache.org/axis2</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">getPrice</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        System.out.println(serviceClient.invokeBlocking(opAddEntry, </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Object[]{}, classes)[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]);<br />    } <br />}<br /></span></div><p></p><p></p><p></p><p></p><p></p><meta content="Word.Document" name="ProgId" /><meta content="Microsoft Word 11" name="Generator" /><meta content="Microsoft Word 11" name="Originator" /><style><!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
--></style><span style="FONT-FAMILY: 宋体">运行上面的程序后，将在控制台输出如下的信息：</span><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #000000">你好 超人<br />443</span></div><p>    <span style="FONT-FAMILY: 宋体">在编写客户端代码时应注意如下几点：</span></p><p><span><span>    </span>1. </span><span style="FONT-FAMILY: 宋体">客户端代码需要引用很多</span>Axis2<span style="FONT-FAMILY: 宋体">的</span>jar<span style="FONT-FAMILY: 宋体">包，如果读者不太清楚要引用哪个</span>jar<span style="FONT-FAMILY: 宋体">包，可以在</span>Eclipse<span style="FONT-FAMILY: 宋体">的工程中引用</span>Axis2<span style="FONT-FAMILY: 宋体">发行包的</span>lib<span style="FONT-FAMILY: 宋体">目录中的所有</span>jar<span style="FONT-FAMILY: 宋体">包。</span></p><p><span><span>    </span>2. </span><span style="FONT-FAMILY: 宋体">在本例中使用了</span>RPCServiceClient<span style="FONT-FAMILY: 宋体">类的</span>invokeBlocking<span style="FONT-FAMILY: 宋体">方法调用了</span>WebService<span style="FONT-FAMILY: 宋体">中的方法。</span>invokeBlocking<span style="FONT-FAMILY: 宋体">方法有三个参数，其中第一个参数的类型是</span>QName<span style="FONT-FAMILY: 宋体">对象，表示要调用的方法名；第二个参数表示要调用的</span>WebService<span style="FONT-FAMILY: 宋体">方法的参数值，参数类型为</span>Object[]<span style="FONT-FAMILY: 宋体">；第三个参数表示</span>WebService<span style="FONT-FAMILY: 宋体">方法的返回值类型的</span>Class<span style="FONT-FAMILY: 宋体">对象，参数类型为</span>Class[]<span style="FONT-FAMILY: 宋体">。当方法没有参数时，</span>invokeBlocking<span style="FONT-FAMILY: 宋体">方法的第二个参数值不能是</span>null<span style="FONT-FAMILY: 宋体">，而要使用</span>new Object[]{}<span style="FONT-FAMILY: 宋体">。</span></p><p><span><span>    </span>3. </span><span style="FONT-FAMILY: 宋体">如果被调用的</span>WebService<span style="FONT-FAMILY: 宋体">方法没有返回值，应使用</span>RPCServiceClient<span style="FONT-FAMILY: 宋体">类的</span>invokeRobust<span style="FONT-FAMILY: 宋体">方法，该方法只有两个参数，它们的含义与</span>invokeBlocking<span style="FONT-FAMILY: 宋体">方法的前两个参数的含义相同。</span></p><p><span><span>    </span>4. </span><span style="FONT-FAMILY: 宋体">在创建</span>QName<span style="FONT-FAMILY: 宋体">对象时，</span>QName<span style="FONT-FAMILY: 宋体">类的构造方法的第一个参数表示</span>WSDL<span style="FONT-FAMILY: 宋体">文件的命名空间名，也就是</span>&lt;wsdl:definitions&gt;<span style="FONT-FAMILY: 宋体">元素的</span>targetNamespace<span style="FONT-FAMILY: 宋体">属性值，下面是</span>SimpleService<span style="FONT-FAMILY: 宋体">类生成的</span>WSDL<span style="FONT-FAMILY: 宋体">文件的代码片段：<br /><br /></span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">&lt;?</span><span style="COLOR: #ff00ff">xml version="1.0" encoding="UTF-8"</span><span style="COLOR: #0000ff">?&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">wsdl:definitions </span><span style="COLOR: #ff0000">xmlns:wsdl</span><span style="COLOR: #0000ff">="http://schemas.xmlsoap.org/wsdl/"</span><span style="COLOR: #ff0000"> xmlns:ns1</span><span style="COLOR: #0000ff">="http://org.apache.axis2/xsd"</span><span style="COLOR: #ff0000"><br />xmlns:ns</span><span style="COLOR: #0000ff">="http://ws.apache.org/axis2"</span><span style="COLOR: #ff0000"> xmlns:wsaw</span><span style="COLOR: #0000ff">="http://www.w3.org/2006/05/addressing/wsdl"</span><span style="COLOR: #ff0000"><br />xmlns:http</span><span style="COLOR: #0000ff">="http://schemas.xmlsoap.org/wsdl/http/"</span><span style="COLOR: #ff0000"> xmlns:xs</span><span style="COLOR: #0000ff">="http://www.w3.org/2001/XMLSchema"</span><span style="COLOR: #ff0000"><br />xmlns:mime</span><span style="COLOR: #0000ff">="http://schemas.xmlsoap.org/wsdl/mime/"</span><span style="COLOR: #ff0000"> xmlns:soap</span><span style="COLOR: #0000ff">="http://schemas.xmlsoap.org/wsdl/soap/"</span><span style="COLOR: #ff0000"><br />xmlns:soap12</span><span style="COLOR: #0000ff">="http://schemas.xmlsoap.org/wsdl/soap12/"</span><strong><span style="COLOR: #ff0000"><br />targetNamespace</span><span style="COLOR: #0000ff">="http://ws.apache.org/axis2"</span></strong><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">wsdl:types</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        <img alt="" src="http://www.blogjava.net/images/dot.gif" /> <img alt="" src="http://www.blogjava.net/images/dot.gif" /><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">wsdl:types</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    <img alt="" src="http://www.blogjava.net/images/dot.gif" /> <img alt="" src="http://www.blogjava.net/images/dot.gif" /><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">wsdl:definitions</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span></div><p></p><meta content="Word.Document" name="ProgId" /><meta content="Microsoft Word 11" name="Generator" /><meta content="Microsoft Word 11" name="Originator" /><link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C14%5Cclip_filelist.xml" rel="File-List" /><style><!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
--></style><p><strong><span style="FONT-FAMILY: 宋体">四、用</span>wsdl2java</strong><strong><span style="FONT-FAMILY: 宋体">简化客户端的编写</span></strong></p><p>    <span style="FONT-FAMILY: 宋体">也许有很多读者会说“有没有搞错啊，只调用两个</span>WebService<span style="FONT-FAMILY: 宋体">方法用要写这么多代码，太麻烦了”。</span></p><p>    <span style="FONT-FAMILY: 宋体">不过幸好</span>Axis2<span style="FONT-FAMILY: 宋体">提供了一个</span>wsdl2java.bat<span style="FONT-FAMILY: 宋体">命令可以根据</span>WSDL<span style="FONT-FAMILY: 宋体">文件自动产生调用</span>WebService<span style="FONT-FAMILY: 宋体">的代码。</span>wsdl2java.bat<span style="FONT-FAMILY: 宋体">命令可以在</span>&lt;Axis2<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;"bin<span style="FONT-FAMILY: 宋体">目录中找到。在使用</span>wsdl2java.bat<span style="FONT-FAMILY: 宋体">命令之前需要设置</span>AXIS2_HOME<span style="FONT-FAMILY: 宋体">环境变量，该变量值是</span>&lt;Axis2<span style="FONT-FAMILY: 宋体">安装目录</span>&gt;<span style="FONT-FAMILY: 宋体">。</span></p><p>    <span style="FONT-FAMILY: 宋体">在</span>Windows<span style="FONT-FAMILY: 宋体">控制台输出如下的命令行来生成调用</span>WebService<span style="FONT-FAMILY: 宋体">的代码：</span></p><p><span>%AXIS2_HOME%\bin\wsdl2java -uri http://localhost:8080/axis2/services/SimpleService?wsdl -p client -s -o stub</span></p><p>    <span style="FONT-FAMILY: 宋体">其中</span>-url<span style="FONT-FAMILY: 宋体">参数指定了</span>wsdl<span style="FONT-FAMILY: 宋体">文件的路径，可以是本地路径，也可以是网络路径。</span>-p<span style="FONT-FAMILY: 宋体">参数指定了生成的</span>Java<span style="FONT-FAMILY: 宋体">类的包名，</span>-o<span style="FONT-FAMILY: 宋体">参数指定了生成的一系列文件保存的根目录。在执行完上面的命令后，读者就会发现在当前目录下多了个</span>stub<span style="FONT-FAMILY: 宋体">目录，在</span>."stub"src"client<span style="FONT-FAMILY: 宋体">目录可以找到一个</span>SimpleServiceStub.java<span style="FONT-FAMILY: 宋体">文件，该文件复杂调用</span>WebService<span style="FONT-FAMILY: 宋体">，读者可以在程序中直接使用这个类，代码如下：<br /></span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> client;<br /><br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> javax.xml.namespace.QName;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.addressing.EndpointReference;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.client.Options;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.apache.axis2.rpc.client.RPCServiceClient;<br /><br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> StubClient<br />{<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> main(String[] args) </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception  <br />    {<br />        SimpleServiceStub stub </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> SimpleServiceStub();<br />        SimpleServiceStub.GetGreeting gg </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> SimpleServiceStub.GetGreeting();<br />        gg.setName(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">比尔</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        System.out.println( stub.getGreeting(gg).get_return());<br />        System.out.println(stub.getPrice().get_return());<br />    } <br />}<br /></span></div><p></p><p></p><meta content="Word.Document" name="ProgId" /><meta content="Microsoft Word 11" name="Generator" /><meta content="Microsoft Word 11" name="Originator" /><link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C16%5Cclip_filelist.xml" rel="File-List" /><style><!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
--></style><p>    <span style="FONT-FAMILY: 宋体">上面的代码大大简化了调用</span>WebService<span style="FONT-FAMILY: 宋体">的步骤，并使代码更加简洁。但要注意的是，</span>wsdl2java.bat<span style="FONT-FAMILY: 宋体">命令生成的</span>Stub<span style="FONT-FAMILY: 宋体">类将</span>WebService<span style="FONT-FAMILY: 宋体">方法的参数都封装在了相应的类中，类名为方法名，例如，</span>getGreeting<span style="FONT-FAMILY: 宋体">方法的参数都封装在了</span>GetGreeting<span style="FONT-FAMILY: 宋体">类中，要想调用</span>getGreeting<span style="FONT-FAMILY: 宋体">方法，必须先创建</span>GetGreeting<span style="FONT-FAMILY: 宋体">类的对象实例。</span></p><p><strong><span style="FONT-FAMILY: 宋体">五、使用</span>C#</strong><strong><span style="FONT-FAMILY: 宋体">调用</span>WebService</strong></p><p>    <span style="FONT-FAMILY: 宋体">从理论上说，</span>WebService<span style="FONT-FAMILY: 宋体">可以被任何支持</span>SOAP<span style="FONT-FAMILY: 宋体">协议的语言调用。在</span>Visual Studio<span style="FONT-FAMILY: 宋体">中使用</span>C#<span style="FONT-FAMILY: 宋体">调用</span>WebService<span style="FONT-FAMILY: 宋体">是在所有语言中最容易实现的（</span>VB.net<span style="FONT-FAMILY: 宋体">的调用方法类似，也同样很简单）。</span></p><p>    <span style="FONT-FAMILY: 宋体">新建一个</span>Visual Studio<span style="FONT-FAMILY: 宋体">工程，并在引用</span>Web<span style="FONT-FAMILY: 宋体">服务的对话框中输入如下的</span>URL<span style="FONT-FAMILY: 宋体">，并输入</span>Web<span style="FONT-FAMILY: 宋体">引用名为“</span>WebService<span style="FONT-FAMILY: 宋体">”：</span></p><p>    <a href="http://localhost:8080/axis2/services/SimpleService?wsdl">http://localhost:8080/axis2/services/SimpleService?wsdl</a><br /></p><p>    <span style="FONT-FAMILY: 宋体">然后引用</span>Web<span style="FONT-FAMILY: 宋体">服务的对话框就会显示该</span>WebService<span style="FONT-FAMILY: 宋体">中的所有的方法，如图</span>5<span style="FONT-FAMILY: 宋体">所示。<br /><div align="center"><img height="463" alt="" src="http://www.blogjava.net/images/blogjava_net/nokiaguy/axis2_1/05.jpg" width="746" /><br /><br />图5<br /></div></span></p><meta content="Word.Document" name="ProgId" /><meta content="Microsoft Word 11" name="Generator" /><meta content="Microsoft Word 11" name="Originator" /><link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C18%5Cclip_filelist.xml" rel="File-List" /><style><!--
/* Font Definitions */
&#64;font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
&#64;font-face
{font-family:""&#64;宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
&#64;page
{}
&#64;page Section1
{size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
layout-grid:15.6pt;}
div.Section1
{page:Section1;}
--></style><p></p><p>    <span style="FONT-FAMILY: 宋体">在完成上面的工作后，只需要如下三行</span>C#<span style="FONT-FAMILY: 宋体">代码就可以调用</span>getGreeting<span style="FONT-FAMILY: 宋体">和</span>getPrice<span style="FONT-FAMILY: 宋体">方法，并显示这两个方法的返回值：</span></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="COLOR: #000000">WebService.SimpleService simpleService </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> WSC.WebService.SimpleService();<br />MessageBox.Show( simpleService.getGreeting(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">比尔</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br />MessageBox.Show(simpleService.getPrice().@return.ToString());</span></div><p></p><p></p><p></p><p>    <span style="FONT-FAMILY: 宋体">在</span>.net<span style="FONT-FAMILY: 宋体">解析</span>WSDL<span style="FONT-FAMILY: 宋体">文件时直接将</span>getGreeting<span style="FONT-FAMILY: 宋体">方法的参数映射为</span>String<span style="FONT-FAMILY: 宋体">类型，因此，可以直接进行传值。</span><br />    <span style="FONT-FAMILY: 宋体">从上面的调用过程可以看出，添加</span>Web<span style="FONT-FAMILY: 宋体">引用的过程就相当于在</span>Java<span style="FONT-FAMILY: 宋体">中调用</span>wsdl2java.bat<span style="FONT-FAMILY: 宋体">自动生成</span>stub<span style="FONT-FAMILY: 宋体">类的过程。只是在调用</span>stub<span style="FONT-FAMILY: 宋体">类时与</span>C#<span style="FONT-FAMILY: 宋体">有一定的区别，但从总体上来说，都大大简化了调用</span>WebService<span style="FONT-FAMILY: 宋体">的过程。</span><br /></p><img src ="http://www.blogjava.net/libin2722/aggbug/296142.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2009-09-23 11:52 <a href="http://www.blogjava.net/libin2722/articles/296142.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Using the Web Service Wrapper on Mule2.x</title><link>http://www.blogjava.net/libin2722/articles/295692.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Sat, 19 Sep 2009 13:53:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/295692.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/295692.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/295692.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/295692.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/295692.html</trackback:ping><description><![CDATA[
		<h1>
				<a name="WebServiceWrapper-UsingtheWebServiceWrapper">
				</a>Using the Web Service Wrapper</h1>
		<p>The <a href="http://www.mulesource.org/docs/site/current2/apidocs/org/mule/transport/soap/axis/component/WebServiceWrapperComponent.html">WebServiceWrapperComponent</a> class allows you to send the result of a web service call to another endpoint. The web service call is performed within <tt>WebServiceWrapperComponent</tt>, providing the following advantages:</p>
		<ul>
				<li>You can set any type of router on inbound and outbound. 
</li>
				<li>Unlike the chaining router, it can send more than one HTTP request at a time 
</li>
				<li>The URL for the web service call can be changed at run-time by sending the URL with the message </li>
		</ul>
		<h2>
				<a name="WebServiceWrapper-ConfiguringtheWebServiceWrapper">
				</a>Configuring the Web Service Wrapper</h2>
		<p>To use the web service wrapper, you specify the <tt>&lt;wrapper-component&gt;</tt> configuration element. The following table describes the attributes you can set for this element. These attributes are described in more detail in the examples that follow.</p>
		<table class="confluenceTable">
				<tbody>
						<tr>
								<th class="confluenceTh">Attribute</th>
								<th class="confluenceTh">Description</th>
								<th class="confluenceTh">Required?</th>
						</tr>
						<tr>
								<td class="confluenceTd">address</td>
								<td class="confluenceTd">Specifies the URL of the web service to call</td>
								<td class="confluenceTd">Yes, unless <tt>addressFromMessage</tt> is set to true</td>
						</tr>
						<tr>
								<td class="confluenceTd">addressFromMessage (default is false)</td>
								<td class="confluenceTd">Specifies that the URL of the web service will be obtained from the message itself</td>
								<td class="confluenceTd">Not required if <tt>address</tt> is set</td>
						</tr>
						<tr>
								<td class="confluenceTd">wrapperProperties</td>
								<td class="confluenceTd">The SOAP document style, expressed as a map of two properties: <tt>style</tt>, which can be set to <tt>RPC</tt> (the default), <tt>Document</tt>, <tt>Message</tt>, or <tt>Wrapped</tt>, and <tt>use</tt>, which can be <tt>Encoded</tt> or <tt>Literal</tt>.</td>
								<td class="confluenceTd">No</td>
						</tr>
						<tr>
								<td class="confluenceTd">
										<tt>&lt;soap-method&gt;</tt>
								</td>
								<td class="confluenceTd">A SOAP method to call (see <a href="http://www.mulesoft.org/display/MULE2USER/Web+Service+Wrapper#WebServiceWrapper-soapmethods">Configuring SOAP Methods</a> below)</td>
								<td class="confluenceTd">No</td>
						</tr>
				</tbody>
		</table>
		<p>The web service wrapper is generic and can be used with any type of web service stack supported by Mule, including Axis and CXF. The examples below show synchronous use cases, but the web service wrapper can also support an asynchronous use case like the <a title="Loan Broker Example" href="http://www.mulesoft.org/display/MULE2INTRO/Loan+Broker+Example">loan broker example</a>. </p>
		<h3>
				<a name="WebServiceWrapper-ExampleConfigurationUsingtheCXFTransport">
				</a>Example Configuration Using the CXF Transport</h3>
		<p>Consider the following example. The web service wrapper is configured as a Mule component, accepting messages from a VM endpoint. A call must be made to a web service on the URL <tt>cxf:<a href="http://localhost:65081/services/TestUMO?method=onReceive" rel="nofollow">http://localhost:65081/services/TestUMO?method=onReceive</a></tt> and the result must be sent to the outbound endpoint <tt>vm://testout</tt>. </p>
		<p>The inbound and outbound endpoints are configured in the usual way. The address is set as an attribute on the component, specifying the web service URL that you want to call. </p>
		<div class="code panel" style="BORDER-TOP-WIDTH: 1px; BORDER-LEFT-WIDTH: 1px; BORDER-BOTTOM-WIDTH: 1px; BORDER-RIGHT-WIDTH: 1px">
				<div class="codeContent panelContent">
						<pre class="code-xml">
								<span class="code-tag">&lt;cxf:connector name=<span class="code-quote">"cxf"</span> defaultFrontend=<span class="code-quote">"simple"</span> /&gt;</span>
								<span class="code-tag">&lt;model name=<span class="code-quote">"Sample"</span>&gt;</span>
								<span class="code-tag">&lt;service name=<span class="code-quote">"WebServiceSample"</span>&gt;</span>
								<span class="code-tag">&lt;inbound&gt;</span>
								<span class="code-tag">&lt;vm:inbound-endpoint path=<span class="code-quote">"testin"</span> /&gt;</span>
								<span class="code-tag">&lt;/inbound&gt;</span>
								<span class="code-tag">&lt;cxf:wrapper-component address=<span class="code-quote">"http://localhost:65081/services/TestUMO?method=onReceive"</span>/&gt;</span>
								<span class="code-tag">&lt;outbound&gt;</span>
								<span class="code-tag">&lt;pass-through-router&gt;</span>
								<span class="code-tag">&lt;outbound-endpoint address=<span class="code-quote">"vm://testout"</span>/&gt;</span>
								<span class="code-tag">&lt;/pass-through-router&gt;</span>
								<span class="code-tag">&lt;/outbound&gt;</span>
								<span class="code-tag">&lt;/service&gt;</span>
						</pre>
				</div>
		</div>
		<h3>
				<a name="WebServiceWrapper-ExampleConfigurationUsingtheaddressFromMessageProperty">
				</a>Example Configuration Using the addressFromMessage Property</h3>
		<p>The "address" property is ideal to use when the web service URL for the web service is known at configuration time. However, if this URL is either not known or else needs to be changed at run-time, the "address" property can be omitted and the "adddressFromMessage" property can be set to true. The following example shows this configuration:</p>
		<div class="code panel" style="BORDER-TOP-WIDTH: 1px; BORDER-LEFT-WIDTH: 1px; BORDER-BOTTOM-WIDTH: 1px; BORDER-RIGHT-WIDTH: 1px">
				<div class="codeContent panelContent">
						<pre class="code-xml">
								<span class="code-tag">&lt;service name = <span class="code-quote">"WebServiceSample2"</span>&gt;</span>
								<span class="code-tag">&lt;inbound&gt;</span>
								<span class="code-tag">&lt;vm:inbound-endpoint path = <span class="code-quote">"testin2"</span>/&gt;</span>
								<span class="code-tag">&lt;/inbound&gt;</span>
								<span class="code-tag">&lt;cxf:wrapper-component addressFromMessage = <span class="code-quote">"true"</span>/&gt;</span>
								<span class="code-tag">&lt;/service&gt;</span>
						</pre>
				</div>
		</div>
		<p>The URL must be set on the message with the property name "ws.service.url".<br /><a name="WebServiceWrapper-soapmethods"></a></p>
		<h3>
				<a name="WebServiceWrapper-ConfiguringSOAPMethods">
				</a>Configuring SOAP Methods</h3>
		<p>CXF endpoints are fairly easy to configure, whereas Axis needs some further configuration to set SOAP methods. You can set a SOAP method using the <tt>&lt;soap-method&gt;</tt> element as shown below: </p>
		<div class="code panel" style="BORDER-TOP-WIDTH: 1px; BORDER-LEFT-WIDTH: 1px; BORDER-BOTTOM-WIDTH: 1px; BORDER-RIGHT-WIDTH: 1px">
				<div class="codeContent panelContent">
						<pre class="code-xml">
								<span class="code-tag">&lt;service name = <span class="code-quote">"WebServiceSample3"</span>&gt;</span>
								<span class="code-tag">&lt;inbound&gt;</span>
								<span class="code-tag">&lt;vm:inbound-endpoint path = <span class="code-quote">"queue.in"</span> connector-ref = <span class="code-quote">"VMQueue"</span>/&gt;</span>
								<span class="code-tag">&lt;/inbound&gt;</span>
								<span class="code-tag">&lt;axis:wrapper-component address = <span class="code-quote">"http://localhost:62088/axis/Calculator?method=add"</span> style = <span class="code-quote">"WRAPPED"</span> use = <span class="code-quote">"LITERAL"</span>&gt;</span>
								<span class="code-tag">&lt;axis:soap-method method = <span class="code-quote">"qname{add:http://muleumo.org/Calc}"</span>&gt;</span>
								<span class="code-tag">&lt;axis:soap-parameter parameter = <span class="code-quote">"Number1"</span> type = <span class="code-quote">"int"</span> mode = <span class="code-quote">"IN"</span>/&gt;</span>
								<span class="code-tag">&lt;axis:soap-parameter parameter = <span class="code-quote">"Number2"</span> type = <span class="code-quote">"int"</span> mode = <span class="code-quote">"IN"</span>/&gt;</span>
								<span class="code-tag">&lt;axis:soap-return type = <span class="code-quote">"int"</span>/&gt;</span>
								<span class="code-tag">&lt;/axis:soap-method&gt;</span>
								<span class="code-tag">&lt;/axis:wrapper-component&gt;</span>
								<span class="code-tag">&lt;outbound&gt;</span>
								<span class="code-tag">&lt;pass-through-router&gt;</span>
								<span class="code-tag">&lt;vm:outbound-endpoint path = <span class="code-quote">"queue.out"</span> connector-ref = <span class="code-quote">"VMQueue"</span>/&gt;</span>
								<span class="code-tag">&lt;/pass-through-router&gt;</span>
								<span class="code-tag">&lt;/outbound&gt;</span>
								<span class="code-tag">&lt;/service&gt;</span>
						</pre>
				</div>
		</div>
<img src ="http://www.blogjava.net/libin2722/aggbug/295692.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2009-09-19 21:53 <a href="http://www.blogjava.net/libin2722/articles/295692.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Mule web service调用中的复杂类型传递</title><link>http://www.blogjava.net/libin2722/articles/295689.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Sat, 19 Sep 2009 12:42:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/295689.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/295689.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/295689.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/295689.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/295689.html</trackback:ping><description><![CDATA[
		<div id="header">
				<div id="blog_site_nav">  官网上很辛苦在一个旮旯里找到如何向 Mule暴露的axis web service 传递复杂数据类型 ，http://www.mulesource.org/pages/viewpage.action?pageId=4678， 官网上只提供了原理，自己补充了一下客户端测试代码,部分服务类做了修改。 <br />    <br />  类清单: <br />  Person: 数据类，测试复杂数据类型的传递 <br />  PersonService: 服务接口类 <br />  PersonServiceImpl: 服务实现类。 <br />  PersonServiceLaucher: Mule服务器启动类 <br />  PersonClient: 客户端测试类。 <br />  person-config.xml, Mule 配置，其中将 PersonServiceImpl 暴露为一个axis1.4的服务。 <br /><br />1. Person数据类 <br /></div>
		</div>
		<div id="page">
				<div class="clearfix" id="content">
						<div id="main">
								<div class="blog_main">
										<div class="blog_content">
												<div class="dp-highlighter">
														<div class="bar">
																<div class="tools">Java代码 <a title="复制代码" onclick="dp.sh.Toolbar.CopyToClipboard(this);return false;" href="http://raymondhekk.javaeye.com/blog/300604#"><img alt="复制代码" src="http://raymondhekk.javaeye.com/images/icon_copy.gif" /></a></div>
														</div>
														<ol class="dp-j">
																<li>
																		<span>
																				<span> </span>
																				<span class="keyword">
																						<strong>
																								<font color="#7f0055">public</font>
																						</strong>
																				</span>
																				<span> </span>
																				<span class="keyword">
																						<strong>
																								<font color="#7f0055">class</font>
																						</strong>
																				</span>
																				<span> Person    </span>
																		</span>
																</li>
																<li>
																		<span>  {   </span>
																</li>
																<li>
																		<span>
																		</span>
																		<span class="keyword">
																				<strong>
																						<font color="#7f0055">private</font>
																				</strong>
																		</span>
																		<span> String name;   </span>
																</li>
																<li>
																		<span>
																		</span>
																		<span class="keyword">
																				<strong>
																						<font color="#7f0055">private</font>
																				</strong>
																		</span>
																		<span> String surname;   </span>
																</li>
																<li>
																		<span>
																		</span>
																		<span class="keyword">
																				<strong>
																						<font color="#7f0055">private</font>
																				</strong>
																		</span>
																		<span> Date registerDate = </span>
																		<span class="keyword">
																				<strong>
																						<font color="#7f0055">new</font>
																				</strong>
																		</span>
																		<span> Date();   </span>
																</li>
																<li>
																		<span>
																		</span>
																		<span class="keyword">
																				<strong>
																						<font color="#7f0055">private</font>
																				</strong>
																		</span>
																		<span> </span>
																		<span class="keyword">
																				<strong>
																						<font color="#7f0055">int</font>
																				</strong>
																		</span>
																		<span> age = </span>
																		<span class="number">
																				<font color="#c00000">20</font>
																		</span>
																		<span>;   </span>
																</li>
																<li>
																		<span>   ...  </span>
																</li>
														</ol>
												</div>
												<pre class="java" style="DISPLAY: none" name="code">  public class Person 
   {
	private String name;
	private String surname;
	private Date registerDate = new Date();
	private int age = 20;
    ...</pre>
												<br />
												<br />2.  服务接口类 <br /><div class="dp-highlighter"><div class="bar"><div class="tools">Java代码 <a title="复制代码" onclick="dp.sh.Toolbar.CopyToClipboard(this);return false;" href="http://raymondhekk.javaeye.com/blog/300604#"><img alt="复制代码" src="http://raymondhekk.javaeye.com/images/icon_copy.gif" /></a></div></div><ol class="dp-j"><li><span><span> </span><span class="keyword"><strong><font color="#7f0055">public</font></strong></span><span> </span><span class="keyword"><strong><font color="#7f0055">interface</font></strong></span><span> PersonService {      </span></span></li><li><span>String printPerson(Person person) ;    </span></li><li><span>Person createPerson(String name,String surname,</span><span class="keyword"><strong><font color="#7f0055">int</font></strong></span><span> age);       </span></li><li><span>    Person[] batchCreatePerson(String namePattern);   </span></li><li><span> }  </span></li></ol></div><pre class="java" style="DISPLAY: none" name="code">  public interface PersonService {	
	String printPerson(Person person) ;	
	Person createPerson(String name,String surname,int age);	
 	Person[] batchCreatePerson(String namePattern);
  }</pre><br /><br />3. 实现类： <br /><div class="dp-highlighter"><div class="bar"><div class="tools">Java代码 <a title="复制代码" onclick="dp.sh.Toolbar.CopyToClipboard(this);return false;" href="http://raymondhekk.javaeye.com/blog/300604#"><img alt="复制代码" src="http://raymondhekk.javaeye.com/images/icon_copy.gif" /></a></div></div><ol class="dp-j"><li><span><span class="keyword"><strong><font color="#7f0055">package</font></strong></span><span> demo.mule.person;   </span></span></li><li><span>  </span></li><li><span></span><span class="keyword"><strong><font color="#7f0055">public</font></strong></span><span> </span><span class="keyword"><strong><font color="#7f0055">class</font></strong></span><span> PersonServiceImpl </span><span class="keyword"><strong><font color="#7f0055">implements</font></strong></span><span> PersonService {   </span></li><li><span>    </span><span class="keyword"><strong><font color="#7f0055">public</font></strong></span><span> String printPerson(Person person) {         </span></li><li><span>        </span><span class="keyword"><strong><font color="#7f0055">return</font></strong></span><span> </span><span class="string"><font color="#0000ff">"person:name="</font></span><span> + person.getName() +</span><span class="string"><font color="#0000ff">",surname="</font></span><span> + person.getSurname();   </span></li><li><span>    }   </span></li><li><span>       </span></li><li><span>    </span><span class="comment"><font color="#008200">/** </font></span> 
</li><li><span><span class="comment"><font color="#008200">     * test return a complex type by web service </font></span> </span></li><li><span><span class="comment"><font color="#008200">     */</font></span><span>  </span></span></li><li><span>    </span><span class="keyword"><strong><font color="#7f0055">public</font></strong></span><span> Person createPerson(String name, String surname,</span><span class="keyword"><strong><font color="#7f0055">int</font></strong></span><span> age) {   </span></li><li><span>        Person p = </span><span class="keyword"><strong><font color="#7f0055">new</font></strong></span><span> Person(name,surname);   </span></li><li><span>        p.setAge(age);   </span></li><li><span>        System.out.println(</span><span class="string"><font color="#0000ff">"a person is created:"</font></span><span> + p.getName());   </span></li><li><span>        </span><span class="keyword"><strong><font color="#7f0055">return</font></strong></span><span> p;   </span></li><li><span>    }   </span></li><li><span>       </span></li><li><span>    </span><span class="keyword"><strong><font color="#7f0055">public</font></strong></span><span> Person[] batchCreatePerson(String namePattern) {   </span></li><li><span>        Person[] persons = </span><span class="keyword"><strong><font color="#7f0055">new</font></strong></span><span> Person[</span><span class="number"><font color="#c00000">3</font></span><span>];   </span></li><li><span>        </span><span class="keyword"><strong><font color="#7f0055">for</font></strong></span><span> (</span><span class="keyword"><strong><font color="#7f0055">int</font></strong></span><span> i = </span><span class="number"><font color="#c00000">0</font></span><span>; i &lt; persons.length; i++) {   </span></li><li><span>            Person p = </span><span class="keyword"><strong><font color="#7f0055">new</font></strong></span><span> Person(namePattern + i,namePattern + i);   </span></li><li><span>            p.setAge( </span><span class="number"><font color="#c00000">20</font></span><span> + i );   </span></li><li><span>            persons[i] = p;   </span></li><li><span>        }   </span></li><li><span>        </span><span class="keyword"><strong><font color="#7f0055">return</font></strong></span><span> persons;   </span></li><li><span>    }   </span></li><li><span>}  </span></li></ol></div><pre class="java" style="DISPLAY: none" name="code">package demo.mule.person;

public class PersonServiceImpl implements PersonService {
	public String printPerson(Person person) {		
		return "person:name=" + person.getName() +",surname=" + person.getSurname();
	}
	
	/**
	 * test return a complex type by web service
	 */
	public Person createPerson(String name, String surname,int age) {
		Person p = new Person(name,surname);
		p.setAge(age);
		System.out.println("a person is created:" + p.getName());
		return p;
	}
	
	public Person[] batchCreatePerson(String namePattern) {
		Person[] persons = new Person[3];
		for (int i = 0; i &lt; persons.length; i++) {
			Person p = new Person(namePattern + i,namePattern + i);
			p.setAge( 20 + i );
			persons[i] = p;
		}
		return persons;
	}
}</pre><br /><br />4. person-config.xml <br /><div class="dp-highlighter"><div class="bar"><div class="tools">Xml代码 <a title="复制代码" onclick="dp.sh.Toolbar.CopyToClipboard(this);return false;" href="http://raymondhekk.javaeye.com/blog/300604#"><img alt="复制代码" src="http://raymondhekk.javaeye.com/images/icon_copy.gif" /></a></div></div><ol class="dp-xml"><li><span><span>  </span><strong><font color="#006699"><span class="tag">&lt;?</span><span class="tag-name">xml</span></font></strong><span> </span><span class="attribute"><font color="#ff0000">version</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"1.0"</font></span><span> </span><span class="attribute"><font color="#ff0000">encoding</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"UTF-8"</font></span><span class="tag"><strong><font color="#006699">?&gt;</font></strong></span><span>  </span></span></li><li><span>&lt;!DOCTYPE mule-configuration PUBLIC "-//MuleSource //DTD mule-configuration XML V1.0//EN" "http://mule.mulesource.org/dtds/mule-configuration.dtd"</span><span class="tag"><strong><font color="#006699">&gt;</font></strong></span><span>  </span></li><li><span></span><strong><font color="#006699"><span class="tag">&lt;</span><span class="tag-name">mule-configuration</span></font></strong><span> </span><span class="attribute"><font color="#ff0000">id</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"mule-test"</font></span><span> </span><span class="attribute"><font color="#ff0000">version</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"1.0"</font></span><span class="tag"><strong><font color="#006699">&gt;</font></strong></span><span>  </span></li><li><span>    </span><strong><font color="#006699"><span class="tag">&lt;</span><span class="tag-name">model</span></font></strong><span> </span><span class="attribute"><font color="#ff0000">name</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"personService"</font></span><span class="tag"><strong><font color="#006699">&gt;</font></strong></span><span>  </span></li><li><span>        </span><span class="comments"><font color="#008200">&lt;!-- test: http://localhost:8082/services/personService?method=createPerson --&gt;</font></span><span>              </span></li><li><span>        </span><strong><font color="#006699"><span class="tag">&lt;</span><span class="tag-name">mule-descriptor</span></font></strong><span> </span><span class="attribute"><font color="#ff0000">name</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"personService"</font></span><span> </span><span class="attribute"><font color="#ff0000">implementation</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"demo.mule.person.PersonServiceImpl"</font></span><span class="tag"><strong><font color="#006699">&gt;</font></strong></span><span>  </span></li><li><span>            </span><strong><font color="#006699"><span class="tag">&lt;</span><span class="tag-name">inbound-router</span><span class="tag">&gt;</span></font></strong><span>  </span></li><li><span>                </span><strong><font color="#006699"><span class="tag">&lt;</span><span class="tag-name">endpoint</span></font></strong><span> </span><span class="attribute"><font color="#ff0000">address</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"axis:http://localhost:8082/services"</font></span><strong><font color="#006699"><span class="tag">&gt;</span><span class="tag">&lt;/</span><span class="tag-name">endpoint</span><span class="tag">&gt;</span></font></strong><span>  </span></li><li><span>            </span><strong><font color="#006699"><span class="tag">&lt;/</span><span class="tag-name">inbound-router</span><span class="tag">&gt;</span></font></strong><span>        </span></li><li><span>            &lt;!-- not nessesary    </span></li><li><span>            </span><strong><font color="#006699"><span class="tag">&lt;</span><span class="tag-name">properties</span><span class="tag">&gt;</span></font></strong><span>  </span></li><li><span>                </span><strong><font color="#006699"><span class="tag">&lt;</span><span class="tag-name">property</span></font></strong><span> </span><span class="attribute"><font color="#ff0000">name</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"style"</font></span><span> </span><span class="attribute"><font color="#ff0000">value</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"wrapped"</font></span><span class="tag"><strong><font color="#006699">/&gt;</font></strong></span><span>  </span></li><li><span>                </span><strong><font color="#006699"><span class="tag">&lt;</span><span class="tag-name">property</span></font></strong><span> </span><span class="attribute"><font color="#ff0000">name</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"use"</font></span><span> </span><span class="attribute"><font color="#ff0000">value</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"literal"</font></span><span class="tag"><strong><font color="#006699">/&gt;</font></strong></span><span>  </span></li><li><span>            </span><strong><font color="#006699"><span class="tag">&lt;/</span><span class="tag-name">properties</span><span class="tag">&gt;</span></font></strong><span>        </span></li><li><span>            --</span><span class="tag"><strong><font color="#006699">&gt;</font></strong></span><span>  </span></li><li><span>        </span><strong><font color="#006699"><span class="tag">&lt;/</span><span class="tag-name">mule-descriptor</span><span class="tag">&gt;</span></font></strong><span>               </span></li><li><span>    </span><strong><font color="#006699"><span class="tag">&lt;/</span><span class="tag-name">model</span><span class="tag">&gt;</span></font></strong><span>  </span></li><li><span></span><strong><font color="#006699"><span class="tag">&lt;/</span><span class="tag-name">mule-configuration</span><span class="tag">&gt;</span></font></strong><span>  </span></li></ol></div><pre class="xml" style="DISPLAY: none" name="code">  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE mule-configuration PUBLIC "-//MuleSource //DTD mule-configuration XML V1.0//EN" "http://mule.mulesource.org/dtds/mule-configuration.dtd"&gt;
&lt;mule-configuration id="mule-test" version="1.0"&gt;
	&lt;model name="personService"&gt;
		&lt;!-- test: http://localhost:8082/services/personService?method=createPerson --&gt;			
		&lt;mule-descriptor name="personService" implementation="demo.mule.person.PersonServiceImpl"&gt;
			&lt;inbound-router&gt;
				&lt;endpoint address="axis:http://localhost:8082/services"&gt;&lt;/endpoint&gt;
			&lt;/inbound-router&gt;		
			&lt;!-- not nessesary 
			&lt;properties&gt;
				&lt;property name="style" value="wrapped"/&gt;
				&lt;property name="use" value="literal"/&gt;
			&lt;/properties&gt;		
			--&gt;
		&lt;/mule-descriptor&gt;			
	&lt;/model&gt;
&lt;/mule-configuration&gt;</pre><br /><br /><br />5. server启动 <br /><div class="dp-highlighter"><div class="bar"><div class="tools">Java代码 <a title="复制代码" onclick="dp.sh.Toolbar.CopyToClipboard(this);return false;" href="http://raymondhekk.javaeye.com/blog/300604#"><img alt="复制代码" src="http://raymondhekk.javaeye.com/images/icon_copy.gif" /></a></div></div><ol class="dp-j"><li><span><span>  </span><span class="keyword"><strong><font color="#7f0055">public</font></strong></span><span> </span><span class="keyword"><strong><font color="#7f0055">class</font></strong></span><span> PersonServiceLaucher {   </span></span></li><li><span></span><span class="keyword"><strong><font color="#7f0055">public</font></strong></span><span> </span><span class="keyword"><strong><font color="#7f0055">static</font></strong></span><span> </span><span class="keyword"><strong><font color="#7f0055">void</font></strong></span><span> main(String[] args) </span><span class="keyword"><strong><font color="#7f0055">throws</font></strong></span><span> ConfigurationException {   </span></li><li><span>    MuleXmlConfigurationBuilder muleXmlConfigurationBuilder = </span><span class="keyword"><strong><font color="#7f0055">new</font></strong></span><span> MuleXmlConfigurationBuilder();   </span></li><li><span>    UMOManager manager = muleXmlConfigurationBuilder.configure(</span><span class="string"><font color="#0000ff">"demo/mule/person/person-config.xml"</font></span><span>);   </span></li><li><span>}   </span></li></ol></div><pre class="java" style="DISPLAY: none" name="code">   public class PersonServiceLaucher {
	public static void main(String[] args) throws ConfigurationException {
		MuleXmlConfigurationBuilder muleXmlConfigurationBuilder = new MuleXmlConfigurationBuilder();
		UMOManager manager = muleXmlConfigurationBuilder.configure("demo/mule/person/person-config.xml");
	}
}</pre><br /><br /><br />6. 测试类 <br /><div class="dp-highlighter"><div class="bar"><div class="tools">Java代码 <a title="复制代码" onclick="dp.sh.Toolbar.CopyToClipboard(this);return false;" href="http://raymondhekk.javaeye.com/blog/300604#"><img alt="复制代码" src="http://raymondhekk.javaeye.com/images/icon_copy.gif" /></a></div></div><ol class="dp-j"><li><span><span> </span><span class="keyword"><strong><font color="#7f0055">public</font></strong></span><span> </span><span class="keyword"><strong><font color="#7f0055">class</font></strong></span><span> PersonClient {       </span></span></li><li><span>    </span><span class="keyword"><strong><font color="#7f0055">private</font></strong></span><span> MuleClient muleClient ;    </span></li><li><span>    </span><span class="keyword"><strong><font color="#7f0055">public</font></strong></span><span> PersonClient() {   </span></li><li><span>        </span><span class="keyword"><strong><font color="#7f0055">try</font></strong></span><span> {   </span></li><li><span>            muleClient = </span><span class="keyword"><strong><font color="#7f0055">new</font></strong></span><span> MuleClient();   </span></li><li><span>        } </span><span class="keyword"><strong><font color="#7f0055">catch</font></strong></span><span> (UMOException e) {         </span></li><li><span>            e.printStackTrace();   </span></li><li><span>        }   </span></li><li><span>    }   </span></li><li><span>  </span></li><li><span>    </span><span class="keyword"><strong><font color="#7f0055">public</font></strong></span><span> </span><span class="keyword"><strong><font color="#7f0055">void</font></strong></span><span> testPrintPerson() </span><span class="keyword"><strong><font color="#7f0055">throws</font></strong></span><span> Exception {   </span></li><li><span>           </span></li><li><span>        Person person = </span><span class="keyword"><strong><font color="#7f0055">new</font></strong></span><span> Person(</span><span class="string"><font color="#0000ff">"David"</font></span><span>,</span><span class="string"><font color="#0000ff">"Jones"</font></span><span>);   </span></li><li><span>        UMOMessage msg = </span><span class="keyword"><strong><font color="#7f0055">new</font></strong></span><span> MuleMessage(person );   </span></li><li><span>        UMOMessage message = muleClient.send(</span><span class="string"><font color="#0000ff">"axis:http://localhost:8082/services/personService?method=printPerson"</font></span><span>,msg);   </span></li><li><span>           </span></li><li><span>        System.out.println(</span><span class="string"><font color="#0000ff">"message:"</font></span><span> + message.getPayloadAsString());   </span></li><li><span>    }   </span></li><li><span>       </span></li><li><span>    </span><span class="keyword"><strong><font color="#7f0055">public</font></strong></span><span> </span><span class="keyword"><strong><font color="#7f0055">void</font></strong></span><span> testCreatePerson() </span><span class="keyword"><strong><font color="#7f0055">throws</font></strong></span><span> Exception {   </span></li><li><span>        Object[] args = </span><span class="keyword"><strong><font color="#7f0055">new</font></strong></span><span> Object[]{</span><span class="string"><font color="#0000ff">"小龙"</font></span><span>,</span><span class="string"><font color="#0000ff">"李"</font></span><span>, </span><span class="keyword"><strong><font color="#7f0055">new</font></strong></span><span> Integer(</span><span class="number"><font color="#c00000">23</font></span><span>)};   </span></li><li><span>        UMOMessage msg = </span><span class="keyword"><strong><font color="#7f0055">new</font></strong></span><span> MuleMessage(args );   </span></li><li><span>        UMOMessage message = muleClient.send(</span><span class="string"><font color="#0000ff">"axis:http://localhost:8082/services/personService?method=createPerson"</font></span><span>,msg);   </span></li><li><span>       </span></li><li><span>        Person p = (Person)message.getPayload();   </span></li><li><span>        System.out.println(</span><span class="string"><font color="#0000ff">"message:"</font></span><span> + message.getPayloadAsString());   </span></li><li><span>        System.out.println(</span><span class="string"><font color="#0000ff">"payload:"</font></span><span> + p.getName() +</span><span class="string"><font color="#0000ff">","</font></span><span> + p.getSurname() +</span><span class="string"><font color="#0000ff">","</font></span><span> + p.getAge());   </span></li><li><span>    }   </span></li><li><span>       </span></li><li><span>    </span><span class="keyword"><strong><font color="#7f0055">public</font></strong></span><span> </span><span class="keyword"><strong><font color="#7f0055">void</font></strong></span><span> testBatchCreatePerson() </span><span class="keyword"><strong><font color="#7f0055">throws</font></strong></span><span> UMOException {   </span></li><li><span>        Object[] args = </span><span class="keyword"><strong><font color="#7f0055">new</font></strong></span><span> Object[]{</span><span class="string"><font color="#0000ff">"Admin"</font></span><span>};   </span></li><li><span>        UMOMessage msg = </span><span class="keyword"><strong><font color="#7f0055">new</font></strong></span><span> MuleMessage(args );   </span></li><li><span>        UMOMessage message = muleClient.send(</span><span class="string"><font color="#0000ff">"axis:http://localhost:8082/services/personService?method=batchCreatePerson"</font></span><span>,msg);   </span></li><li><span>           </span></li><li><span>        Person[] ps = (Person[])message.getPayload();   </span></li><li><span>        System.out.println(</span><span class="string"><font color="#0000ff">"persons:"</font></span><span> + ps.length);   </span></li><li><span>        </span><span class="keyword"><strong><font color="#7f0055">for</font></strong></span><span> (</span><span class="keyword"><strong><font color="#7f0055">int</font></strong></span><span> i = </span><span class="number"><font color="#c00000">0</font></span><span>; i &lt; ps.length; i++) {   </span></li><li><span>            Person p = ps[i];   </span></li><li><span>            System.out.println(</span><span class="string"><font color="#0000ff">"person:"</font></span><span> + p.getName() +</span><span class="string"><font color="#0000ff">","</font></span><span> + p.getSurname() +</span><span class="string"><font color="#0000ff">","</font></span><span> + p.getAge());   </span></li><li><span>        }          </span></li><li><span>    }   </span></li><li><span>    </span><span class="keyword"><strong><font color="#7f0055">public</font></strong></span><span> </span><span class="keyword"><strong><font color="#7f0055">static</font></strong></span><span> </span><span class="keyword"><strong><font color="#7f0055">void</font></strong></span><span> main(String[] args) </span><span class="keyword"><strong><font color="#7f0055">throws</font></strong></span><span> Exception {   </span></li><li><span>        PersonClient personClient = </span><span class="keyword"><strong><font color="#7f0055">new</font></strong></span><span> PersonClient();   </span></li><li><span>        personClient.testPrintPerson();   </span></li><li><span>        personClient.testCreatePerson();           </span></li><li><span>        personClient.testBatchCreatePerson();   </span></li><li><span>    }   </span></li><li><span>}  </span></li></ol></div><pre class="java" style="DISPLAY: none" name="code"> public class PersonClient {	
	private MuleClient muleClient ;	
	public PersonClient() {
		try {
			muleClient = new MuleClient();
		} catch (UMOException e) {		
			e.printStackTrace();
		}
	}

	public void testPrintPerson() throws Exception {
		
		Person person = new Person("David","Jones");
		UMOMessage msg = new MuleMessage(person );
		UMOMessage message = muleClient.send("axis:http://localhost:8082/services/personService?method=printPerson",msg);
		
		System.out.println("message:" + message.getPayloadAsString());
	}
	
	public void testCreatePerson() throws Exception {
		Object[] args = new Object[]{"小龙","李", new Integer(23)};
		UMOMessage msg = new MuleMessage(args );
		UMOMessage message = muleClient.send("axis:http://localhost:8082/services/personService?method=createPerson",msg);
	
		Person p = (Person)message.getPayload();
		System.out.println("message:" + message.getPayloadAsString());
		System.out.println("payload:" + p.getName() +"," + p.getSurname() +"," + p.getAge());
	}
	
	public void testBatchCreatePerson() throws UMOException {
		Object[] args = new Object[]{"Admin"};
		UMOMessage msg = new MuleMessage(args );
		UMOMessage message = muleClient.send("axis:http://localhost:8082/services/personService?method=batchCreatePerson",msg);
		
		Person[] ps = (Person[])message.getPayload();
		System.out.println("persons:" + ps.length);
		for (int i = 0; i &lt; ps.length; i++) {
			Person p = ps[i];
			System.out.println("person:" + p.getName() +"," + p.getSurname() +"," + p.getAge());
		}		
	}
	public static void main(String[] args) throws Exception {
		PersonClient personClient = new PersonClient();
		personClient.testPrintPerson();
		personClient.testCreatePerson();		
		personClient.testBatchCreatePerson();
	}
}</pre><br /><br /><br />测试过程： <br />1） 启动Mule服务容器 <br />2） 执行PersonClient <br /><br /><br />总结： <br />  1) Mule暴露POJO为一个服务还是很简单的, 配置非常少 <br />  2) 传递和返回Java复杂数据类型，自定义数据类型都非常方便。不过，客户端需要明确知道每个方法传递的参数个数和类型，以及返回的参数类型，并且需要自己type cast。 在具体项目中，可以自己再做一层封装或用AOP， 以本地调用的方式调用 mule 的web service。 <br /></div>
								</div>
						</div>
				</div>
		</div>
<img src ="http://www.blogjava.net/libin2722/aggbug/295689.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2009-09-19 20:42 <a href="http://www.blogjava.net/libin2722/articles/295689.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>(原)Axis2 OM 模式</title><link>http://www.blogjava.net/libin2722/articles/294572.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Thu, 10 Sep 2009 05:33:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/294572.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/294572.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/294572.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/294572.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/294572.html</trackback:ping><description><![CDATA[只是个简单的例子，能说明问题就行。<br />服务端：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> com.ws.server;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.util.Iterator;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> javax.xml.stream.XMLStreamException;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.axiom.om.OMElement;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.axiom.om.OMNode;<br /></span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /> * @company LuckyStar 工作室<br /> *<br /> * @description Axis2 WebService 服务端 (OM模式)<br /> *<br /> * </span><span style="color: rgb(128, 128, 128);">@author</span><span style="color: rgb(0, 128, 0);"> 李彬<br /> *<br /> * @date 2009-8-12<br /> </span><span style="color: rgb(0, 128, 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);"> MyServer {<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> OMElement invoke(OMElement element) </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> XMLStreamException{<br />        <br />        element.build();<br />        <br />        Iterator</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">OMNode</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> iterator </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> element.getChildElements();<br />        </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(iterator.hasNext()){<br />            OMNode node </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> iterator.next();<br />            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (node.getType() </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> OMNode.ELEMENT_NODE) {<br />                OMElement omElement </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (OMElement)node;<br />                </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (omElement.getLocalName().equals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">value</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)) {<br />                    String temp </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> omElement.getText().trim();<br />                    System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Service Value1:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">temp);<br />                }</span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(omElement.getLocalName().equals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">value2</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)){<br />                    String temp </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> omElement.getText().trim();<br />                    System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Service Value2:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">temp);<br />                }<br />            }<br />        }<br />        <br />        element.detach();<br />        <br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> element;<br />    }<br />    <br />}<br /></span></div><br />服务端配置文件 META-INF/services.xml<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><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);">serviceGroup</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);">="myservice"</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);">parameter </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="ServiceClass"</span><span style="color: rgb(255, 0, 0);"> locked</span><span style="color: rgb(0, 0, 255);">="false"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">com.ws.server.MyServer</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">parameter</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);">="invoke"</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);">messageReceiver </span><span style="color: rgb(255, 0, 0);">class</span><span style="color: rgb(0, 0, 255);">="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">messageReceiver</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);">actionMapping</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">urn:invoke</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">actionMapping</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);">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);">serviceGroup</span><span style="color: rgb(0, 0, 255);">&gt;</span></div><br />打包（aar包）放入%tomcat_home%/webapps/axis2/WEB-INF/service下，然后启动服务就oK了<br /><br />下面是客户端<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> com.ws.client;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> javax.xml.namespace.QName;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.axiom.om.OMAbstractFactory;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.axiom.om.OMElement;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.axiom.om.OMFactory;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.axiom.om.OMNamespace;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.axis2.AxisFault;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.axis2.addressing.EndpointReference;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.axis2.client.Options;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.axis2.rpc.client.RPCServiceClient;<br /></span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /> * @company LuckyStar 工作室<br /> *<br /> * @description Axis2 WebService 客户端 (OM模式)<br /> *<br /> * </span><span style="color: rgb(128, 128, 128);">@author</span><span style="color: rgb(0, 128, 0);"> 李彬<br /> *<br /> * @date 2009-8-12<br /> </span><span style="color: rgb(0, 128, 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);"> WsTest {<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);">static</span><span style="color: rgb(0, 0, 0);"> OMElement getInvokeOMElement(){<br />        OMFactory factory </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> OMAbstractFactory.getOMFactory();<br />        OMNamespace namespace </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> factory.createOMNamespace(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">http://www.liwu.com</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);">liwu</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        OMElement method </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> factory.createOMElement(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">invoke</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,namespace);<br />        OMElement value </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> factory.createOMElement(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">value</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,namespace);<br />        value.addChild(factory.createOMText(value, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Hello terry!!!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />        <br />        OMElement value2 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> factory.createOMElement(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">value</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,namespace);<br />        value2.addChild(factory.createOMText(value2, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Hello wuxin!!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />        <br />        method.addChild(value);<br />        <br />        method.addChild(value2);<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> method;<br />    }<br />    <br />    @SuppressWarnings(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">unchecked</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);">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 />        EndpointReference endpointReference </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);"> EndpointReference(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">http://localhost/axis2/services/myservice</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        OMElement method </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> getInvokeOMElement();<br />        Options options </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);"> Options();<br />        options.setTo(endpointReference);<br />        ServiceClient client;<br />        </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {<br />            client </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);"> ServiceClient();<br />            client.setOptions(options);<br />            OMElement value </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> client.sendReceive(method);<br />            System.out.println(value);<br />            System.out.println();<br />            Iterator</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">OMNode</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> iterator </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> value.getChildElements();<br />            </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(iterator.hasNext()){<br />                OMNode node </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> iterator.next();<br />                </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (node.getType() </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> OMNode.ELEMENT_NODE) {<br />                    OMElement omElement </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (OMElement)node;<br />                    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (omElement.getLocalName().equals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">value</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)) {<br />                        String temp </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> omElement.getText().trim();<br />                        System.out.println(temp);<br />                    }<br />                }<br />            }<br />        } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (AxisFault e) {<br />            e.printStackTrace();<br />        }<br />    }<br />}<br /></span></div><br /><br /><br /><br /><img src ="http://www.blogjava.net/libin2722/aggbug/294572.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2009-09-10 13:33 <a href="http://www.blogjava.net/libin2722/articles/294572.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Axis2快速上手指南</title><link>http://www.blogjava.net/libin2722/articles/286732.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Tue, 14 Jul 2009 09:11:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/286732.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/286732.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/286732.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/286732.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/286732.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 原文链接:http://ws.apache.org/axis2/1_1_1/quickstartguide.html本指南的目的是让你尽可能快的创建使用Axis2的服务和客户端，我们将使用一个简单的StockQuote服务并显示给你一些创建和部署它的不同的方式，以及快速的看看Axis2自带的一些工具，然后我们将看看创建访问这些服务的客户端。内容Java代码 介绍  做好准备  Axis2服...&nbsp;&nbsp;<a href='http://www.blogjava.net/libin2722/articles/286732.html'>阅读全文</a><img src ="http://www.blogjava.net/libin2722/aggbug/286732.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2009-07-14 17:11 <a href="http://www.blogjava.net/libin2722/articles/286732.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>(转载)使用Axis2的底层API开发Web Service</title><link>http://www.blogjava.net/libin2722/articles/214223.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Fri, 11 Jul 2008 04:26:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/214223.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/214223.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/214223.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/214223.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/214223.html</trackback:ping><description><![CDATA[<div><font size="2"><em>本文是在理解官方指南的基础上，用实例实现Axis2提供的4种调用机制，并给出测试结果。</em><br />
author: ZJ 07-3-13<br />
Blog: </font><font size="2"><a href="http://zhangjunhd.blog.51cto.com/" target="_blank">http://zhangjunhd.blog.51cto.com/</a></font></div>
<div>&nbsp;</div>
<div><font size="2"><strong>1．使用Axis2的底层API开发Web Service Server端</strong><br />
1.1创建一个WebService(取名为MyService)<br />
&nbsp;&nbsp;&nbsp; 在MyService中有两个operations,如下所示。</font></div>
<div style="border: 1px solid #aaaaaa; padding: 5px; background-color: #d3d3d3;">
<div><font size="2">public void ping(OMElement element){}//IN-ONLY模式。仅仅接收OMElement，并对其处理。<br />
public OMElement echo(OMElement element){}//IN_OUT模式。接收OMElemen，并返回OMElement。</font></div>
</div>
<div>&nbsp;</div>
<div><font size="2">1.2如何写Web Service<br />
1）创建实现服务的类。</font></div>
<div><font size="2">2）创建services.xml来解析这个Web Service。</font></div>
<div><font size="2">3）将其打包成一个*.aar文档（Axis Archive）。</font></div>
<div><font size="2">4）部署Web Service。</font></div>
<div>&nbsp;</div>
<div><font size="2">1.2.1 创建实现服务的类<br />
&nbsp;&nbsp;&nbsp; 此类中提供的方法必须与Web Service（在services.xml中声明）中的operations对应。除非你提供了数据绑定，否则所有的方法只能接收一个参数，其类型为OMElement。</font></div>
<div style="border: 1px solid #aaaaaa; padding: 5px; background-color: #d3d3d3;">
<div><font size="2">public class MyService{<br />
&nbsp; public void ping(OMElement element){...}<br />
&nbsp; public OMElement echo(OMElement element){...}<br />
}</font></div>
</div>
<div><font style="background-color: #ffffff;" size="2"><u>MyService.java</u></font></div>
<div style="border: 1px solid #aaaaaa; padding: 5px; background-color: #d3d3d3;">
<div><font size="2">package userguide.example1;</font></div>
<div><font size="2">import org.apache.axiom.om.OMElement;<br />
import org.apache.axis2.AxisFault;<br />
import javax.xml.stream.XMLStreamException;</font></div>
<div><font size="2">public class MyService {<br />
&nbsp;&nbsp;&nbsp; public OMElement echo(OMElement element) throws XMLStreamException {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Praparing the OMElement so that it can be attached to another OM Tree.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //First the OMElement should be completely build in case it is not fully built and still<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //some of the xml is in the stream.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; element.build();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Secondly the OMElement should be detached from the current OMTree so that it can<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; // be attached some other OM Tree. Once detached the OmTree will remove its<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // connections to this OMElement.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; element.detach();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return element;<br />
&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; public void ping(OMElement element) throws XMLStreamException {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Do some processing<br />
&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; public void pingF(OMElement element) throws AxisFault{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new AxisFault("Fault being thrown");<br />
&nbsp;&nbsp;&nbsp; }<br />
}</font></div>
</div>
<div>&nbsp;</div>
<div><font size="2">1.2.2 创建services.xml<br />
&nbsp;&nbsp;&nbsp; Axis2使用services.xml来充当一个Web Servicea的配置文件。每一个使用Axis2部署的Web Service都必须拥有一个services.xml。</font></div>
<div style="border: 1px solid #aaaaaa; padding: 5px; background-color: #d3d3d3;">
<div><font size="2">&lt;services&gt;<br />
&nbsp; &lt;description&gt;<br />
&nbsp;&nbsp;&nbsp; This is a sample Web Service with two operations,echo and ping.<br />
&nbsp; &lt;/description&gt;<br />
&nbsp; &lt;parameter name=&#8221;ServiceClass&#8221; locked=&#8221;false&#8221;&gt;<br />
&nbsp; userguide.example1.MyService<br />
&nbsp; &lt;/parameter&gt;<br />
&nbsp; &lt;operation name=&#8221;echo&#8221;&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;messageReceiver class=&#8221;org.apache.axis2.receivers.RawXMLINOutMessageReceiver&#8221;/&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;actionMapping&gt;urn:echo&lt;/actionMapping&gt;<br />
&nbsp; &lt;/operation&gt;<br />
&nbsp; &lt;operation name=&#8221;ping&#8221;&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;messageReceiver class=&#8221;org.apache.receivers.RawXMLINOnlyMessageReceiver&#8221;/&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;actionMapping&gt;urn:ping&lt;/actionMapping&gt;<br />
&nbsp; &lt;/operation&gt;<br />
&lt;/service&gt;</font></div>
</div>
<div><font style="background-color: #ffffff;" size="2">注：The actionMapping is required only if you want to enable WS-Addressing.<br />
&nbsp;&nbsp;&nbsp; 可以创建一个services.xml，其中包含一组服务。这样在运行期，你可以在这些服务间共享信息。</font></div>
<div style="border: 1px solid #aaaaaa; padding: 5px; background-color: #d3d3d3;">
<div><font size="2">&lt;serviceGroup&gt;<br />
&nbsp; &lt;service name=&#8221;Service1&#8221;&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;!--details for Services1--&gt;<br />
&nbsp; &lt;/service&gt;<br />
&lt;service name=&#8221;Service2&#8221;&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;!--details for Services2--&gt;<br />
&nbsp; &lt;/service&gt;<br />
&nbsp; &lt;module ref=&#8221;ModuleName&#8221;/&gt;<br />
&nbsp; &lt;parameter name=&#8221;serviceGroupParam1&#8221; locked=&#8221;false&#8221;&gt;value1&lt;/parameter&gt;<br />
&lt;/serviceGroup&gt;</font></div>
</div>
<div><font style="background-color: #ffffff;" size="2">注：name of the service is a compulsory attribute.</font></div>
<div>&nbsp;</div>
<div><font size="2">1.2.3打包与部署<br />
&nbsp;&nbsp;&nbsp; 这里不再详述，参见《</font><a class="subject" href="http://zhangjunhd.blog.51cto.com/blog/113473/23690" target="_blank"><font color="#000000" size="2">基于Tomcat5.0和Axis2开发Web Service应用实例</font></a><font size="2"> 》。</font></div>
<div>&nbsp;</div>
<div><font size="2"><strong>2．使用Axis2底层APIs实现Web Service客户端</strong><br />
2.1ClientUtil<br />
&nbsp;&nbsp;&nbsp; 创建一个客户端通用的SOAP包装Util文件。封装"getEchoOMElement"和"getPingOMElement"分别对应"echo"和"ping"这两个operation。</font></div>
<div><u><font size="2">ClientUtil.java</font></u></div>
<div style="border: 1px solid #aaaaaa; padding: 5px; background-color: #d3d3d3;">
<div><font size="2">package userguide.clients;</font></div>
<div><font size="2">import org.apache.axiom.om.OMAbstractFactory;<br />
import org.apache.axiom.om.OMElement;<br />
import org.apache.axiom.om.OMFactory;<br />
import org.apache.axiom.om.OMNamespace;</font></div>
<div><font size="2">public class ClientUtil {<br />
&nbsp;&nbsp;&nbsp; public static OMElement getEchoOMElement() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMFactory fac = OMAbstractFactory.getOMFactory();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMNamespace omNs = fac.createOMNamespace(<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "</font><font size="2"><a href="http://example1.org/example1" target="_blank">http://example1.org/example1</a></font><font size="2">", "example1");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMElement method = fac.createOMElement("echo", omNs);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMElement value = fac.createOMElement("Text", omNs);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; value.addChild(fac.createOMText(value, "Axis2 Echo String "));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; method.addChild(value);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return method;<br />
&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; public static OMElement getPingOMElement() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMFactory fac = OMAbstractFactory.getOMFactory();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMNamespace omNs = fac.createOMNamespace(<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "</font><font size="2"><a href="http://example1.org/example1" target="_blank">http://example1.org/example1</a></font><font size="2">", "example1");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMElement method = fac.createOMElement("ping", omNs);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMElement value = fac.createOMElement("Text", omNs);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; value.addChild(fac.createOMText(value, "Axis2 Ping String "));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; method.addChild(value);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return method;<br />
&nbsp;&nbsp;&nbsp; }<br />
}</font></div>
</div>
<div>&nbsp;</div>
<div><font size="2">2.2EchoBlockingClient<br />
&nbsp;&nbsp;&nbsp; Axis2向用户提供了从blocking
single channel调用到non-blocking dual channel调用的多种调用Web
Service的模式。下面用最简单的blocking调用机制来实现&#8221;MyService&#8221;中的"echo" operation。</font></div>
<div><u><font size="2">EchoBlockingClient.java</font></u></div>
<div style="border: 1px solid #aaaaaa; padding: 5px; background-color: #d3d3d3;">
<div><font size="2">package userguide.clients;</font></div>
<div><font size="2">import org.apache.axiom.om.OMElement;<br />
import org.apache.axis2.AxisFault;<br />
import org.apache.axis2.addressing.EndpointReference;<br />
import org.apache.axis2.client.Options;<br />
import org.apache.axis2.client.ServiceClient;</font></div>
<div><font size="2">/**<br />
&nbsp;* Sample for synchronous single channel blocking service invocation.<br />
&nbsp;* Message Exchage Pattern IN-OUT<br />
&nbsp;*/<br />
public class EchoBlockingClient {<br />
private static EndpointReference targetEPR =<br />
&nbsp;new EndpointReference("</font><font size="2"><a href="http://localhost:8080/axis2/services/MyService" target="_blank">http://localhost:8080/axis2/services/MyService</a></font><font size="2">");<br />
&nbsp;&nbsp;&nbsp; public static void main(String[] args) {<br />
try {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMElement payload = ClientUtil.getEchoOMElement();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font size="2"><font color="#5f9ea0">&nbsp;&nbsp;&nbsp; Options options = new Options();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; options.setTo(targetEPR); // this sets the location of MyService service<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ServiceClient serviceClient = new ServiceClient();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; serviceClient.setOptions(options);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMElement result = sender.sendReceive(payload);<br />
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(result);<br />
} catch (AxisFault axisFault) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; axisFault.printStackTrace();<br />
} <br />
}</font></div>
</div>
<div><font style="background-color: #ffffff;" size="2">&nbsp;&nbsp;&nbsp; 绿色部分显示了为了调用一个Web Service而需要对operation作的设置。剩下的部分是用来创建OMElement，用来发送和显示相应的OMElement。</font></div>
<div>&nbsp;</div>
<div><font size="2">结果：</font></div>
<div style="border: 1px solid #aaaaaa; padding: 5px; background-color: #d3d3d3;">
<div><font size="2">&lt;example1:echo xmlns:example1="</font><font size="2"><a href="http://example1.org/example1" target="_blank">http://example1.org/example1</a></font><font size="2">" <br />
xmlns:tns="</font><font size="2"><a href="http://ws.apache.org/axis2" target="_blank">http://ws.apache.org/axis2</a></font><font size="2">"&gt;<br />
&lt;example1:Text&gt;<br />
Axis2 Echo String <br />
&lt;/example1:Text&gt;<br />
&lt;/example1:echo&gt;</font></div>
</div>
<div>&nbsp;</div>
<div><font size="2">2.3 PingClient<br />
&nbsp;&nbsp;&nbsp; 在&#8221;MyService&#8221;中，我们有一种IN-ONLY模式的名为"ping"的operation。应用它的客户端代码如下：<br />
<u>PingClient.java</u></font></div>
<div style="border: 1px solid #aaaaaa; padding: 5px; background-color: #d3d3d3;">
<div><font size="2">package userguide.clients;</font></div>
<div><font size="2">import org.apache.axiom.om.OMElement;<br />
import org.apache.axis2.AxisFault;<br />
import org.apache.axis2.addressing.EndpointReference;<br />
import org.apache.axis2.client.Options;<br />
import org.apache.axis2.client.ServiceClient;</font></div>
<div><font size="2">/**<br />
&nbsp;* Sample for fire-and-forget service invocation<br />
&nbsp;* Message Exchage Pattern IN-Only<br />
&nbsp;*/<br />
public class PingClient {<br />
private static EndpointReference targetEPR =<br />
&nbsp;new EndpointReference("</font><font size="2"><a href="http://localhost:8080/axis2/services/MyService" target="_blank">http://localhost:8080/axis2/services/MyService</a></font><font size="2">");<br />
&nbsp;&nbsp;&nbsp; public static void main(String[] args) {<br />
try {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMElement payload = ClientUtil.getPingOMElement();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Options options = new Options();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; options.setTo(targetEPR);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ServiceClient serviceClient = new ServiceClient();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; serviceClient.setOptions(options);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font size="2"><font style="background-color: #ffffff;"><font style="background-color: #d3d3d3;" color="#5f9ea0">serviceClient.fireAndForget(payload);</font><br />
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /**<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * We have to block this thread untill we send the request , the problem<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * is if we go out of the main thread , then request wont send ,so<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * you have to wait some time :)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.sleep(500);<br />
&nbsp;&nbsp;&nbsp;&nbsp; } <br />
catch (AxisFault axisFault) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; axisFault.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp; }<br />
}</font></div>
</div>
<div><font style="background-color: #ffffff;" size="2">&nbsp;&nbsp;&nbsp; 由于我们在访问一个IN-ONLY模式的operation，所以我们可以直接使用ServiceClient中的"fireAndForget()"方法来调用这个operation。而且那样做的话，不会阻塞发起端，因此，它会立刻将控制权返回给客户端。</font></div>
<div>&nbsp;</div>
<div><font size="2">2.4 EchoNonBlockingClient<br />
&nbsp;&nbsp;&nbsp;
在客户端EchoBlockingClient，一旦调用"serviceClient.sendReceive(payload);"，客户端将会被阻
塞直到operation完成。这种方式在有很多Web
Service需要在一个单一的客户端应用程序中启动时很不可取。一种解决方法是使用Non-Blocking API来调用这些Web
Services。Axis2提供给用户一种基于回叫机制的non-blocking API。<br />
<u>EchoNonBlockingClient.java</u></font></div>
<div style="border: 1px solid #aaaaaa; padding: 5px; background-color: #d3d3d3;">
<div><font size="2">package userguide.clients;</font></div>
<div><font size="2">import org.apache.axiom.om.OMElement;<br />
import org.apache.axis2.AxisFault;<br />
import org.apache.axis2.addressing.EndpointReference;<br />
import org.apache.axis2.client.Options;<br />
import org.apache.axis2.client.ServiceClient;<br />
import org.apache.axis2.client.async.AsyncResult;<br />
import org.apache.axis2.client.async.Callback;</font></div>
<div><font size="2">/**<br />
&nbsp;* Sample for asynchronous single channel non-blocking service invocation.<br />
&nbsp;* Message Exchage Pattern IN-OUT<br />
&nbsp;*/<br />
public class EchoNonBlockingClient {<br />
private static EndpointReference targetEPR =<br />
&nbsp;new EndpointReference("</font><font size="2"><a href="http://127.0.0.1:8080/axis2/services/MyService" target="_blank">http://127.0.0.1:8080/axis2/services/MyService</a></font><font size="2">");<br />
&nbsp;&nbsp;&nbsp; public static void main(String[] args) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ServiceClient sender = null;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMElement payload = ClientUtil.getEchoOMElement();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Options options = new Options();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; options.setTo(targetEPR);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Callback to handle the response<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font size="2"><font color="#5f9ea0">Callback callback = new Callback() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void onComplete(AsyncResult result) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(result.getResponseEnvelope());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void onError(Exception e) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br />
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Non-Blocking Invocation<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sender = new ServiceClient();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sender.setOptions(options);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font size="2"><font color="#5f9ea0"> sender.sendReceiveNonBlocking(payload, callback);<br />
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Wait till the callback receives the response.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (!callback.isComplete()) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.sleep(1000);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (AxisFault axisFault) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; axisFault.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (Exception ex) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ex.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } finally {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sender.finalizeInvoke();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (AxisFault axisFault) { }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; }<br />
}</font></div>
</div>
<div>&nbsp;</div>
<div><font size="2">结果：</font></div>
<div style="border: 1px solid #aaaaaa; padding: 5px; background-color: #d3d3d3;">
<div><font size="2">&lt;?xml version='1.0' encoding='utf-8'?&gt;<br />
&lt;soapenv:Envelope xmlns:soapenv="</font><font size="2"><a href="http://schemas.xmlsoap.org/soap/envelope/" target="_blank">http://schemas.xmlsoap.org/soap/envelope/</a></font><font size="2">"&gt;<br />
&lt;soapenv:Header /&gt;<br />
&lt;soapenv:Body&gt;<br />
&lt;example1:echo xmlns:example1="</font><font size="2"><a href="http://example1.org/example1" target="_blank">http://example1.org/example1</a></font><font size="2">" <br />
xmlns:tns="</font><font size="2"><a href="http://ws.apache.org/axis2" target="_blank">http://ws.apache.org/axis2</a></font><font size="2">"&gt;<br />
&lt;example1:Text&gt;<br />
Axis2 Echo String<br />
&lt;/example1:Text&gt;<br />
&lt;/example1:echo&gt;<br />
&lt;/soapenv:Body&gt;<br />
&lt;/soapenv:Envelope&gt;</font></div>
</div>
<div><font style="background-color: #ffffff;" color="#000000" size="2">&nbsp;&nbsp;&nbsp; sender.sendReceiveNonBlocking(payload, callback);这个调用接受一个callback对象作为参数。Axis2客户端API提供了一个抽象类CallBack，其中提供了方法：</font></div>
<div style="border: 1px solid #aaaaaa; padding: 5px; background-color: #d3d3d3;">
<div><font size="2">public abstract void onComplete(AsyncResult result);<br />
public abstract void onError(Exception e);<br />
public boolean isComplete() {}</font></div>
</div>
<div><font style="background-color: #ffffff;" size="2">&nbsp;&nbsp;&nbsp; 用户需要重写"onComplete " 和 "onError "方法。一旦客户端收到Web Service的response，onComplete方法将会被调用，这样将中止阻塞状态。</font></div>
<div>&nbsp;</div>
<div><font size="2">2.5EchoNonBlockingDualClient<br />
&nbsp;&nbsp;&nbsp; 当调用的Web
Service需要很长一段时间来完成时，这种由Non-Blocking
API提供的解决方式将有一定的局限性。这种局限性是由使用单一的传输连接来调用Web
Service并接收response造成的。换句话说，客户端提供一种没有阻塞的调用机制，但request和response的传输使用单一的传输
（双工方式）连接（如HTTP）。长时间运行的Web Service调用或Web
Service调用使用单工传输方式（如SMTP）不能简单地利用一个没有阻塞的调用。<br />
&nbsp;&nbsp;&nbsp;
一种尝试地解决方法是request和response各自使用单独的传输连接（单工或双工均可）。这种方式产生的问题是如何解决相关性（关联
request和response）。WS-Addressing提供了一种很好的解决方法，在头中使用&lt;wsa:MessageID&gt;
和 &lt;wsa:RelatesTo&gt; 标签。Axis2对这种基于关联机制的寻址方式提供了支持。<br />
&nbsp;&nbsp;&nbsp;
用户可以选择Blocking 或Non-Blocking APIs的Web
Service，并使用两个传输连接。通过使用一个布尔标记，同一个API可以调用多个在两个传输连接上的Web Services(IN-OUT
operations)。下例使用Non-Blocking API 以及两个传输连接来实现上文中提到的"echo" operation。<br />
<u>EchoNonBlockingDualClient.java</u></font></div>
<div style="border: 1px solid #aaaaaa; padding: 5px; background-color: #d3d3d3;">
<div><font size="2">package userguide.clients;</font></div>
<div><font size="2">import org.apache.axiom.om.OMElement;<br />
import org.apache.axis2.AxisFault;<br />
import org.apache.axis2.Constants;<br />
import org.apache.axis2.addressing.EndpointReference;<br />
import org.apache.axis2.client.Options;<br />
import org.apache.axis2.client.ServiceClient;<br />
import org.apache.axis2.client.async.AsyncResult;<br />
import org.apache.axis2.client.async.Callback;<br />
import javax.xml.namespace.QName;</font></div>
<div><font size="2">/**<br />
&nbsp;* Sample for asynchronous dual channel non-blocking service invocation.<br />
&nbsp;* Message Exchage Pattern IN-OUT<br />
&nbsp;* Ulitmate asynchronous service invocation sample.<br />
&nbsp;*/<br />
public class EchoNonBlockingDualClient {<br />
private static EndpointReference targetEPR =<br />
&nbsp;new EndpointReference("</font><font size="2"><a href="http://127.0.0.1:8080/axis2/services/MyService" target="_blank">http://127.0.0.1:8080/axis2/services/MyService</a></font><font size="2">");<br />
&nbsp;&nbsp;&nbsp; public static void main(String[] args) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ServiceClient sender = null;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMElement payload = ClientUtil.getEchoOMElement();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Options options = new Options();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; options.setTo(targetEPR);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; options.setTransportInProtocol(Constants.TRANSPORT_HTTP);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font size="2"><font color="#5f9ea0">&nbsp;&nbsp; options.setUseSeparateListener(true);<br />
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; options.setAction("urn:echo");&nbsp; // this is the action mapping we put within the service.xml<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Callback to handle the response<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Callback callback = new Callback() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void onComplete(AsyncResult result) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(result.getResponseEnvelope());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void onError(Exception e) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Non-Blocking Invocation<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ConfigurationContext sysContext = ConfigurationContextFactory<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .createConfigurationContextFromFileSystem(<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "D:\\Dvp\\Axis2\\axis2\\WEB-INF", null);//见注解①<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sender = new ServiceClient(sysContext, null);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sender.engageModule(new QName(Constants.MODULE_ADDRESSING));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sender.setOptions(options);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sender.sendReceiveNonBlocking(payload, callback);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Wait till the callback receives the response.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (!callback.isComplete()) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.sleep(1000);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Need to close the Client Side Listener.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (AxisFault axisFault) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; axisFault.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (Exception ex) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ex.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } finally {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font size="2"><font color="#5f9ea0">&nbsp; sender.finalizeInvoke();<br />
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (AxisFault axisFault) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //have to ignore this<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; }<br />
}</font></div>
</div>
<div><font style="background-color: #ffffff;"><font size="2">注解①<br />
</font><em><font size="2">RE: [Axis2] 0.95 WS-Addressing web SERVICE-SIDE: module not found<br />
&nbsp;&nbsp;&nbsp;
I now have managed to get EchoNonBlockingDualClient working. I still
can't get the original code to work, where ever I put
addressing-0.95.mar, but the ConfigurationContext works.<br />
&nbsp;&nbsp;&nbsp; The code I ended up with was:</font></em></font></div>
<div style="border: 1px solid #aaaaaa; padding: 5px; background-color: #d3d3d3;">
<div><font size="2">&nbsp;ConfigurationContext sysContext = ConfigurationContextFactory<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .createConfigurationContextFromFileSystem(<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "C:\\axis2", null);<br />
&nbsp; sender = new ServiceClient(sysContext, null);</font></div>
</div>
<div><font style="background-color: #ffffff;"><font size="2"><em>&nbsp;&nbsp;&nbsp; with no need, obviously, for the .engageModule method.<br />
&nbsp;&nbsp;&nbsp;
I did discover though that the directory which the ConfigurationContext
points to has to have two directories within it: "conf", which must
contain the axis.xml configuration file, and the "modules" directory
which contains addressing-0.95.mar.</em> </font></font></div>
<div><font size="2">&nbsp;&nbsp;&nbsp;
在方法"options.setUseSeparateListener(...)"中的布尔标记通知通知Axis2引擎使用两个不同的传输连接来分别处
理request和response。Finally中的
"serviceClient.finalizeInvoke()"方法通知Axis2引擎停用客户端的用于接收response的listener。<br />
&nbsp;&nbsp;&nbsp; 在我们运行客户端的例程之前，我们还有一件事情要做。如前面提到的，Axis2使用基于地址的关联机制，因此我们必须在服务器端和客户端&#8220;搭建&#8221;寻址模块。</font></div>
<div><br />
<font size="2">结果：</font></div>
<div style="border: 1px solid #aaaaaa; padding: 5px; background-color: #d3d3d3;">
<div><font size="2">&lt;?xml version='1.0' encoding='utf-8'?&gt;<br />
&lt;soapenv:Envelope xmlns:soapenv="</font><font size="2"><a href="http://schemas.xmlsoap.org/soap/envelope/" target="_blank">http://schemas.xmlsoap.org/soap/envelope/</a></font><font size="2">" xmlns:wsa="</font><font size="2"><a href="http://www.w3.org/2005/08/addressing" target="_blank">http://www.w3.org/2005/08/addressing</a></font><font size="2">"&gt;<br />
&lt;soapenv:Header&gt;<br />
&lt;wsa:To&gt;<a href="http://59.14.131.187:6060/axis2/services/__ANONYMOUS_SERVICE__/__OPERATION_OUT_IN__" target="_blank">http://59.14.131.187:6060/axis2/services/__ANONYMOUS_SERVICE__/__OPERATION_OUT_IN__</a><br />
&lt;/wsa:To&gt;<br />
&lt;wsa:ReplyTo&gt;<br />
&lt;wsa:Address&gt;<br />
</font><font size="2"><a href="http://www.w3.org/2005/08/addressing/anonymous" target="_blank">http://www.w3.org/2005/08/addressing/anonymous</a></font><br />
<font size="2">&lt;/wsa:Address&gt;<br />
&lt;/wsa:ReplyTo&gt;<br />
&lt;wsa:From&gt;<br />
&lt;wsa:Address&gt;<br />
</font><font size="2"><a href="http://127.0.0.1:8080/axis2/services/MyService" target="_blank">http://127.0.0.1:8080/axis2/services/MyService</a></font><br />
<font size="2">&lt;/wsa:Address&gt;<br />
&lt;/wsa:From&gt;<br />
&lt;wsa:FaultTo&gt;<br />
&lt;wsa:Address&gt;<br />
</font><font size="2"><a href="http://127.0.0.1:8080/axis2/services/MyService" target="_blank">http://127.0.0.1:8080/axis2/services/MyService</a></font><br />
<font size="2">&lt;/wsa:Address&gt;<br />
&lt;/wsa:FaultTo&gt;<br />
&lt;wsa:MessageID&gt;<br />
urn:uuid:B087CBB98F1B51A24711742241136206<br />
&lt;/wsa:MessageID&gt;<br />
&lt;wsa:Action&gt;urn:echo&lt;/wsa:Action&gt;<br />
&lt;wsa:RelatesTo wsa:RelationshipType="wsa:Reply"&gt;<br />
urn:uuid:CA4B9513377E6E9E1511742241130391<br />
&lt;/wsa:RelatesTo&gt;<br />
&lt;/soapenv:Header&gt;<br />
&lt;soapenv:Body&gt;<br />
&lt;example1:echo xmlns:example1="</font><font size="2"><a href="http://example1.org/example1" target="_blank">http://example1.org/example1</a></font><font size="2">" xmlns:tns="</font><font size="2"><a href="http://ws.apache.org/axis2" target="_blank">http://ws.apache.org/axis2</a></font><font size="2">"&gt;<br />
&lt;example1:Text&gt;<br />
Axis2 Echo String<br />
&lt;/example1:Text&gt;<br />
&lt;/example1:echo&gt;<br />
&lt;/soapenv:Body&gt;<br />
&lt;/soapenv:Envelope&gt;</font></div>
</div>
<div><font style="background-color: #ffffff;" size="2">[SimpleHTTPServer] Stop called</font></div>
<div>&nbsp;</div>
<div><font size="2">2.6 实现服务器端的寻址<br />
&nbsp;&nbsp;&nbsp;
根据Axis2的结构，寻址模块在"pre-dispatch"阶段已经给出它的句柄。因此，所谓的&#8220;搭建&#8221;仅仅是在&#8221;axis2.xml&#8221;（注意不是
services.xml）增加一个模块的引用。现在将下面这行字加入到axis2.xml，该文件在"/webapps/axis2/WEB-
INF/conf"目录下。</font></div>
<div style="border: 1px solid #aaaaaa; padding: 5px; background-color: #d3d3d3;">
<div><font size="2">&lt;module ref="addressing"/&gt;</font></div>
</div>
<div><font size="2">注： 一旦你改变了axis2.xml，你必须重启这个servlet容器，改变才能生效。</font></div>
<div>&nbsp;</div>
<div><font size="2">2.7 实现客户端的寻址<br />
&nbsp;&nbsp;&nbsp; 有两种方式。<br />
&nbsp;&nbsp;&nbsp;
一种方法是在%Axis2_HOME%\axis2-std-1.0-bin\modules目录下得到addressing-&lt;
version&gt;.mar。并且在你的classpath中对其可见。（此种方法目前，我还没有调试成功，具体见注解①。下面的第二种方法可用）<br />
&nbsp;&nbsp;&nbsp; 另一种方法是创建一个ConfigurationContext，指定一个repository位置。Axis2支持repository的方式来保存服务和模块。<br />
&nbsp;&nbsp;&nbsp;
你可以使用二进制distribution作为repository，只要它含有一个Axis2
repository认可的repository结构（其中应包含services和modules目录）。ConfigurationContext
中含有Axis2体系的运行时的上下文信息。 <br />
&nbsp;&nbsp;&nbsp;
如果你解压一个标准的二进制distribution到目录（譬如）$user_home/axis2/dist, 那么在 sender = new
ServiceClient();之前加入（具体见EchoNonBlockingDualClient.java）： </font></div>
<div style="border: 1px solid #aaaaaa; padding: 5px; background-color: #d3d3d3;">
<div><font size="2">new ServiceClient();之前加入（具体见EchoNonBlockingDualClient.java）： <br />
ConfigurationContext configContext = <br />
ConfigurationContextFactory.createConfigurationContextFromFileSystem(&lt; Axis2RepositoryLocation &gt;, null);</font></div>
</div>
<div><font style="background-color: #ffffff;" size="2">&nbsp;&nbsp;&nbsp; 用"sender = new ServiceClient(configContext, null);" 替换 "sender = new ServiceClient();"<br />
这样可以在客户端和服务器端都实现寻址。</font></div>
<div>&nbsp;</div>
<div><font size="2">2.8 EchoBlockingDualClient<br />
&nbsp;&nbsp;&nbsp;
这又是一个两路的传输的request/response客户端，但这次，我们使用一个Blocking
API。实现机制和EchoNonBlockingDualClient差不多，唯一的不同是，这里不需要使用一个callback对象来处理
response。<br />
<u>EchoBlockingDualClient.java</u></font></div>
<div style="border: 1px solid #aaaaaa; padding: 5px; background-color: #d3d3d3;">
<div><font size="2">package userguide.clients;</font></div>
<div><font size="2">import org.apache.axiom.om.OMElement;<br />
import org.apache.axis2.AxisFault;<br />
import org.apache.axis2.Constants;<br />
import org.apache.axis2.addressing.EndpointReference;<br />
import org.apache.axis2.client.Options;<br />
import org.apache.axis2.client.ServiceClient;</font></div>
<div><font size="2">import javax.xml.namespace.QName;<br />
import javax.xml.stream.XMLOutputFactory;<br />
import java.io.StringWriter;</font></div>
<div><font size="2">/**<br />
&nbsp;* Sample for synchronous dual channel blocking service invocation.<br />
&nbsp;* Message Exchage Pattern IN-OUT<br />
&nbsp;*/<br />
public class EchoBlockingDualClient {<br />
private static EndpointReference targetEPR =<br />
&nbsp;new EndpointReference("</font><font size="2"><a href="http://127.0.0.1:8080/axis2/services/MyService" target="_blank">http://127.0.0.1:8080/axis2/services/MyService</a></font><font size="2">");<br />
&nbsp;&nbsp;&nbsp; public static void main(String[] args) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ServiceClient sender = null;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMElement payload = ClientUtil.getEchoOMElement();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Options options = new Options();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; options.setTo(targetEPR);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; options.setAction("urn:echo");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //The boolean flag informs the axis2 engine to use two separate transport connection<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //to retrieve the response.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; options.setTransportInProtocol(Constants.TRANSPORT_HTTP);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; options.setUseSeparateListener(true);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Blocking Invocation<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ConfigurationContext sysContext = ConfigurationContextFactory<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .createConfigurationContextFromFileSystem(<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "D:\\Dvp\\Axis2\\axis2\\WEB-INF", null);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sender = new ServiceClient(sysContext, null);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sender.engageModule(new QName(Constants.MODULE_ADDRESSING));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sender.setOptions(options);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMElement result = sender.sendReceive(payload);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StringWriter writer = new StringWriter();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result.serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; writer.flush();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(writer.toString());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Need to close the Client Side Listener.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (AxisFault axisFault) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; axisFault.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (Exception ex) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ex.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } finally{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sender.finalizeInvoke();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (AxisFault axisFault) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; }<br />
}</font></div>
</div>
<font style="background-color: #ffffff;" size="2">结果：<br />
&lt;example1:echo xmlns:example1="</font><font style="background-color: #ffffff;" size="2"><a href="http://example1.org/example1" target="_blank">http://example1.org/example1</a></font><font style="background-color: #ffffff;" size="2">" xmlns:tns="</font><font style="background-color: #ffffff;" size="2"><a href="http://ws.apache.org/axis2" target="_blank">http://ws.apache.org/axis2</a></font><font size="2"><font style="background-color: #ffffff;">"&gt;<br />
&lt;example1:Text&gt;Axis2 Echo String &lt;/example1:Text&gt;<br />
&lt;/example1:echo&gt;<br />
[SimpleHTTPServer] Stop called</font> </font>
<img src ="http://www.blogjava.net/libin2722/aggbug/214223.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2008-07-11 12:26 <a href="http://www.blogjava.net/libin2722/articles/214223.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用Axis2传递简单Java对象（POJO）</title><link>http://www.blogjava.net/libin2722/articles/214035.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Thu, 10 Jul 2008 09:23:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/214035.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/214035.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/214035.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/214035.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/214035.html</trackback:ping><description><![CDATA[<table id="content" style="table-layout: fixed; width: 650px" cellspacing="10" cellpadding="0" width="650" border="0">
    <tbody>
        <tr>
            <td>
            <div><strong>版权声明：</strong>原创作品，允许转载，转载时请务必以超链接形式标明文章 <a style="text-decoration: underline" href="http://zhangjunhd.blog.51cto.com/113473/26053" target="_blank">原始出处</a> 、作者信息和本声明。否则将追究法律责任。<a href="http://zhangjunhd.blog.51cto.com/113473/26053">http://zhangjunhd.51cto.com/113473/26053</a></div>
            </td>
        </tr>
        <tr>
            <td>
            <div>
            <div style="margin: 0cm 0cm 0pt; text-align: center" align="left"><font size="2"><em><span style="font-family: 宋体" new="" times="">本文介绍如何使用</span>Axis2</em><em><span style="font-family: 宋体" new="" times="">在</span>Web Service</em><em><span style="font-family: 宋体" new="" times="">中传递</span>Java</em><em><span style="font-family: 宋体" new="" times="">对象。</span></em></font></div>
            <div style="margin: 0cm 0cm 0pt"><font size="2">author: ZJ 07-5-7</font></div>
            <div style="margin: 0cm 0cm 0pt"><font size="2">Blog: </font><a href="http://zhangjunhd.blog.51cto.com/" target="_blank">http://zhangjunhd.blog.51cto.com/</a></div>
            <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
            <div style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font size="2"><span style="font-family: 宋体" new="" times="">在</span>Axis2_1.2<span style="font-family: 宋体" new="" times="">版本中提供了传递</span>Java<span style="font-family: 宋体" new="" times="">对象的功能（注：只有</span>1.1/1.2<span style="font-family: 宋体" new="" times="">版本提供，更早的</span>Axis2<span style="font-family: 宋体" new="" times="">版本没有此功能）。此项功能称为传输</span>POJO(a Plain Old Java Object)</font></div>
            <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
            <div style="margin: 0cm 0cm 0pt"><font size="2"><strong>1.</strong><strong><span style="font-family: 宋体" new="" times="">引入一个简单的</span>POJO- The Weather POJO</strong></font></div>
            <div style="margin: 0cm 0cm 0pt"><u><font size="2">Weather.java</font></u></div>
            <table style="border-right: medium none; border-top: medium none; border-left: medium none; border-bottom: medium none; border-collapse: collapse" cellspacing="0" cellpadding="0" border="1">
                <tbody>
                    <tr>
                        <td style="border-right: windowtext 1pt solid; padding-right: 5.4pt; border-top: windowtext 1pt solid; padding-left: 5.4pt; background: #e6e6e6; padding-bottom: 0cm; border-left: windowtext 1pt solid; width: 426.1pt; padding-top: 0cm; border-bottom: windowtext 1pt solid" valign="top" width="568">
                        <div style="margin: 0cm 0cm 0pt"><font size="2">package sample.pojo.data;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">public class Weather {</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float temperature;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String forecast;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; boolean rain;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float howMuchRain;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void setTemperature(float temp) {</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temperature = temp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public float getTemperature() {</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return temperature;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void setForecast(String fore) {</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; forecast = fore;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public String getForecast() {</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return forecast;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void setRain(boolean r) {</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rain = r;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public boolean getRain() {</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return rain;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void setHowMuchRain(float howMuch) {</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; howMuchRain = howMuch;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public float getHowMuchRain() {</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return howMuchRain;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">}</font></div>
                        </td>
                    </tr>
                </tbody>
            </table>
            <div style="margin: 0cm 0cm 0pt"><em><font size="2">Note that it's all just straight POJOs with field items and getter and setter methods for each field.</font></em></div>
            <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
            <div style="margin: 0cm 0cm 0pt"><font size="2"><strong>2.</strong><strong><span style="font-family: 宋体" new="" times="">基于此</span>POJO</strong><strong><span style="font-family: 宋体" new="" times="">的</span>service</strong></font></div>
            <div style="margin: 0cm 0cm 0pt"><u><font size="2">WeatherService.java</font></u></div>
            <table style="border-right: medium none; border-top: medium none; border-left: medium none; border-bottom: medium none; border-collapse: collapse" cellspacing="0" cellpadding="0" border="1">
                <tbody>
                    <tr>
                        <td style="border-right: windowtext 1pt solid; padding-right: 5.4pt; border-top: windowtext 1pt solid; padding-left: 5.4pt; background: #e6e6e6; padding-bottom: 0cm; border-left: windowtext 1pt solid; width: 426.1pt; padding-top: 0cm; border-bottom: windowtext 1pt solid" valign="top" width="568">
                        <div style="margin: 0cm 0cm 0pt"><font size="2">package sample.pojo.service;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">import sample.pojo.data.Weather;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">public class WeatherService{</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp; Weather weather;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp; </font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp; public void setWeather(Weather weather){</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.weather = weather;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp; }</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp; public Weather getWeather(){</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return this.weather;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp; }</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">}</font></div>
                        </td>
                    </tr>
                </tbody>
            </table>
            <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
            <div style="margin: 0cm 0cm 0pt"><font size="2"><strong>3.</strong><strong><span style="font-family: 宋体" new="" times="">相应的</span>services.xml</strong></font></div>
            <table style="border-right: medium none; border-top: medium none; border-left: medium none; border-bottom: medium none; border-collapse: collapse" cellspacing="0" cellpadding="0" border="1">
                <tbody>
                    <tr>
                        <td style="border-right: windowtext 1pt solid; padding-right: 5.4pt; border-top: windowtext 1pt solid; padding-left: 5.4pt; background: #e6e6e6; padding-bottom: 0cm; border-left: windowtext 1pt solid; width: 426.1pt; padding-top: 0cm; border-bottom: windowtext 1pt solid" valign="top" width="568">
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&lt;service name="WeatherService" scope="application"&gt;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp; &lt;description&gt;Weather POJO Service&lt;/description&gt;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp; &lt;messageReceivers&gt;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;messageReceiver </font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mep="http://www.w3.org/2004/08/wsdl/in-only"</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp; class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/&gt;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;messageReceiver</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mep="http://www.w3.org/2004/08/wsdl/in-out"</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp; class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/&gt;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp; &lt;/messageReceivers&gt;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp; &lt;parameter name="ServiceClass"&gt;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sample.pojo.service.WeatherService</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp; &lt;/parameter&gt;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&lt;/service&gt;</font></div>
                        </td>
                    </tr>
                </tbody>
            </table>
            <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
            <div style="margin: 0cm 0cm 0pt"><font size="2"><strong>4.</strong><strong><span style="font-family: 宋体" new="" times="">打包与部署</span></strong></font></div>
            <div style="margin: 0cm 0cm 0pt; text-indent: 21pt"><span style="font-family: 宋体" new="" times=""><font size="2">将文件组织成：</font></span></div>
            <table style="border-right: medium none; border-top: medium none; border-left: medium none; border-bottom: medium none; border-collapse: collapse" cellspacing="0" cellpadding="0" border="1">
                <tbody>
                    <tr>
                        <td style="border-right: windowtext 1pt solid; padding-right: 5.4pt; border-top: windowtext 1pt solid; padding-left: 5.4pt; background: #e6e6e6; padding-bottom: 0cm; border-left: windowtext 1pt solid; width: 426.1pt; padding-top: 0cm; border-bottom: windowtext 1pt solid" valign="top" width="568">
                        <div style="margin: 0cm 0cm 0pt; text-align: left; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align="left"><span style="font-family: 宋体"><font size="2">- WeatherService</font></span></div>
                        <div style="margin: 0cm 0cm 0pt; text-align: left; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align="left"><span style="font-family: 宋体"><font size="2">&nbsp;&nbsp; - META-INF</font></span></div>
                        <div style="margin: 0cm 0cm 0pt; text-align: left; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align="left"><span style="font-family: 宋体"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp; - services.xml</font></span></div>
                        <div style="margin: 0cm 0cm 0pt; text-align: left; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align="left"><span style="font-family: 宋体"><font size="2">&nbsp;&nbsp; - sample</font></span></div>
                        <div style="margin: 0cm 0cm 0pt; text-align: left; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align="left"><span style="font-family: 宋体"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp; - pojo</font></span></div>
                        <div style="margin: 0cm 0cm 0pt; text-align: left; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align="left"><span style="font-family: 宋体"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - data</font></span></div>
                        <div style="margin: 0cm 0cm 0pt; text-align: left; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align="left"><span style="font-family: 宋体"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - Weather.class</font></span></div>
                        <div style="margin: 0cm 0cm 0pt; text-align: left; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align="left"><span style="font-family: 宋体"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - service</font></span></div>
                        <div style="margin: 0cm 0cm 0pt"><span style="font-family: 宋体"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - WeatherService.class</font></span></div>
                        </td>
                    </tr>
                </tbody>
            </table>
            <div style="margin: 0cm 0cm 0pt; text-indent: 21pt"><font size="2"><span style="font-family: 宋体" new="" times="">将其打包为</span>WeatherService.aar<span style="font-family: 宋体" new="" times="">，并部署在</span>Tomcat<span style="font-family: 宋体" new="" times="">上（详见 <strong><a href="http://zhangjunhd.blog.51cto.com/blog/113473/23690" target="_blank"><font color="#000000">基于Tomcat5.0和Axis2开发Web Service应用实例</font></a></strong> ）。</span></font></div>
            <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
            <div style="margin: 0cm 0cm 0pt"><font size="2"><strong>5</strong><strong><span style="font-family: 宋体" new="" times="">．测试</span></strong></font></div>
            <div style="margin: 0cm 0cm 0pt"><u><font size="2">WeatherRPCClient.java</font></u></div>
            <table style="border-right: medium none; border-top: medium none; border-left: medium none; border-bottom: medium none; border-collapse: collapse" cellspacing="0" cellpadding="0" border="1">
                <tbody>
                    <tr>
                        <td style="border-right: windowtext 1pt solid; padding-right: 5.4pt; border-top: windowtext 1pt solid; padding-left: 5.4pt; background: #e6e6e6; padding-bottom: 0cm; border-left: windowtext 1pt solid; width: 426.1pt; padding-top: 0cm; border-bottom: windowtext 1pt solid" valign="top" width="568">
                        <div style="margin: 0cm 0cm 0pt"><font size="2">package sample.pojo.rpcclient;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">import javax.xml.namespace.QName;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">import org.apache.axis2.AxisFault;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">import org.apache.axis2.addressing.EndpointReference;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">import org.apache.axis2.client.Options;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">import org.apache.axis2.rpc.client.RPCServiceClient;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">import sample.pojo.data.Weather;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">public class WeatherRPCClient {</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static void main(String[] args1) throws AxisFault {</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RPCServiceClient serviceClient = new RPCServiceClient();</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Options options = serviceClient.getOptions();</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EndpointReference targetEPR = new EndpointReference(</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "http://localhost:8080/axis2/services/WeatherService");</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; options.setTo(targetEPR);</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Setting the weather</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QName opSetWeather = new QName("http://service.pojo.sample/xsd",</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "setWeather");</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Weather w = new Weather();</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; w.setTemperature((float) 39.3);</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; w.setForecast("Cloudy with showers");</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; w.setRain(true);</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; w.setHowMuchRain((float) 4.5);</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Object[] opSetWeatherArgs = new Object[] { w };</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; serviceClient.invokeRobust(opSetWeather, opSetWeatherArgs);</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; serviceClient.invokeRobust(opSetWeather, opSetWeatherArgs);</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Getting the weather</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QName opGetWeather = new QName("http://service.pojo.sample/xsd",</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "getWeather");</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Object[] opGetWeatherArgs = new Object[] {};</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Class[] returnTypes = new Class[] { Weather.class };</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Object[] response = serviceClient.invokeBlocking(opGetWeather,</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; opGetWeatherArgs, returnTypes);</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Weather result = (Weather) response[0];</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (result == null) {</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("Weather didn't initialize!");</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Displaying the result</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("Temperature&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : "</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + result.getTemperature());</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("Forecast&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : "</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + result.getForecast());</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("Rain&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : " + result.getRain());</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("How much rain (in inches) : "</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + result.getHowMuchRain());</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">}</font></div>
                        </td>
                    </tr>
                </tbody>
            </table>
            <div style="margin: 0cm 0cm 0pt"><font size="2">&nbsp;</font></div>
            <div style="margin: 0cm 0cm 0pt"><font size="2"><strong>6</strong><strong><span style="font-family: 宋体" new="" times="">．结果</span></strong></font></div>
            <table style="border-right: medium none; border-top: medium none; border-left: medium none; border-bottom: medium none; border-collapse: collapse" cellspacing="0" cellpadding="0" border="1">
                <tbody>
                    <tr>
                        <td style="border-right: windowtext 1pt solid; padding-right: 5.4pt; border-top: windowtext 1pt solid; padding-left: 5.4pt; background: #e6e6e6; padding-bottom: 0cm; border-left: windowtext 1pt solid; width: 426.1pt; padding-top: 0cm; border-bottom: windowtext 1pt solid" valign="top" width="568">
                        <div style="margin: 0cm 0cm 0pt"><font size="2">Temperature&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 39.3</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">Forecast&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Cloudy with showers</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">Rain&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;: true</font></div>
                        <div style="margin: 0cm 0cm 0pt"><font size="2">How much rain (in inches) &nbsp;&nbsp;&nbsp;: 4.5</font></div>
                        </td>
                    </tr>
                </tbody>
            </table>
            </div>
            </td>
        </tr>
    </tbody>
</table>
<img src ="http://www.blogjava.net/libin2722/aggbug/214035.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2008-07-10 17:23 <a href="http://www.blogjava.net/libin2722/articles/214035.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Axis2快速上手指南</title><link>http://www.blogjava.net/libin2722/articles/214034.html</link><dc:creator>礼物</dc:creator><author>礼物</author><pubDate>Thu, 10 Jul 2008 09:22:00 GMT</pubDate><guid>http://www.blogjava.net/libin2722/articles/214034.html</guid><wfw:comment>http://www.blogjava.net/libin2722/comments/214034.html</wfw:comment><comments>http://www.blogjava.net/libin2722/articles/214034.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/libin2722/comments/commentRss/214034.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/libin2722/services/trackbacks/214034.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 原文链接:http://ws.apache.org/axis2/1_1_1/quickstartguide.html 本指南的目的是让你尽可能快的创建使用Axis2的服务和客户端，我们将使用一个简单的StockQuote服务并显示给你一些创建和部署它 的不同的方式，以及快速的看看Axis2自带的一些工具，然后我们将看看创建访问这些服务的客户端。 内容 Java代码 ...&nbsp;&nbsp;<a href='http://www.blogjava.net/libin2722/articles/214034.html'>阅读全文</a><img src ="http://www.blogjava.net/libin2722/aggbug/214034.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/libin2722/" target="_blank">礼物</a> 2008-07-10 17:22 <a href="http://www.blogjava.net/libin2722/articles/214034.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>