Java Reference
In-Depth Information
1. Create the interface that the web service will implement, and to which clients, such as
your servlet, will refer.
2. Implement the web service.
3. Add the reference annotation to the servlet; an instance of the generated SEI will automat-
ically be injected.
Let's get to work.
Catalog.java in Example 6-4 is the interface that clients will refer to. It defines a simple op-
eration that returns a book title for a given identifier.
Example6-4.Catalog.java defines the service interface
package com.soacookbook.ch03;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
/**
* Public interface for CatalogWS impl.
*/
@WebService(targetNamespace="http://ns.soacookbook.com")
public interface Catalog {
@WebMethod
@WebResult(name="title")
String getTitle(
@WebParam(name="id") String id);
}
Note that you need to include the @WebService annotation on the interface, or the client will
complain. Also, the @WebService annotation must include the targetNamespace because
you want to customize it in your service implementation as well.
CatalogWS.java , shown in Example 6-5 , implements the service interface.
Example6-5.CatalogWS.java implements the service interface
package com.soacookbook.ch03;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
Search WWH ::




Custom Search