rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

WebSphere Service Registry and Repository(以下称为Service Registry)是用于查询和管理可重用服务文档的*存储库,包括Web服务描述语言(WSDL),服务组件定义语言(SCDL),可扩展标记语言(XML)和XML模式定义(XSD)文档类型。 使用Service Registry,您可以轻松查询这些文档,并将它们用作新的复合应用程序的构建基块。 使用Service Registry Eclipse插件,您可以向Service Registry查询WSDL文档,然后将文档导入到现有的Web项目中,以创建客户端来使用WSDL文档中描述的Web服务。

从工具的角度来看,我们将使用基于Eclipse的WebSphere Software V7的Rational Application Developer(以下称为Application Developer)来生成JavaServer Pages(JSP)Web应用程序客户端以使用公共Web服务。 Application Developer包括用于各种开发角色的插件和向导,例如Java™程序员,数据库,J2EE和Web Services开发人员。

先决条件

为了完成本文中的步骤,您必须满足以下先决条件:

  • 在Windows操作环境中安装Application Developer。
  • 安装Service Registry V6(对于Application Developer安装是本地的)。
  • 安装Service Registry Eclipse插件SA02。
  • 创建一个名为SampleEAR的企业应用程序项目,其中包含一个名为SampleClient的动态Web项目。
  • 安装WebSphere Application Server(以下称为Application Server)V6.1测试环境。
  • 确保您具有Internet连接。

加载WSDL文档

首先,您需要发布描述公共Web服务MightyMaxims到服务注册表的WSDL文档。 可从www.xmethods.net获得的该Web服务在调用时返回随机报价。

首先,通过选择Applications => Enterprise Applications => ServiceRegistry从WebSphere管理控制台启动Service Registry。

  1. 通过将浏览器指向http:// localhost:< 嵌入式HTTP端口 > / ServiceRegistry ,打开Service Registry控制台,如图1所示 注:要获取< 嵌入式HTTP端口 >,请在WebSphere管理控制台中选择服务器=>应用程序服务器=> server1 =>端口=> WC_defaulthost
    图1.服务注册表控制台
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...
  2. 展开服务凭证,然后选择加载凭证
  3. 在图2所示的“加载文档”页面上,执行以下操作:
    • 选择“ 远程文件位置”
    • 在“ 远程文件位置”字段中输入http://saintbook.org/MightyMaxims/MightyMaxims.asmx?WSDL
    • 选择WSDL作为文档类型。
    • 输入文档描述和版本,然后单击确定
    图2.加载WSDL文档
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...
  4. 图3显示WSDL文档已成功上传到Service Registry。 验证文档的描述和版本。
    图3. WSDL文档上传状态
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...
  5. 选择“ 定制属性” (在右侧的“ 其他属性 ”下)以查看WSDL文档的元数据属性,如图4所示。
    图4. WSDL文档的定制属性
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

配置服务注册表Eclipse插件

接下来,您需要在Application Developer中配置Service Registry Eclipse插件(SA02)。 SA02使您可以从Eclipse环境上载,查询和编辑服务文档。 安装插件后,将Service Registry视图添加到您的开发工作区中,其中服务文档分类为Concepts(GenericObject),WSDL,XML和XSD。

  1. 通过选择开始=>程序=> IBM软件开发平台=> IBM Rational Application Developer => IBM Rational Application Developer打开Application Developer
  2. 在开发工作区中,选择Windows => Preferences => Service Registry => WSRR Locations
  3. 在“ WSRR位置”对话框中,单击“ 添加”以配置新的Service Registry位置,如图5所示。
    图5. WSRR Locations对话框
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...
  4. 在“ 添加服务注册表首选项”对话框中,输入以下值,如图6所示,然后单击“ 确定”
    • 别名WSRR6.0.0.2
    • 主机localhost
    • 端口<RMI connector port> 要获取<RMI连接器端口>,在WebSphere管理控制台中,选择服务器=>应用程序服务器=> server1 =>端口=> BOOTSTRAP_ADDRESS
    • 安全性
    图6.添加服务注册表首选项
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...
  5. WSRR Locations对话框显示新条目,如图7所示。
    图7. WSRR位置条目
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

检索WSDL文档

在本部分中,您将从系统注册表视图中查询上载的WSDL文档。 您将执行通配符查询,该查询返回所有上载到Service Registry的WSDL文档。 要限制搜索条件,您可以根据文档类型,名称空间,版本和元数据过滤结果。

  1. 打开系统注册表视图,通过选择Window =>显示视图=>其他 ,然后双击服务注册表中的显示视图对话框的服务注册表文件夹下,如图8。
    图8.显示视图对话框
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...
  2. 图9在Web透视图中显示了Service Registry视图。
    图9.服务注册表视图
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...
  3. 在Service Registry视图中右键单击WSDL Documents ,然后选择Retrieve WSDLs ,如图10所示。
    图10.检索WSDL
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...
  4. 如图11所示,“检索到的项目”对话框显示了上载到Service Registry的WSDL文档的查询结果。 验证是否检索到适当的服务文档,然后单击“ 确定”
    图11.检索到的WSDL文档
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...
  5. 在Service Registry视图中,您将看到WSDL Documents下列出的MightyMaxims.asmx?WSDL文档,如图12所示。
    图12. MightyMaxims WSDL文档
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

