JAX-WS web service

1.) Create a dynamic web project with the name “JAX-WS”.

2.) Create the web.xml file with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>JAX-WS</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

3.) Create a sample web service with right click on the project. Other/Web services/Create a sample web service. Follow the screenshot:

4.) Java service will be created:

package or.ait.webservices;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService()
public class Calculator {

	@WebMethod()
	public String sayHello(String name) {
	    System.out.println("Hello: " + name);
	    return "Hello " + name + "!";
	}
}

5.) Start Jboss application server and select “Run/Run on server” and deploy project.

6.) In the console log you will see a similar text:

22:05:35,182 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "JAX-WS.war" (runtime-name: "JAX-WS.war")
22:05:35,529 INFO  [org.jboss.ws.cxf.metadata] (MSC service thread 1-8) JBWS024061: Adding service endpoint metadata: id=Calculator
 address=http://localhost:8080/JAX-WS/Calculator
 implementor=or.ait.webservices.Calculator
 serviceName={http://webservices.ait.or/}CalculatorService
 portName={http://webservices.ait.or/}CalculatorPort
 annotationWsdlLocation=null
 wsdlLocationOverride=null
 mtomEnabled=false
22:05:36,161 INFO  [org.apache.cxf.service.factory.ReflectionServiceFactoryBean] (MSC service thread 1-8) Creating Service {http://webservices.ait.or/}CalculatorService from class or.ait.webservices.Calculator
22:05:37,506 INFO  [org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-8) Setting the server's publish address to be http://localhost:8080/JAX-WS/Calculator
22:05:37,728 INFO  [org.jboss.ws.cxf.deployment] (MSC service thread 1-8) JBWS024074: WSDL published to: file:/C:/projects/jbdevstudio/runtimes/jboss-eap/standalone/data/wsdl/JAX-WS.war/CalculatorService.wsdl
22:05:37,734 INFO  [org.jboss.as.webservices] (MSC service thread 1-2) JBAS015539: Starting service jboss.ws.port-component-link
22:05:37,738 INFO  [org.jboss.as.webservices] (MSC service thread 1-8) JBAS015539: Starting service jboss.ws.endpoint."JAX-WS.war".Calculator
22:05:37,758 INFO  [org.jboss.web] (ServerService Thread Pool -- 67) JBAS018210: Register web context: /JAX-WS
22:05:37,902 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS018559: Deployed "JAX-WS.war" (runtime-name : "JAX-WS.war")

7.) Check the wsdl created in your browser: (WSDL link) http://localhost:8080/JAX-WS/Calculator?wsdl

8.) Create the service client with ctrl+n select “web services” node from the nodes. Then select “web services client”. Past WSDL link into “Service definition” text field and press finish.

9.) Test client runnable with starting “ClientSample.java” in org.ait.test folder.

Tasks

1.) Modify Calculator cource code az add a calculate(int a, int b) function and recreate the client