Part 5: Creating a Web Service Proxy
If you need to access a web service from a Java client, you will need a java web service proxy. JDeveloper provides a wizard that will create one for you.
show more or less
The purpose of a proxy client is to provide access to the web services API as if it were a local service. All the web service proxy generator needs is the web service WSDL. From that, it determines the API and generates the required classes.

Step 1: Creating the Web Service Proxy

In this section, you use a wizard to generate a Java proxy for calling a web service. Once complete, you can create a client to connect to it and use it.

  1. Create a new empty project. Right-click the Annotation project node and select New. In the New Gallery, click the All Features tab and then select General > Projects in the Categories list and Custom Project in the Items list. Click OK.

    new gallery

  2. Create a new Generic Project and name it ClientTester and click Finish.

    create generic project fnish

  3. To use a client, you need to have the HTTP Analyzer up and running with one of your services. If it is not running, expand the Annotation project, and test the MyCompany class in the HTTP Analyzer. Confirm that it is up and working. (You could use any of the web services you created.)

    h t t p analyzer

  4. Right-click the WSDL URL from the analyzer Copy. Do not close the HTTP Analyzer tab.

  5. To generate the proxy, right-click the ClientTester project and select New.

    application navigator

  6. In the New Gallery, select the All Technologies tab. Expand the Business Tier node and select Web Services in the Categories list. Select the Web Service Client and Proxy item and click OK.

    new gallery

    This action invokes the Create Web Service Proxy wizard.

  7. Click Next to dismiss the Welcome page.

  8. In the Select Client Style page, select the JAX-WS Style and click Next.

    create web service proxy step 2

  9. In the Select Web Service Description page, you specify the location of the WSDL service.
    There are two ways you can reference the WSDL: URL and File.

    To use the URL, copy the URL from the HTTP Analyzer then paste it into the WSDL Document URL (such as http://localhost:7101/WebService-Annotation-context-root/MyCompanyPort).

    Then append to the URL: ?WSDL

    If you use the URL, then you must select the Copy WSDL into Project checkbox.

    create web service proxy step 3

    Alternatively you can use the browse button to find a WSDL file on your machine like you did earlier (for example,D:\Temp\MyWebService1.wsdl).

  10. Click Next.

  11. In the Specify Default Mapping Options, click Next to accept the default values. If you needed to change the Endpoint URL to point to a different server, you would do so here.

    create web service proxy step 5

  12. For the rest of the pages in the wizard, the default values are fine. Either click Next to examine the remaining steps, or click Finish to create the proxy.

    create web service proxy step 9

  13. Click Save All save all to save your work.

  14. Expand the ClientTester | Applications Sources | annotation | MyCompanyWSProxy nodes in the Application Navigator, which should look like the image below.

    application navigator

Step 2: Creating and Testing the Client Proxy

In this section you update the client class to invoke the web service proxy and return the result to the message window.

  1. In the Application Navigator, Double-click the class to open it in the editor.

    application navigator

  2. Add the following code to the main() method of the MyCompanyPortClient class:

    code editor
  3. Click Save All save all to save your work.

    Now you can test the client proxy.

  4. In the Application Navigator, right-click the file and select Run. (The HTTP Analyzer must be up and running to process the client request. If it is not up, go back to the Annotation project, right-click the file and select Test Web Service. If you get errors and the test does not run, shut down JDeveloper and restart it.)

    application navigator

  5. The results of the client can be viewed in the ClientTester.jpr -Log window. If successful, you should see Administration is at Redwood City.

    running log window

  6. Close all tabs in the editor, close the Run Manager window, and collapse all of the projects in the Application Navigator.

Bookmark Print Expand all | Hide all
Back to top
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.