if (args.length != 1) {
usage();
}
try {
QName serviceName = new QName(SERVICE_URI, "SmallBookService");
QName portName = new QName(SERVICE_URI, "SmallBookQueryPort");
ServiceFactory factory = ServiceFactory.newInstance();
Service service = factory.createService(new URL(args[0]), serviceName);
// Get a Call object for the getBookCount() method
Call call = service.createCall(portName, new QName(SERVICE_URI, "getBookCount"));
Object result = call.invoke(null);
int bookCount = ((Integer)result).intValue();
System.out.println("Number of books: " + bookCount);
// Get Call objects for the getBookTitle() and getBookAuthor methods
Call bookTitleCall = service.createCall(portName, new QName(SERVICE_URI, "getBookTitle"));
Call bookAuthorCall = service.createCall(portName, new QName(SERVICE_URI, "getBookAuthor"));
for (int i = 0; i < bookCount; i++) {
// Get the book title
result = bookTitleCall.invoke(new Object[] { new Integer(i) });
String title = (String)result;
System.out.print("Book title is [" + title + "], ");
// Get the book's author.
bookAuthorCall.invoke(new Object[] { title, null });
List list = bookAuthorCall.getOutputValues();
String author = (String)list.get(0);
System.out.println("author is [" + author + "]");
}
// Log successful completion
Call logCall = service.createCall(portName, new QName(SERVICE_URI, "log"));
logCall.invokeOneWay(new Object[] { "Successful completion." });
} catch (Exception ex) {
System.out.println(ex);
ex.printStackTrace(System.out);
}