LibraryLink ToToggle FramesPrintFeedback

Required Annotations

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


[Tip]Tip

It is not necessary to provide values for any of the @WebService annotation's properties. However, it is recommended that you provide as much information as you can.

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", 1
            targetNamespace="http:\\demos.fusesource.com", 2
	        serviceName="updateQuoteService", 3
            wsdlLocation="http:\\demos.fusesource.com\quoteExampleService?wsdl", 4
            portName="updateQuotePort") 5
public interface quoteReporter
{
  public Quote getQuote(String ticker);
}

The @WebService annotation in Example 1.3 does the following:

1

Specifies that the value of the name attribute of the wsdl:portType element defining the service interface is quoteUpdater.

2

Specifies that the target namespace of the service is http:\\demos.fusesource.com.

3

Specifies that the value of the name of the wsdl:service element defining the published service is updateQuoteService.

4

Specifies that the service will publish its WSDL contract at http:\\demos.fusesource.com\quoteExampleService?wsdl.

5

Specifies that the value of the name attribute of the wsdl:port element defining the endpoint exposing the service is updateQuotePort.

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.