Java Reference
In-Depth Information
return "Hello, " + name + "!";
}
}
This service will accept a single parameter and return a string containing the parameter value.
Notice that both the interface and the implementation must have the @WebService annotation
for publishing and invoking using an Endpoint . The implementation points to its client-fa-
cing interface using the endpointInterface attribute of the @WebService annotation. This
is a fully qualified string.
NOTE
If you specify a value for the endpointInterface attribute in the @WebService annotation, the
interface will act as the service of record, and its further annotations will be honored while any sub-
sequent annotations in the implementing class will be ignored. This is why you specify the SOAP
binding in the interface.
That is all you need to do to create a web service in its most basic form. But it's not quite a
real web service until you publish it so that clients can invoke it. You do not need to use a web
container for this example. You will use the javax.xml.ws.Endpoint class to publish it to
the HTTP server internal to the Java SE 6 VM, as shown in Example 4-3 .
Example4-3.Publishing the web service endpoint
package com.soacookbook.ch03;
import javax.xml.ws.Endpoint;
public class HelloPublisher {
public static final String URI = "http://localhost:9999/hello";
public static void main(String[] args) {
//Create instance of service implementation
HelloWS impl = new HelloWS();
//Make available
Endpoint endpoint = Endpoint.publish(URI, impl);
//Test that it is available
boolean status = endpoint.isPublished();
System.out.println("Web service status = " + status);
}
}
Search WWH ::




Custom Search