hengheng123456789

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  297 Posts :: 68 Stories :: 144 Comments :: 0 Trackbacks

You can create of Web services using a top-down approach (which starts with a WSDL file) or a bottom-up approach (which starts with a Java bean or EJB).

建立Web services有两种方式:

top-down :是从WSDL 开始,Top-down Web services development involves creating a Web service from a WSDL file.

bottom-up :是从Java bean or EJB开始,Bottom-up Web services development involves creating a Web service from a Java™ bean or enterprise bean.

通用的开发步骤有以下几步:

  1. Create a Web project.
  2. Create or import an artifact to be turned into a Web service.
  3. Create a Web service.
  4. Publish a business entity.
  5. Publish a Web service.

首先介绍一下top-down方式:

  1. Switch to the J2EE perspective (Window > Open Perspective > J2EE).
  2. In the Project Explorer view, select the WSDL file that you created or imported into the Web Content folder of your Web project.
  3. Click File > New > Other. Select Web Services in order to display the various Web service wizards. Select the Web Service wizard. Click Next.
  4. Web Services page: select Top down Java bean Web service as your Web service type. You can optionally choose to do the following:
    • Start the Web service in a Web project - if you do not select this option you will have to manually start the Web service. You must select this option to enable the other options on this page.
    • Launch the Web Services Explorer to publish your Web service to a UDDI registry.
    • Generate a Java?bean client proxy to the Web service. The Java bean client proxy that is generated provides a remote procedure call interface to the Web service.
    • Test the Web service - this allows you to test the Web service in the Web Service Explorer before a proxy is generated.
    • Send the Web service traffic through the TCP/IP Monitor, which allows you to watch the SOAP traffic generated by the Web service and to test this traffic for WS-I compliance. Note that this is only supported for Tomcat v4.0 and v4.1. If you are using Tomcat v5.0 and want to monitor the Web service traffic, you need to manually set up a TCP/IP monitor 
  5. Web Service Selection page: Enter the URI to the WSDL, WSIL, or HTML file that will be used to generate the Java bean. If you have selected the WSDL file before starting the wizard, this information should be prefilled. You can optionally generate a WSIL file from this file as well. Ensure that there are no spaces at the beginning of the URI or you may generate a null pointer exception.
  6. Service Deployment Configuration page: specify the server and client deployment settings.
    1. Click Edit and select the Apache Axis run-time environment and select the server on which you want to run your Web service and Web service client.
    2. Select the Web project in which you want your Web service created. The wizard will create this for you if they do not already exist.
    3. Select the type and name of project in which you want the Web service client created. If you enter the name of an existing project, the project type field must match that of the existing project. If you enter a name of a project that does not already exist, the wizard will create the project for you. Note that the only project type supported for Axis and SOAP run-time clients is a Web project. If you want the client to be created in a Java, EJB, or Application Client project, you must select the WebSphere   run-time environment for your client.
  7. Web Services Skeleton Java Bean Configuration page: Select the folder where the generated Java will be stored. If you want to review or edit the mappings between packages and namespaces, select the Define custom mapping for namespace to package check box. Click Next.
  8. Web Service Namespace to Package Mappings page: if you selected Define custom mapping for package to namespace on the previous panel, you can enter your custom mapping pairs on this panel by clicking Add. Click Next.
  9. Web Service Test page: If you selected to test the Web service, select the test facility for the generated Web service. This will open the Web service in the Web Services Explorer. Select the operation you want to test, enter the required information, and click Go. The result will display in the Status pane. Click Next.
  10. Web Service Proxy page: If you have selected to generate a proxy, this page shows the options for the proxy. It lists the folder where the proxy will be generated, and you can optionally create custom mappings between namespaces and packages. Click Next.
  11. Web Service Client Test page: Use this page to select the following options:
    1. Select your test facility. You can test the generated proxy in the Universal Test Client or the Web Service Explorer, or you can generate a sample Web service JSP.
    2. If you selected to test the proxy through a JSP, you can select the folder where the JSP will be located, and you can select the methods that will be included in the JSP.
    3. Select Run test on server to start the server for you automatically.
  12. Web Service Publication page: If you have selected to publish your Web service to a UDDI registry, use this page to launch the Web Services Explorer and select the UDDI registry to which the Web service will be published. Click Finish.

