ws

JAX-WS client without tool

  • WsClient.java
  • SimpleWsService.java
  • pom.xml

WsClient.java

package com.training.ws;

import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;

public class WsClient {

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

        URL url = new URL(
                "http://localhost:9080/jax_ws_wsgen_tool/SimpleWsService?wsdl");

        QName qName = new QName("http://ws.training.com/", "SimpleWsService");

        Service service = Service.create(url, qName);

        SimpleWsService port = service.getPort(SimpleWsService.class);

        System.out.println(port.getServiceName());

        System.out.println(port.hello("user"));

    }

}

SimpleWsService.java

package com.training.ws;

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

@WebService
public interface SimpleWsService {

    @WebMethod(action = "getServiceNameAction", operationName = "getServiceName", exclude = false)
    String getServiceName();

    @WebMethod(action = "helloAction", operationName = "hello", exclude = false)
    String hello(@WebParam(name = "nameParam") String name);
}

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.training.rs</groupId>
    <artifactId>jax_ws_client_without_tool</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

</project>