FAQ
History |
Previous Home Next |
Search
Feedback |
DividerCreating 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 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:
- Code and compile a class that implements the service's methods.
- Create the service: NewRight ArrowWeb ServicesRight ArrowWeb Service
- Generate the service's helper classes and WSDL file: Right-click the service node and choose Generate Web Service.
- 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.
- The Sun ONE Application Server 7 has been installed.
- In the Runtime pane of the Explorer, choose Server RegistryRight ArrowInstalled 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.
- In the Runtime pane of the Explorer, expand Server RegistryRight ArrowDefault Servers.
- Verify that beneath Default Servers there is a node for Web Tier Applications:
server1(
host
:
port
)
.- If this node is not displayed, then follow the instructions in the Sun ONE Studio 4, Enterprise Edition for Java Tutorial.
- 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
helloservice
package.This package will contain all of the files for
MyHelloService
. If this is the first time you've gone through these instructions, thenhelloservice
will contain a single file: the source code forSimpleGreeter
.- Right-click
SimpleGreeter
and choose Open.The Source Editor displays
SimpleGreeter.java
, which has two methods:sayHello
andsayGoodbye
. 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
helloservice
package and choose NewRight ArrowWeb ServicesRight ArrowWeb Service.The Web Service pane of the New wizard appears.
- In the wizard's Specify Web Service pane, do the following.
- In the Name field, enter
MyHelloService
.- In the Package field, enter
helloservice
.- For the Create From buttons, choose Java Methods.
- For the Architecture buttons, choose Web centric.
- Click Next.
- In the wizard's Select Methods pane, do the following.
- Expand the nodes in the
helloservice
package until you see the methods beneath theSimpleGreeter
class.- Choose the
sayHello
andsayGoodbye
methods.- Click Finish.
In the Explorer, a Web service node (a blue sphere in a cube) for
MyHelloService
appears.Specifying the SOAP RPC URL
- Right-click the
MyHelloService
node, 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
localhost
and 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
MyHelloService
Web service and choose Generate Web Service.The IDE creates the service's helper classes, placing them in the
MyHelloServiceGen
package and also creates theMyHelloService
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.
- Right-click the
MyHelloService
WSDL and choose Open.- In the Source Editor, scroll down to the bottom of the WSDL file.
The
location
attribute of thesoap:address
element should match the property in Specifying the SOAP RPC URL, step 2.- Close the Source Editor.
Deploying MyHelloService
- Right-click the
MyHelloService
Web service node and choose Deploy.- To verify the deployment, do the following.
- Start the Admin Console of the Sun One Application Server 7.
- In the left pane of the Admin Console, expand these nodes: App Server InstancesRight Arrowserver1Right ArrowWeb Apps.
The
MyHelloService
node should appear beneath Web Apps.
FAQ
History |
Previous Home Next |
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.