bottom-up方式:

  1. Switch to the J2EE perspective ( Window > Open Perspective > J2EE).
  2. In the Project Explorer view, select the bean that you created or imported into the source folder of your Web project.
  3. Click File > New > Other. SelectWeb Services in order to display the various Web service wizards. Select the Web Service wizard. Click Next.
  4. Web Services page: select Bottom up Java bean Web service as your Web service type. You can optionally choose to do the following:
    • Start the Web service in a Web project - if you do not select this option you will have to manually start the Web service. You must select this option to enable the other options on this page.
    • Launch the Web Services Explorer to publish your Web service to a UDDI registry.
    • Generate a Java bean client proxy to the Web service. The Java bean client proxy that is generated provides a remote procedure call interface to the Web service.
    • Test the Web service - this allows you to test the Web service in the Web Service Explorer before a proxy is generated.
    • Send the Web service traffic through the TCP/IP Monitor, which allows you to watch the SOAP traffic generated by the Web service and to test this traffic for WS-I compliance. Note that this is only supported for Tomcat v4.0 and v4.1. If you are using Tomcat v5.0 and want to monitor the Web service traffic, you need to manually set up a TCP/IP monitor 
  5. Object selection page: select the Java bean from which the Web service will be created.
  6. Service Deployment Configuration page: specify the server and client deployment settings.
    1. Click Edit and select the Apache Axis run-time environment and select the server on which you want to run your Web service and Web service client.
    2. Select the Web project in which you want your Web service created, and the EAR with which it will be associated. The wizard will create these for you if they do not already exist.
    3. Select the type and name of project in which you want the Web service client created. If you enter the name of an existing project, the project type field must match that of the existing project. If you enter a name of a project that does not already exist, the wizard will create the project for you. Note that the only project type supported for Axis and SOAP run-time clients is a Web project. If you want the client to be created in a Java, EJB, or Application Client project, you must select the WebSphere  run-time environment for your client.
    4. Select an existing EAR or enter a unique name to associate the Web service client with a different EAR than the Web service EAR. Note: Selecting different EARs for the Web service and Web service client can reduce the chance of encountering run time errors, but will use more system resources.
  7. A message will display stating that you have made a WS-I non-compliant selection. The Apache Axis run-time environment is not WS-I compliant. Select Ignore.
  8. Web Service Java Bean Identity page: the Web service URI and WSDL name will be listed. You?have the following options:
    • Select the methods to expose.
    • Select the encoding style. RPC/Encoded is the recommended encoding style for the Axis run-time environment. This encoding method is not WS-I compliant.
    • Select if you want to customize the package to namespace mappings.
    Click Next
  9. Web Service Package to Namespace Mappings page: if you selected Define custom mapping for package to namespace on the previous panel, you can enter your custom mapping pairs on this panel by clicking Add.
  10. Web Service Test page: If you selected to test the Web service, select the test facility for the generated Web service. This will open the Web service in the Web Services Explorer. Select the operation you want to test, enter the required information, and clickGo. The result will display in the Status pane. Click Next.
  11. Web Service Proxy page: if you have selected to generate a proxy, select if you want to customize the package to namespace mappings.
  12. Web Service Client Test page: Use this page to select the following options:
    1. Select your test facility. You can test the generated proxy in the Universal Test Client or the Web Service Explorer, or you can generate a sample Web service JSP.
    2. If you selected to test the proxy through a JSP, you can select the folder where the JSP will be located, and you can select the methods that will be included in the JSP.
    3. Select Run test on server to start the server for you automatically.
  13. Web Service Publication page: Select whether or not you want to publish this Web service to a UDDI registry. Click Finish . Note: you may see a warning stating Error in generating WSDL from Java. ClassNotFound: <bean name>. This error can be safely ignored.

最后我们可建立Web Service Client来验证Web Service 的使用。

首先需要发现Web services,步骤如下:

