FileDocCategorySizeDatePackage
FirstDynamicClient.javaAPI DocExample2629Mon Dec 16 13:26:38 GMT 2002ora.jwsnut.chapter6.client

FirstDynamicClient

public class FirstDynamicClient extends Object

Fields Summary
private static final String
SERVICE_URI
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

     
         
        
        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);
        }
    
public static voidusage()

        System.err.println("Usage: java FirstDynamicClient WSDLAddress");
        System.exit(1);