By Marone: July 2015
Soap web service hello world
Goal
This article describes how to create a simple soap web service without using a web container (stand alone).It needs only javax.xml.ws.Endpoint API and JAX-WS.Used technologies
JDK 1.7Interface: HelloWorld
package com.wstutorial.ws;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
@WebService
@SOAPBinding
public interface HelloWorld {
@WebMethod
String sayHelloWorld(String content);
}
Impelementation: HelloWorldImpl
package com.wstutorial.ws;
import javax.jws.WebService;
@WebService(endpointInterface = "com.wstutorial.ws.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
@Override
public String sayHelloWorld(String content) {
return "Hello " + content + " !";
}
}
Endpoint Publisher
package com.wstutorial.ws;
import javax.xml.ws.Endpoint;
public class Publisher {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8090/ws/helloworld", new HelloWorldImpl());
System.out.println("Service is running");
}
}
Call the url
http://localhost:8090/ws/helloworld?wsdlWSDL
<?xml version="1.0"?>
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://ws.wstutorial.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.wstutorial.com/" name="HelloWorldImplService">
<types>
<xsd:schema>
<xsd:import namespace="http://ws.wstutorial.com/" schemaLocation="http://localhost:8090/ws/helloworld?xsd=1"/>
</xsd:schema>
</types>
<message name="sayHelloWorld">
<part name="parameters" element="tns:sayHelloWorld"/>
</message>
<message name="sayHelloWorldResponse">
<part name="parameters" element="tns:sayHelloWorldResponse"/>
</message>
<portType name="HelloWorld">
<operation name="sayHelloWorld">
<input wsam:Action="http://ws.wstutorial.com/HelloWorld/sayHelloWorldRequest" message="tns:sayHelloWorld"/>
<output wsam:Action="http://ws.wstutorial.com/HelloWorld/sayHelloWorldResponse" message="tns:sayHelloWorldResponse"/>
</operation>
</portType>
<binding name="HelloWorldImplPortBinding" type="tns:HelloWorld">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="sayHelloWorld">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="HelloWorldImplService">
<port name="HelloWorldImplPort" binding="tns:HelloWorldImplPortBinding">
<soap:address location="http://localhost:8090/ws/helloworld"/>
</port>
</service>
</definitions>