webservicesIn this tutorial we will show how to deploy a JAX-WS Web service on JBoss AS 7. You will see how you can easily deploy and test a Web service in the new application server release.

In order to use Web services in the new application server release you need the following extension in your configuration file:

<extension module="org.jboss.as.webservices"/>					
If you are using JBoss AS 7.1.1 this extension is already included in the standalone.xml configuration file, otherwise earlier releases include it in the -preview.xml configuration files so for example if you want to start the standalone server and user webservices you need to use the --server-config option. For example:

standalone.bat --server-config=standalone-preview.xml  

JBoss AS 7 ships with Apache CXF web services implementation. Apache CXF is an open source services framework. CXF helps you build and develop services using frontend programming APIs, like JAX-WS and JAX-RS. These services can speak a variety of protocols such as SOAP, XML/HTTP, RESTful HTTP, or CORBA and work over a variety of transports such as HTTP, JMS or JBI.

So let's create a simple Web service contained in a Web application:

package com.sample;

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

public interface Math {
 public long sum(long a, long b);

And this is the corresponding Web service implementation:
package com.sample;

import javax.jws.WebService;

@WebService(endpointInterface = "com.sample.Math", serviceName = "MathWS")

public class MathWS implements Math 

  public long sum(long a, long b)
    System.out.println("Summing "+a+" + "+b);
    return a+b;
As this Web service is implemented as a Servlet, we need registering the Servlet into the web.xml as usual:

Now deploy the Web application and verify from that the Web service has been published. (We have used a Web application named balance.war).

In AS7 you don't have anymore the jbossws Web application but you can use the new Web management at http://localhost:9900/console

In the Web tab you can find the Web services link where you can see the list of the Web services published.
JBoss 7 Web service tutorial
Now writing an Apache CXF client is just a matter of seconds:

package com.sample;

import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

public class Client {

    public static void main(String args[]) throws Exception {

        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

        factory.getInInterceptors().add(new LoggingInInterceptor());
        factory.getOutInterceptors().add(new LoggingOutInterceptor());
        Math client = (Math) factory.create();

        System.out.println("Server said: " + client.sum(3,4));




Related articles available on mastertheboss.com

JBoss web services

JAX-WS simplifies the development model for a web service endpoin

What is a Web Service One Way invocation?

JBoss recipe of the day

Asynchronous web services with JBoss WS

Developing rigorous and responsive web service client application

How to change the default Web Service deployment Port ?

JBoss recipe of the day

Using Axis Web Services with JBoss

Still not ready for JBoss WS ? if you don't have a JDK 1.5 compli

Invoking JBoss Web Services with Flex

Flex® is a free, open source framework for building highly in