﻿<?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-心梦帆影——JavaEE探索与研究-随笔分类-WebService</title><link>http://www.blogjava.net/rongxh7/category/39686.html</link><description>Struts2.x+Spring2.x+Hibernate3.x+EJB3.0+JPA+Jquery+SOA+WebService+Eclipse+MySQL+Oracle+WebLogic+JBoss+.......探索与求知，寻找一条完美的路，通过梦想的世界！</description><language>zh-cn</language><lastBuildDate>Thu, 02 Jul 2009 20:13:46 GMT</lastBuildDate><pubDate>Thu, 02 Jul 2009 20:13:46 GMT</pubDate><ttl>60</ttl><item><title>[图解教程]Axis2与Eclipse整合开发Web Service之二：WSDL逆向生成服务端</title><link>http://www.blogjava.net/rongxh7/archive/2009/07/02/285193.html</link><dc:creator>心梦帆影</dc:creator><author>心梦帆影</author><pubDate>Thu, 02 Jul 2009 07:47:00 GMT</pubDate><guid>http://www.blogjava.net/rongxh7/archive/2009/07/02/285193.html</guid><wfw:comment>http://www.blogjava.net/rongxh7/comments/285193.html</wfw:comment><comments>http://www.blogjava.net/rongxh7/archive/2009/07/02/285193.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rongxh7/comments/commentRss/285193.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rongxh7/services/trackbacks/285193.html</trackback:ping><description><![CDATA[<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 一般开发Web Service，是选写服务端，再根据生成的WSDL文件生成客户端。看过一本SOA的书中说，如果实现防止不同语言一些特定的数据类型的不兼容性，推荐先定义WSDL接口，包括一输入输出参数、返回值及相关的数据类型等，再通过WSDL来生成服务器端和客户端，这样的好处是：服务端不用关心客户端怎么调用，客户端也不用关系服务端如何实现。</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 关于Eclipse中Axis2的配置方法，请看我的<a href="http://www.blogjava.net/rongxh7/archive/2009/05/21/271982.html">[图解教程] Axis2与Eclipse整合开发Web Service之一：简单的计算服务例子</a>，下面来新建一个WSDL文件，如下图：</p> <p><a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb.png" width="590" height="595"></a> </p> <p>改个名字为&#8220;manager.wsdl&#8221;，如下图：</p> <p><a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_4.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb_1.png" width="546" height="465"></a> </p> <p>下一步，定义命名空间和协议等信息，默认即行。如下图：</p> <p><a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_6.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb_2.png" width="504" height="429"></a> </p> <p>finish后，会在主工作区出现如下图：</p> <p><a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_12.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb_5.png" width="612" height="195"></a> </p> <p>这是manager.wsdl的图形化形式，点击&#8220;Source&#8221;会可查看到源代码：</p> <p><a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_14.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb_6.png" width="608" height="271"></a> </p> <p>这是默认生成的wsdl，我们要根据我们的项目需要，修改上面的图，首先对方法名进行修改，如下图：</p> <p><a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_18.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb_8.png" width="472" height="170"></a> </p> <p>可见，修改之后，右边的input和output也跟着修改了，这两个就是定义plus的输入和输出。</p> <p>点击input参数&#8220;plus&#8221;右边的提示箭头，进入下图：</p> <p><a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_20.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb_9.png" width="432" height="197"></a> </p> <p>就在这里定义输入参数和和参数类型等信息，因为我们plus(float x, float y)方法中有两个参数x和y，故我们将上图改成两个参数的序列：</p> <p><a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_30.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb_14.png" width="416" height="229"></a> </p> <p>变成下图，对比一下方法plus(float x, float y)，下图也不会太难理解吧！</p> <p><a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_32.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb_15.png" width="465" height="223"></a> </p> <p>我们返回manager.wsdl视图，选择output参数右边的箭头，进入下图：</p> <p><a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_34.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb_16.png" width="451" height="168"></a> </p> <p>我们在这里设置float plus(float x, float y)方法的返回值及其类型，因其返回值只有一个，我们只须把上面的out的类型改成我们方法中用的float，改后，如下图：</p> <p><a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_42.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb_20.png" width="530" height="203"></a> </p> <p>有没有注意到上图左上角有个<a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_44.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb_21.png" width="37" height="32"></a> 图标，点击它，进入下图：</p> <p><a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_48.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb_23.png" width="654" height="456"></a> </p> <p>我们可以在这里对输入输出的参数及其他数据类型进行修改，如果在上面的操作过程中，不小心产生了多余的标签的话，也可以在这里去除。</p> <p>好了，我们再回到manager.wsdl，在源代码视图里右键选&#8220;Validate&#8221;，对xml文档进行检验，如果有错误的，就根据需要修改。</p> <p><a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_50.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb_24.png" width="318" height="216"></a> </p> <p>好了，图形化编写的wsdl文档完成了，顺便说一下，方法是可以定义多个的，如下图：</p> <p><a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_52.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb_25.png" width="437" height="177"></a> </p> <p>为简单起见，我们就先以刚才做定义的那个方法为例，看看，如何根据wsdl文件，自动生成Web Service的服务器端。</p> <p>&nbsp;</p> <p>我们New一个Web Service，如下图：</p> <p><a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_54.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb_26.png" width="523" height="497"></a> </p> <p>记得在Web Service type中选择&#8220;Top down Java Bean Web Service&#8221;，如下图：</p> <p><a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_56.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb_27.png" width="545" height="185"></a></p> <p>然后，在Service definition中找到刚才写的那个manager.wsdl文件。</p> <p><a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_58.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb_28.png" width="570" height="455"></a>&nbsp; </p> <p>回到Web Service对话框，将服务类型的滑块调到&#8220;Develop service&#8221;处，</p> <p><a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_60.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb_29.png" width="584" height="398"></a> </p> <p>接下来，就next &#8211;&gt; next &#8211;-&gt; finish就行。它会自动生成Web Service服务端的接口和类，在类中，可找到我们定义的方法：</p> <p><a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_62.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb_30.png" width="578" height="174"></a> </p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p>我们只要修改方法plus的方法体，以实现我们要实现的功能即行。如下：</p> <p><a href="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_64.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/rongxh7/WindowsLiveWriter/Axis2EclipseWebServiceWSDL_C28D/image_thumb_31.png" width="579" height="188"></a> </p> <p>这是通过WSDL反向生成Web Service服务端的最简单一个例子，可能看不到有什么好处，没有像<a href="http://www.blogjava.net/rongxh7/archive/2009/05/21/271982.html">[图解教程] Axis2与Eclipse整合开发Web Service之一：简单的计算服务例子</a>那样的简便快捷，但如果是一些特有的数据类型，如List，Set，这些，我们有在WSDL图形化设计中找到相应的替代类型，先定义WSDL再生成服务端接口，这样做，不仅Java开发客户端是没有问题的，用C#开发客户端也能成功没有出错！</p> <p>但如果先开发服务器端的话，如果用到一些Java特有的数据类型，如List，Set，如果用其他语言生成的客户端，就可能出问题。同理，用C#开发服务端，如果用到像DataSet这样的返回类型的话，那如果用Java或者其他语言去开发客户端，也可能会出现问题的。</p> <p>如果统一先写WSDL，再根据WSDL生成服务端和客户端，应该是一种很不错的做法，Eclipse在这方面的图形化支持给带给我们事半功倍的效果，这样做，也比较符合SOA的做法。</p> <img src ="http://www.blogjava.net/rongxh7/aggbug/285193.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rongxh7/" target="_blank">心梦帆影</a> 2009-07-02 15:47 <a href="http://www.blogjava.net/rongxh7/archive/2009/07/02/285193.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[图解教程] Axis2与Eclipse整合开发Web Service之一：简单的计算服务例子</title><link>http://www.blogjava.net/rongxh7/archive/2009/05/21/271982.html</link><dc:creator>心梦帆影</dc:creator><author>心梦帆影</author><pubDate>Thu, 21 May 2009 07:13:00 GMT</pubDate><guid>http://www.blogjava.net/rongxh7/archive/2009/05/21/271982.html</guid><wfw:comment>http://www.blogjava.net/rongxh7/comments/271982.html</wfw:comment><comments>http://www.blogjava.net/rongxh7/archive/2009/05/21/271982.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.blogjava.net/rongxh7/comments/commentRss/271982.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rongxh7/services/trackbacks/271982.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 系统功能: 开发一个计算器服务CalculateService，这个服务包含加(plus)、减(minus)、乘(multiply)<br><br>、除(divide)的操作。<br><br>开发前准备：下载Axis2的最新版本Axis2 1.4.1 Release，网址<br><br>http://ws.apache.org/axis2/download/1_4_1/download.cgi，选择Standard Binary Distribution<br><br>的.zip包即"axis2-1.4.1-bin.zip"这个文件，解压缩得到的目录名axis2-1.4.1，目录内的文件结构如<br><br>下：&nbsp;&nbsp;<a href='http://www.blogjava.net/rongxh7/archive/2009/05/21/271982.html'>阅读全文</a><img src ="http://www.blogjava.net/rongxh7/aggbug/271982.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rongxh7/" target="_blank">心梦帆影</a> 2009-05-21 15:13 <a href="http://www.blogjava.net/rongxh7/archive/2009/05/21/271982.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>是它的Bug还是我的错误：EJB的WebService客户端报LazyInitializationException异常</title><link>http://www.blogjava.net/rongxh7/archive/2009/04/26/267560.html</link><dc:creator>心梦帆影</dc:creator><author>心梦帆影</author><pubDate>Sun, 26 Apr 2009 05:27:00 GMT</pubDate><guid>http://www.blogjava.net/rongxh7/archive/2009/04/26/267560.html</guid><wfw:comment>http://www.blogjava.net/rongxh7/comments/267560.html</wfw:comment><comments>http://www.blogjava.net/rongxh7/archive/2009/04/26/267560.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/rongxh7/comments/commentRss/267560.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rongxh7/services/trackbacks/267560.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要:     本文是我用EJB+JPA(Hibernate实现)+Web Service开发时，遇到的一些问题，查了许多地方，都找不到答案，请各位朋友耐心读一下本文，有想法的欢迎留言！谢谢！ <br>    有个疑问：是不是设置的lazy加载，即使没有用到，也会加载的？即使会加载的，为什么我在服务器端测试时能正常，而在Web Service的客户端测试时，却报错？&nbsp;&nbsp;<a href='http://www.blogjava.net/rongxh7/archive/2009/04/26/267560.html'>阅读全文</a><img src ="http://www.blogjava.net/rongxh7/aggbug/267560.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rongxh7/" target="_blank">心梦帆影</a> 2009-04-26 13:27 <a href="http://www.blogjava.net/rongxh7/archive/2009/04/26/267560.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>