Implementing a web service using an interface

All methods declared in our web service implementation class, CourseManagementService, are exposed as web service operations. However, if you want to expose only a limited set of methods from the web service implementation class, then you can use the Java interface. For example, if we want to expose only the getCourses method as a web service operation, then we can create an interface, let's say ICourseManagementService:

package packt.jee.eclipse.ws.soap; 
 
import java.util.List; 
 
import javax.jws.WebService; 
 
@WebService 
public interface ICourseManagementService { 
  public List<Course> getCourses(); 
} 

The implementation class also needs to be annotated with @WebService, with the endpointInterface attribute set to the interface name:

package packt.jee.eclipse.ws.soap; 
 
import java.util.ArrayList; 
import java.util.List; 
 
import javax.jws.WebService; 
 
@WebService 
(endpointInterface="packt.jee.eclipse.ws.soap.ICourseManagementService") public class CourseManagementService implements ICourseManagementService { //getCourses and getCourse methods follow here }

Now, restart Tomcat and inspect the WSDL. You will notice that only the getCourses operation is defined in the WSDL.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.163.229