从UDDI 查找:

  1. Launch the Web Services Explorer
  2. Click UDDI Main.
  3. In the Actions pane select a registry from the drop-down list and click Go.
  4. In the Actions pane toolbar click the Find icon A picture of the Find icon..
  5. In the Actions pane, enter the name of the query, what you are searching for, the type of search that you want to perform, and any query information:
    1. Search for  This list allows you to search for businesses, services, or service interfaces.
      • Businesses Once you locate a business in the registry, use the icons in the Action pane toolbar to do the following:
        • View and edit business details
        • Get the services associated with that business
        • Publish a service
        • Manage referenced services
        • Manage publisher assertions
        • Add the business to Favorites
        • Unpublish the business
      • Services Once you locate a service in the registry, use the icons in the Action pane toolbar to do the following:
        • View and edit service details
        • Get the business associated with that service
        • Get the service interfaces associated with that service
        • Import the service WSDL file to the Eclipse workbench
        • Import the service WSDL file to the file system
        • Launch the Web Service wizards
        • Add the service to Favorites
        • Unpublish the service
      • Service interfaces Once you locate a service interface in the registry, use the icons in the Action pane toolbar to do the following:
        • View and edit interface details
        • Get the services associated with that service interface
        • Get the businesses associated with that service interface
        • Import the service interface WSDL file to the Eclipse workbench
        • Import the service interface WSDL file to the file system
        • Launch the Web Service wizards
        • Add the service interface to Favorites
        • Unpublish the service interface
    2. Type of search  These radio buttons allow you to specify a simple or advanced search, or a search by a Universal Unique Identifier (UUID).
      Simple
      Type the name of the businesses, services, or service interfaces for which you are searching. Note: The search set size is set to 100 and the maximum number of returned results is set to 10 by default.  If you would like to override the defaults, use the Advanced search.
      Advanced
      Allows you to enter more search options to focus the scope of your search. Select this option if you would like to search for multiple businesses or services.
      UUID
      Allow you to enter the UUID key.  The UUID key is the identifier that is associated with the published object.
  6. Once you have searched and discovered the business service description you desired, select the service or the service interface and click the Import icon to:
    • import the WSDL document into your Web project
    • import the WSDL document into the WSDL Explorer for testing
    • launch the Web Service Skeleton Creation wizard or Web Service Client wizard directly from the Web Services Explorer.

从WSIL 查找:

  1. From the Web Services Explorer toolbar, click the WSIL Page icon Picture of the WSIL Page icon..
  2. In the Navigator pane, click WSIL Main.
  3. In the URL to document field of the Actions pane enter the URL to the WSIL document or HTTP document that contains links to a WSIL document. Details on how an HTTP file can contain links to WSIL can be found here: http://www.ibm.com/developerworks/webservices/library/ws-wsilspec.html
  4. Once you have located the WSIL document, use the icons in the Action pane toolbar to do the following:
    • View WSIL document details
    • List all of the WSDL services associated with that WSIL document
    • List all of the UDDI services associated with that WSIL document
    • List all of the UDDI businesses associated with that WSIL document
    • List all of the WSIL links associated with that WSIL document
    • Import the WSIL document to the file system
    • Add the WSIL document to Favorites
    Important: If the IBM Web Services Explorer does not display the project that you would like to import your WSDL file to, ensure that you have created the project and/or click the Refresh icon.

建立Web Service Client:

  1. Switch to the J2EE perspective (Window > Open Perspective > J2EE).
  2. In the Navigator view, select the Web project in which you want to generate a sample application.
  3. Click File > New > Other. Select Web Services in order to display the various Web service wizards. Select the Web Service Client wizard. Click Next.
  4. Web Services page: Select the type of proxy to be generated, and whether or not it will be tested.
  5. Client Environment Configuration page: Select the run-time environment and the server for your Web service client.
    1. Click Explore Options and select the Apache Axis run-time environment and select the server on which you want to run your Web service client.
    2. Select the type and name of project in which you want the Web service client created.
      • If you enter the name of an existing project, the project type field must match that of the existing project. Ensure that the project selected as the Client Web Project is different from the Service Web Project, or the service will be overwritten by the client's generated artifacts.
      • If you enter a name of a project that does not already exist, the wizard will create the project for you.
      • Note that the only project type supported for Axis and SOAP run-time clients is a Web project. If you want the client to be created in a Java, EJB, or Application Client project, you must select the WebSphere run-time environment for your client.
  6. Web Service Selection page: Enter the URI to the WSDL, WSIL, or HTML file that will be used to generate the client. You can optionally generate a WSIL file from this file as well.
  7. Web Service Proxy page: This panel shows the options for the proxy. It lists the folder where the proxy will be generated, and you can optionally create custom mappings between namespaces and packages.
  8. Web Service Namespace to Package Mappings page: if you selected Define custom mapping for namespace to package on the previous page, you can enter your custom mapping pairs on this page by clicking Add.
  9. Web Service Client Test page: Select the test facility that you will use to test the proxy, and the methods that you want included in the proxy. Note that the Universal Test Client (UTC) is only compatible with Web service clients deployed on WebSphere servers.
  10. Click Finish. If you have selected to test the proxy, the test client will open in a browser window.
posted on 2007-02-28 16:40 哼哼 阅读(4645) 评论(0)  编辑  收藏 所属分类: JAVA-Web

只有注册用户登录后才能发表评论。


网站导航: