Creating a SOAP Service using JAX-WS Annotations

It is possible to create SOAP webservices with only a few lines of code using the JAX-WS annotations. In a productivity environment you might prefer using contract-first instead of code-first to create your webservice but for now we’re going to use the fast method and that means code-first and annotations olé!

A look at the WSDL

Running the Main class it’s now possible to take a look at the generated WSDL – it should be available at this URL: http://localhost:8090/soap/sample?WSDL

The generated WSDL could look like this

<?xmlversion="1.0"encoding="UTF-8"?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. --><definitionsxmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"xmlns:tns="http://soap.tutorial.hascode.com/"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns="http://schemas.xmlsoap.org/wsdl/"targetNamespace="http://soap.tutorial.hascode.com/"name="SampleServiceService"><types><xsd:schema><xsd:importnamespace="http://soap.tutorial.hascode.com/"schemaLocation="http://localhost:8090/soap/sample?xsd=1"></xsd:import></xsd:schema></types><messagename="getInfo"><partname="parameters"element="tns:getInfo"></part></message><messagename="getInfoResponse"><partname="parameters"element="tns:getInfoResponse"></part></message><messagename="doubleString"><partname="parameters"element="tns:doubleString"></part></message><messagename="doubleStringResponse"><partname="parameters"element="tns:doubleStringResponse"></part></message><portTypename="SampleService"><operationname="getInfo"><inputmessage="tns:getInfo"></input><outputmessage="tns:getInfoResponse"></output></operation><operationname="doubleString"><inputmessage="tns:doubleString"></input><outputmessage="tns:doubleStringResponse"></output></operation></portType><bindingname="SampleServicePortBinding"type="tns:SampleService"><soap:bindingtransport="http://schemas.xmlsoap.org/soap/http"style="document"></soap:binding><operationname="getInfo"><soap:operationsoapAction=""></soap:operation><input><soap:bodyuse="literal"></soap:body></input><output><soap:bodyuse="literal"></soap:body></output></operation><operationname="doubleString"><soap:operationsoapAction=""></soap:operation><input><soap:bodyuse="literal"></soap:body></input><output><soap:bodyuse="literal"></soap:body></output></operation></binding><servicename="SampleServiceService"><portname="SampleServicePort"binding="tns:SampleServicePortBinding"><soap:addresslocation="http://localhost:8090/soap/sample"></soap:address></port></service></definitions>