| Home Page |
| Course Page |
Acknowledgment
Overview
Source Code
Demonstration
HTTP Messages
This example is taken from Martin Kalin, Java Web Services: Up and Running (O'Reilly, 2009).
Write a simple time server in Java and publish it as a SOAP-based web service.
The example uses the Java API for XML Web Services (JAX-WS) that is part of the standard Java platform starting with JDK 1.6. All code must be compiled and executed using JDK 1.6. The API is in package javax.jws, package javax.xml, and their subpackages.
For further information, see the Metro Web Services Stack web site (http://metro.java.net/).
$ java ch01.ts.TimeServerPublisher localhost 56789
$ java ch01.ts.TimeClient localhost 56789 Sun Jan 31 12:17:15 EST 2010 1264958235807
To watch the HTTP traffic between the client and the server, use the tcpmon utility. Download tcpmon.jar from https://tcpmon.dev.java.net/.
$ java -jar tcpmon.jar &
$ java ch01.ts.TimeClient localhost 8080 Sun Jan 31 14:14:44 EST 2010 1264965285026
<?xml version="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.1 in JDK 6. -->
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.1 in JDK 6. -->
<definitions
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://ts.ch01/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://ts.ch01/"
name="TimeServerImplService">
<types></types>
<message name="getTimeAsString"></message>
<message name="getTimeAsStringResponse">
<part name="return" type="xsd:string"></part>
</message>
<message name="getTimeAsElapsed"></message>
<message name="getTimeAsElapsedResponse">
<part name="return" type="xsd:long"></part>
</message>
<portType name="TimeServer">
<operation name="getTimeAsString" parameterOrder="">
<input message="tns:getTimeAsString"></input>
<output message="tns:getTimeAsStringResponse"></output>
</operation>
<operation name="getTimeAsElapsed" parameterOrder="">
<input message="tns:getTimeAsElapsed"></input>
<output message="tns:getTimeAsElapsedResponse"></output>
</operation>
</portType>
<binding name="TimeServerImplPortBinding" type="tns:TimeServer">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"></soap:binding>
<operation name="getTimeAsString">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal" namespace="http://ts.ch01/"></soap:body>
</input>
<output>
<soap:body use="literal" namespace="http://ts.ch01/"></soap:body>
</output>
</operation>
<operation name="getTimeAsElapsed">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal" namespace="http://ts.ch01/"></soap:body>
</input>
<output>
<soap:body use="literal" namespace="http://ts.ch01/"></soap:body>
</output>
</operation>
</binding>
<service name="TimeServerImplService">
<port name="TimeServerImplPort" binding="tns:TimeServerImplPortBinding">
<soap:address location="http://localhost:8080/ts"></soap:address>
</port>
</service>
</definitions>
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getTimeAsString xmlns:ns2="http://ts.ch01/"/>
</S:Body>
</S:Envelope>
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getTimeAsStringResponse xmlns:ns2="http://ts.ch01/">
<return>Sun Jan 31 14:14:44 EST 2010</return>
</ns2:getTimeAsStringResponse>
</S:Body>
</S:Envelope>
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getTimeAsElapsed xmlns:ns2="http://ts.ch01/"/>
</S:Body>
</S:Envelope>
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getTimeAsElapsedResponse xmlns:ns2="http://ts.ch01/">
<return>1264965285026</return>
</ns2:getTimeAsElapsedResponse>
</S:Body>
</S:Envelope>
| Course Page |
| Home Page |