PreviousHomeNext Search

Creating a Web Service with JAX-RPC

This section describes how to build and deploy a simple Web service named MyHelloService using Sun ONE Studio 4 and Sun ONE Application Server 7. For the sake of brevity, instructions in this section refer to Sun ONE Studio 4 as the "IDE." After you've deployed MyHelloService, you can access it by the clients discussed in Creating Web Service Clients with JAX-RPC.

Note: The instructions that follow were written for Sun ONE Studio 4 update 1, Enterprise Edition. If you are running a later version, then you should refer to the Sun ONE Studio Programming Series for up to date instructions. (See Further Information.)

These are the basic steps for creating a Web service:

  1. Code and compile a class that implements the service's methods.
  2. Create the service: NewRight ArrowWeb ServicesRight ArrowWeb Service
  3. Generate the service's helper classes and WSDL file: Right-click the service node and choose Generate Web Service.
  4. Deploy the service: Right-click the service node and choose Deploy.

The sections that follow cover these steps in greater detail.

Verifying the IDE Settings

Before building MyHelloService, check the following.

Creating MyHelloService

  1. In the IDE, mount the file system at <INSTALL>/examples/jaxrpc.
  2. In the Explorer, expand the file system you just mounted.
  3. Expand the helloservice package.
  4. This package will contain all of the files for MyHelloService. If this is the first time you've gone through these instructions, then helloservice will contain a single file: the source code for SimpleGreeter.

  5. Right-click SimpleGreeter and choose Open.
  6. The Source Editor displays SimpleGreeter.java, which has two methods: sayHello and sayGoodbye. In a later step you will assign these methods to MyHelloService. At runtime, the service's remote clients will be able to invoke these methods.

  7. Right-click the Source Editor and choose Compile.
  8. Close the Output window and the Source Editor.
  9. Right-click the helloservice package and choose NewRight ArrowWeb ServicesRight ArrowWeb Service.
  10. The Web Service pane of the New wizard appears.

  11. In the wizard's Specify Web Service pane, do the following.
    1. In the Name field, enter MyHelloService.
    2. In the Package field, enter helloservice.
    3. For the Create From buttons, choose Java Methods.
    4. For the Architecture buttons, choose Web centric.
    5. Click Next.
  12. In the wizard's Select Methods pane, do the following.
    1. Expand the nodes in the helloservice package until you see the methods beneath the SimpleGreeter class.
    2. Choose the sayHello and sayGoodbye methods.
    3. Click Finish.

In the Explorer, a Web service node (a blue sphere in a cube) for MyHelloService appears.

Specifying the SOAP RPC URL

  1. Right-click the MyHelloService node, choose Properties, and examine the SOAP RPC URL property.
  2. This URL is sometimes called the service endpoint address. Remote clients of the service use this URL to locate the service. In a later step, you'll see that the URL is written to the service's WSDL file.

    The SOAP RPC URL property has the following syntax:


    The <host> is the name of the computer that is running the Web server and <port> is the server's port number. The <web-context> (sometimes called the context root), is a name that is mapped to the document root of the servlet that implements the Web service. The <url-pattern> is an arbitrary string which may contain forward slashes, for example, my/app/account. The <url-pattern> allows you to further qualify the URL. By default, the IDE assigns the name of the Web service (MyHelloService) to the <web-context> and <url-pattern> elements.

  3. For the SOAP RPC URL property, make sure that the port number matches the value you noted in Verifying the IDE Settings. If the host name is localhost and the port number is 80, then the SOAP RPC URL property should be:
  4. http://localhost:80/MyHelloService/MyHelloService

  5. If necessary, change the port number of the SOAP RPC URL.
  6. Close the Properties sheet.

Generating the Service's Helper Classes and WSDL File

  1. Right-click the MyHelloService Web service and choose Generate Web Service.
  2. The IDE creates the service's helper classes, placing them in the MyHelloServiceGen package and also creates the MyHelloService WSDL file. In the IDE's Explorer, a WSDL file icon appears as a blue sphere in the lower left corner of a rectangle.

    A WSDL file is an XML document that describes a particular service. WSDL files are important because they decouple the service and client development processes. A service provider make its WSDL file available to client developers. Using an IDE, a client developer specifies the WSDL file and generates the runtime classes needed by the client program. (See Building and Running the StaticStubHello Client.) Note that the client developer has access to the service's WSDL, but not to the service's libraries or source code.

  3. Right-click the MyHelloService WSDL and choose Open.
  4. In the Source Editor, scroll down to the bottom of the WSDL file.
  5. The location attribute of the soap:address element should match the property in Specifying the SOAP RPC URL, step 2.

  6. Close the Source Editor.

Deploying MyHelloService

  1. Right-click the MyHelloService Web service node and choose Deploy.
  2. To verify the deployment, do the following.
    1. Start the Admin Console of the Sun One Application Server 7.
    2. In the left pane of the Admin Console, expand these nodes: App Server InstancesRight Arrowserver1Right ArrowWeb Apps.
    3. The MyHelloService node should appear beneath Web Apps.

PreviousHomeNext Search

All of the material in The J2EE Tutorial for the Sun ONE Platform is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.