Java Reference
In-Depth Information
Invoking the Simplest Web Service
Problem
You deployed the Hello web service using Endpoint in Creating and Deploying the Simplest
Web Service , and now you want to call it.
Solution
This solution assumes that you have already deployed the web service according to Creating
and Deploying the Simplest Web Service . Recall that this service is deployed within the HTTP
server that ships with JDK 6, and not to a container.
To call the web service, create a URL that points to the WSDL location, and then create a
QName object to represent the name of the service as specified in the name attribute of the
WSDL's <service> element. Then create a service instance based on those two locators. The
service instance gives you a representation of the port, which corresponds to the interface. You
can think of this process as being somewhat analogous to getting the business interface from
an EJB Home. This is the same process you would do if you had used the wsimport tool.
Once you have the port type, which will be your interface type, you can start invoking busi-
ness methods. Example 6-2 shows a complete listing.
Example6-2.Hello web service client, HelloClient.java
package com.soacookbook.ch03;
import java.net.URL;
import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
public class HelloClient {
public static void main(String[] args) throws Exception {
//Specify the WSDL
URL wsdlLocation = new URL("http://localhost:9999/hello?wsdl");
//Create a Qualified Name that represents the
//namespace and local part of the service
QName serviceName = new QName("http://ch03.soacookbook.com/",
"HelloWSService");
Search WWH ::




Custom Search