Part 3: Building a Web Service from an Existing WSDL
In this section you use the WSDL that was created for you in the last section as the source for a new web service.

A web service is described using Web Service Description Language (WSDL).
show more or less
A WSDL file contains information that defines exposed web service methods. You can use a JDeveloper wizard to interrogate a WSDL file and create all of the classes required to implement that definition. Because the WSDL is merely a skeleton definition of a web service, you won't get any implementation of the methods, only the method definitions. You will have to add the implementation code to the methods.
Step 1: Creating a Web Service from a WSDL
In the previous two sections you created web services using annotation and a wizard. In this section you create a web service from an existing WSDL file. For convenience, you will use the WSDL file you created in the last section of this tutorial.
  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. Name the project TopDown, leaving other values at their defaults. Click Finish.

    Create Generic project wizard

  3. Right-click the new TopDown project and select New.

    Application navigatory New

  4. In the New Gallery, select the Business Tier | Web Services node in the Categories list. Select the Java Web Service from WSDL item and click OK.

    new gallery

  5. In the Create Java Web Service from WSDL wizard, click Next to dismiss the Welcome page.

  6. In the Select Deployment Platform step of the wizard, ensure that the Java 1.5, with support for JAX-WS Annotation is selected as the deployment platform, and then click Next.

    create java web service from wsdl wizard

  7. In the Select Web Service Description step, you specify the source WSDL to be used in creating the web service. Click Browse and navigate to the WSDL you earlier saved (should be something like MyWebService1.wsdl). Select it and click Select.

    select web service description

  8. Notice the file path displays in the WSDL Document URL field. Click Next.

    w s d l document url

  9. Either click Finish to complete the process, or click Next to view all the defaulted options then click Finish. The image below shows the last page of the wizard.

    create java web service from wsdl wizard last step

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

  11. The Application Navigator now displays the Java web service and all the Java files.

    application navigator with TopDown project

  12. Double-click MyWebService1.wsdl in the Application Navigator. Notice the design of the WSDL in the editor.

    web service w s d l

    Remember that since the web service was created from the top down, the wizard created all the method headers, but you need to provide the method bodies.

  13. Set the sayHello() method to return something more reasonable. Double-click the file to open it in the editor.

    web service java code editor

  14. Set the return to "Hello " + arg0. This returns the word Hello followed by the value that is entered in the argument.

    say hello code

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

Step 2: Testing the Web Service
In this section you compile, deploy and test the web service. Just as before, you use the HTTP Analyzer for testing the web service. When you test web services using the analyzer, the service is compiled and deployed to the integrated server. The analyzer is then invoked, enabling you to send and receive values from the web service.
  1. In the Application Navigator, right-click the MyWebService1 node and from the context menu, select Test Web Service.

    This option invokes the integrated server, deploys the service, and then starts the HTTP Analyzer.

    test web service menu

    The top portion of the HTTP Analyzer editor displays the URL for the web service, WSDL URL, and exposed Operations.

    HTTP Analyzer

  2. In the Request area, enter <your name> in the arg0 field and click Send Request.

    analyzer request

    The analyzer then sends the request to the service and after a bit, the return parameter is displayed.

    analyzer response

  3. Close all the tabs in the editor and collapse the TopDown node in the Application Navigator.

    application navigator

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