Java Reference
In-Depth Information
//Create a proxy to get a port stub from
Service service = Service.create(wsdlLocation, serviceName);
// Return a list of QNames of ports
System.out.println("QNames of service endpoints:");
Iterator<QName> it = service.getPorts();
QName lastEndpoint = null;
while (it.hasNext()) {
lastEndpoint = it.next();
System.out.println("Name: " + lastEndpoint);
//prints: Name: {http://ch03.soacookbook.com/}HelloWSPort
}
// Get the Hello stub
Hello hello = service.getPort(lastEndpoint, Hello.class);
//Invoke the business method
String result = hello.sayHello("Duke");
System.out.println("\nResponse: " + result);
}
}
The comments within the file should indicate what's happening. I want to show the simplest
possible invocation of a service. The only part of the client that is not strictly necessary is the
iterator over the available endpoints. You could just have invoked the business method after
getting the port from the service.
Here is the output from invoking this program:
QNames of service endpoints:
Name: {http://ch03.soacookbook.com/}HelloWSPort
Response: Hello, Duke!
The client program lists the QName s available by reading the <port> child elements of the
<service> element on the WSDL, and there is a QName : {http://ch03.soacookbook.com/
}HelloWSPort . A QName is a combination of namespace and local part. The namespace in
QName 's toString method is enclosed in curly braces, and the local part is appended.
During invocation, the binding attribute of this QName is read, and the invoker is referred to
the <binding> element of the WSDL, which lists the operations that can be performed, and
the types necessary to use in messages during invocation of those operations. A stub is gener-
ated based on the interface specified, which the client program uses to call methods as if they
were local to the same JVM.
Search WWH ::




Custom Search