|
FAQ
History |
|
Search
Feedback |
Creating a Web Service with JAX-RPC
This section describes how to build and deploy a simple Web service named
MyHelloServiceusing 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 deployedMyHelloService, 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:
The sections that follow cover these steps in greater detail.
Verifying the IDE Settings
Before building
MyHelloService, check the following.
- The Sun ONE Application Server 7 has been installed.
- In the Runtime pane of the Explorer, choose Server Registry
Installed Servers.
- Verify that the Sun One Application Server 7 is listed below Installed Servers. If it is not listed, then follow the instructions in Deploying Web Modules.
- The Sun ONE Application Server 7 is the default server.
- You know the server instance port number.
- Start the Admin Console of the Sun ONE Application Server 7.
- in the console's left pane, select Domains.
- In the tree of the left pane, expand the App Server Instances node and choose server1.
- Note the HTTP Port number in the right pane. In most installations, the default port number is 80. In a later section (Specifying the SOAP RPC URL), you will specify this number for
MyHelloService.Creating MyHelloService
- In the IDE, mount the file system at <
INSTALL>/examples/jaxrpc.- In the Explorer, expand the file system you just mounted.
- Expand the
helloservicepackage.This package will contain all of the files for
MyHelloService. If this is the first time you've gone through these instructions, thenhelloservicewill contain a single file: the source code forSimpleGreeter.- Right-click
SimpleGreeterand choose Open.The Source Editor displays
SimpleGreeter.java, which has two methods:sayHelloandsayGoodbye. In a later step you will assign these methods toMyHelloService. At runtime, the service's remote clients will be able to invoke these methods.- Right-click the Source Editor and choose Compile.
- Close the Output window and the Source Editor.
- Right-click the
helloservicepackage and choose NewWeb Services
Web Service.
The Web Service pane of the New wizard appears.
- In the wizard's Specify Web Service pane, do the following.
- In the wizard's Select Methods pane, do the following.
In the Explorer, a Web service node (a blue sphere in a cube) for
MyHelloServiceappears.Specifying the SOAP RPC URL
- Right-click the
MyHelloServicenode, choose Properties, and examine the SOAP RPC URL property.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:
http://<host>:<port>/<web-context>/<url-pattern>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.- 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
localhostand the port number is 80, then the SOAP RPC URL property should be:
http://localhost:80/MyHelloService/MyHelloService- If necessary, change the port number of the SOAP RPC URL.
- Close the Properties sheet.
Generating the Service's Helper Classes and WSDL File
- Right-click the
MyHelloServiceWeb service and choose Generate Web Service.The IDE creates the service's helper classes, placing them in the
MyHelloServiceGenpackage and also creates theMyHelloServiceWSDL 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.
- Right-click the
MyHelloServiceWSDL and choose Open.- In the Source Editor, scroll down to the bottom of the WSDL file.
The
locationattribute of thesoap:addresselement should match the property in Specifying the SOAP RPC URL, step 2.- Close the Source Editor.
Deploying MyHelloService
|
FAQ
History |
|
Search
Feedback |
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.