Java – Removing annotations and adding xml in developing JAX-WS webservice

javajax-wsweb services

I am a new bie to the world of webservices , I have one query as I was developing the JAX-WS the below web service both producer and client but I was using the annotaions could you please advise me how to develop the same program without use of annotations that is using XML ..itself..

Create A Web Service Endpoint Interface

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.RPC)
public interface HelloWorld{

    @WebMethod String getHelloWorldAsString(String name);

}

Create A Web Service Endpoint Implementation

import javax.jws.WebService;

//Service Implementation
@WebService(endpointInterface = "com.mkyong.ws.HelloWorld")
public class HelloWorldImpl implements HelloWorld{

    @Override
    public String getHelloWorldAsString(String name) {
        return "Hello World JAX-WS " + name;
    }

}

Create A Endpoint Publisher

import javax.xml.ws.Endpoint;
import com.mkyong.ws.HelloWorldImpl;

//Endpoint publisher
public class HelloWorldPublisher{

    public static void main(String[] args) {
       Endpoint.publish("http://localhost:9999/ws/hello", new HelloWorldImpl());
    }

}

Java Web Service Client Via Wsimport Tool

wsimport -keep http://localhost:9999/ws/hello?wsdl

It will generate necessary client files, which is depends on the provided wsdl file. In this case, it will generate one interface and one service implementation file.

finally the main class using the generated stub classes..

package com.mkyong.client;

import com.mkyong.ws.HelloWorld;
import com.mkyong.ws.HelloWorldImplService;

public class HelloWorldClient{

    public static void main(String[] args) {

        HelloWorldImplService helloService = new HelloWorldImplService();
        HelloWorld hello = helloService.getHelloWorldImplPort();

        System.out.println(hello.getHelloWorldAsString("mkyong"));

    }

}

Best Answer

I came across this question while having the same issue...

finally found the so needed explanation here: http://jonas.ow2.org/JONAS_5_1_1/doc/doc-en/pdf/jaxws_developer_guide.pdf

look for : Overriding annotations

Related Topic