导入WSDL文档

要将MightyMaxims.asmx?WSDL导入动态Web项目SampleClient中,请执行以下操作:

  1. 在Service Registry视图中的WSDL Documents下,右键单击MightyMaxims.asmx?WSDL ,然后选择Import Document ,如图13所示。
    图13.导入WSDL文档
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...
  2. 在“ 导入WSRR文档”对话框中,如图14所示,展开SampleClient项目,然后选择WEB-INF文件夹。 输入或选择父文件夹字段将自动用SampleClient / WebContent / WEB-INF填充。 输入MightyMaxims.wsdl作为文件名,并选中生成文件夹结构 ,然后单击完成
    图14. Import WSRR Document对话框
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...
  3. 要验证是否成功导入了WSDL文档, 在Project Explorer视图中导航至SampleClient / WebContent / WEB-INF / saintbook.org / MightyMaxims ,然后双击MightyMaxims.wsdl以在WSDL编辑器中将其启动,如图15所示。 。
    图15. WSDL编辑器
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

测试WSDL文档

您可以使用Eclipse Web Services Explorer来验证公开的功能是否按预期工作,并查看SOAP请求和响应信封。

  1. 打开Web服务资源管理器中右击SampleClient /的WebContent / WEB-INF / saintbook.org / MightyMaxims / MightyMaxims.wsdl在Project Explorer视图,并选择Web服务=>测试与Web服务浏览器
  2. 在WSDL Binding Details对话框中,选择ForToday ,如图16所示。
    图16. Web服务浏览器
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...
  3. 在“调用WSDL操作”对话框中,单击执行以执行ForToday操作。 响应将显示在“ 状态”框中,如图17所示。
  4. 要查看SOAP请求和响应的信封,单击状态帧的右上角。
    图17.调用WSDL操作
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...
  5. 显示SOAP请求和响应信封,如图18所示。
    图18. SOAP请求和响应信封
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

生成Web服务客户端代理

现在,您需要生成示例JSP Web应用程序将其用作调用Web服务的中间层的代理类。 没有Java bean代理,您将无法生成示例JSP Web应用程序。

  1. 要打开Web服务客户端向导,请在Project Explorer视图中右键单击SampleClient / WebContent / WEB-INF / saintbook.org / MightyMaxims / MightyMaxims.wsdl文件,然后选择Web Services => Generate Client
  2. 在图19所示的Web Services对话框中,验证Service definition字段指向/SampleClient/WebContent/WEB-INF/saintbook.org/MightyMaxims/MightyMaxims.wsdl,并在Client type字段中选择Java Proxy ,然后单击下一步继续。
    图19. Web Service客户端对话框
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...
  3. 在“ Web服务代理页面”对话框中,如图20所示,验证“ 输出文件夹”字段是否指向/ SampleClient / src,并且在“ 安全性”配置字段中选择任何安全性 ,然后单击“ 完成”
  4. 当提示您启用Web部署描述符/SampleClient/WebContent/WEB-INF/web.xml的自动文件覆盖时,请单击“全部同意”。
    图20. Web服务代理页面
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...
  5. 要验证是否成功生成了代理类, 在Project Explorer视图中导航到SampleClient / JavaResources / com.TheQuoteForToday.www / MaximSoapProxy.java ,如图21所示。
    图21. Java bean代理
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

生成样本JSP客户端

要生成客户端,请执行以下操作:

  1. 在Project Explorer视图中,右键单击SampleClient / JavaResources / com.TheQuoteForToday.www / MaximSoapProxy.java ,然后选择Web Services => Generate Sample JSPs
  2. 在“ Web Service客户端测试”对话框中,验证是否选择了适当的值,如图22所示,然后单击“ 完成”
    图22.生成Web服务客户端
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...
  3. Web Services Test Client应用程序在配置的浏览器中启动。 在“ 方法”框中单击forToday() ,然后在“ 输入”框中单击“ 调用 ”。 响应将显示在Result框中,如图23所示。
    图23. Web服务测试客户端
    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

    查看全尺寸图片

    rational rosa_使用Rational Application Developer和WebSphere Service Registry and Repository生成Web服务客户端...

Summary

在本文中,您学习了如何将公共WSDL文档上载到Service Registry,然后使用Service Registry Eclipse插件将该文档导入Application Developer中的Web项目。 最后,您生成了一个Web服务代理类和一个示例JSP客户端以使用该Web服务。


翻译自: https://www.ibm.com/developerworks/websphere/library/techarticles/0803_yee/0803_yee.html