Tuesday, 24 December 2013

Invoking the Simplest Web Service In Java

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 
//Create a Qualified Name that represents the 
//namespace and local part of the service
QName serviceName = new QName("http://ch03.soacookbook.com/", 
"HelloWSService");
//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);
}
}
Share it Please

0 comments:

Post a Comment

Copyright @ 2013 Learn About Computers and Programming. Designed by Templateism | Love for The Globe Press