In order to create a service from Java code you are only required to add one annotation to your code. You must add the
@WebService
annotation on both the SEI and the implementation class.
The @WebService
annotation is defined by the javax.jws.WebService
interface and it is placed on
an interface or a class that is intended to be used as a service. @WebService
has the properties described in
Table 1.1
Table 1.1. @WebService
Properties
Property | Description |
---|---|
name | Specifies the name of the service interface. This property is mapped to the name attribute of the
wsdl:portType element that defines the service's interface in a WSDL contract. The default is to append PortType to the
name of the implementation class.
[a]
|
targetNamespace | Specifies the target namespace where the service is defined. If this property is not specified, the target namespace is derived from the package name. |
serviceName | Specifies the name of the published service. This property is mapped to the name attribute of the
wsdl:service element that defines the published service. The default is to use the name of the service's implementation class.
[a]
|
wsdlLocation | Specifies the URL where the service's WSDL contract is stored. This must be specified using a relative URL. The default is the URL where the service is deployed. |
endpointInterface | Specifies the full name of the SEI that the implementation class implements. This property is only specified when the attribute is used on a service implementation class. |
portName | Specifies the name of the endpoint at which the service is published. This property is mapped to the name attribute of the
wsdl:port element that specifies the endpoint details for a published service. The default is the append Port to the
name of the service's implementation class.[a] |
[a] When you generate WSDL from an SEI the interface's name is used in place of the implementation class' name. |
![]() | Tip |
---|---|
It is not necessary to provide values for any of the |
The SEI requires that you add the @WebService
annotation. Because the SEI is the contract that defines the service, you should specify
as much detail as possible about the service in the @WebService
annotation's properties.
Example 1.3 shows the interface defined in
Example 1.1 with the @WebService
annotation.
Example 1.3. Interface with the @WebService
Annotation
package com.fusesource.demo; import javax.jws.*; @WebService(name="quoteUpdater",targetNamespace="http:\\demos.fusesource.com",
serviceName="updateQuoteService",
wsdlLocation="http:\\demos.fusesource.com\quoteExampleService?wsdl",
portName="updateQuotePort")
public interface quoteReporter { public Quote getQuote(String ticker); }
The @WebService
annotation in Example 1.3 does the following:
Specifies that the value of the | |
Specifies that the target namespace of the service is | |
Specifies that the value of the | |
Specifies that the service will publish its WSDL contract at | |
Specifies that the value of the |
In addition to annotating the SEI with the @WebService
annotation, you also must annotate the service implementation class
with the @WebService
annotation. When adding the annotation to the service implementation class you only need to specify the
endpointInterface property. As shown in Example 1.4 the property must
be set to the full name of the SEI.
Example 1.4. Annotated Service Implementation Class
package org.eric.demo; import javax.jws.*; @WebService(endpointInterface="com.fusesource.demo.quoteReporter") public class stockQuoteReporter implements quoteReporter { public Quote getQuote(String ticker) { ... } }