background image

Web Service Client

<< Deciding on Remote or Local Access | The Contents of an Enterprise Bean >>
<< Deciding on Remote or Local Access | The Contents of an Enterprise Bean >>

Web Service Client

Although it is uncommon, it is possible for an enterprise bean to allow both remote and local
access. If this is the case, either the business interface of the bean must be explicitly designated as
a business interface by being decorated with the @Remote or @Local annotations, or the bean
class must explicitly designate the business interfaces by using the @Remote and @Local
annotations. The same business interface cannot be both a local and remote business interface.
Web Service Clients
A web service client can access a Java EE application in two ways. First, the client can access a
web service created with JAX-WS. (For more information on JAX-WS, see
Chapter 16,
"Building Web Services with JAX-WS."
) Second, a web service client can invoke the business
methods of a stateless session bean. Message beans cannot be accessed by web service clients.
Provided that it uses the correct protocols (SOAP, HTTP, WSDL), any web service client can
access a stateless session bean, whether or not the client is written in the Java programming
language. The client doesn't even "know" what technology implements the service: stateless
session bean, JAX-WS, or some other technology. In addition, enterprise beans and web
components can be clients of web services. This flexibility enables you to integrate Java EE
applications with web services.
A web service client accesses a stateless session bean through the bean's web service endpoint
implementation class. By default, all public methods in the bean class are accessible to web
service clients. The @WebMethod annotation may be used to customize the behavior of web
service methods. If the @WebMethod annotation is used to decorate the bean class's methods,
only those methods decorated with @WebMethod are exposed to web service clients.
For a code sample, see
"A Web Service Example: helloservice" on page 665
.
Method Parameters and Access
The type of access affects the parameters of the bean methods that are called by clients. The
following topics apply not only to method parameters but also to method return values.
Isolation
The parameters of remote calls are more isolated than those of local calls. With remote calls, the
client and bean operate on different copies of a parameter object. If the client changes the value
of the object, the value of the copy in the bean does not change. This layer of isolation can help
protect the bean if the client accidentally modifies the data.
In a local call, both the client and the bean can modify the same parameter object. In general,
you should not rely on this side effect of local calls. Perhaps someday you will want to distribute
your components, replacing the local calls with remote ones.
Defining Client Access with Interfaces
Chapter 20 · Enterprise Beans
639