Annotating a class with @WebService is not enough to implement a web service. We need a library that implements JAX-WS specification. There are a number of JAX-WS frameworks available, for example, Axis2, Apache CFX, and Glassfish Metro. In this chapter, we will use the Glassfish Metro implementation, which is also a reference implementation (https://jax-ws.java.net/) of JAX-WS from Oracle.
Let's add Maven dependency for the JAX-WS framework. Open pom.xml and add the following dependency:
<dependencies> <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-rt</artifactId> <version>2.2.10</version> </dependency> </dependencies>
Replace the previous version number with the latest version of the framework. The Metro framework also requires you to declare web service endpoints in the configuration file called sun-jaxws.xml. Create the sun-jaxws.xml file in the src/main/webapp/WEB-INF folder and add the endpoint as follows:
<?xml version="1.0" encoding="UTF-8"?> <endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
version="2.0"> <endpoint name="CourseService" implementation="packt.jee.eclipse.ws.soap.CourseManagementService" url-pattern="/courseService" /> </endpoints>
The endpoint implementation is the fully qualified name of our web service implementation class. url-pattern is just like servlet mapping that you specify in web.xml. In this case, any relative URL starting with /courseService would result in the invocation of our web service.