KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > hwRPCLit > client > Client


1 package demo.hwRPCLit.client;
2
3 import java.io.File JavaDoc;
4 import java.net.URL JavaDoc;
5
6 import javax.xml.namespace.QName JavaDoc;
7 import org.objectweb.hello_world_rpclit.GreeterRPCLit;
8 import org.objectweb.hello_world_rpclit.SOAPServiceRPCLit;
9 import org.objectweb.hello_world_rpclit.types.MyComplexStruct;
10
11 public final class Client {
12
13     private static final QName JavaDoc SERVICE_NAME =
14         new QName JavaDoc("http://objectweb.org/hello_world_rpclit", "SOAPServiceRPCLit");
15     private static final QName JavaDoc PORT_NAME =
16         new QName JavaDoc("http://objectweb.org/hello_world_rpclit", "SoapPortRPCLit");
17
18     private Client() {
19     }
20
21     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
22
23         if (args.length == 0) {
24             System.out.println("please specify wsdl");
25             System.exit(1);
26         }
27
28         URL JavaDoc wsdlURL;
29         File JavaDoc wsdlFile = new File JavaDoc(args[0]);
30         if (wsdlFile.exists()) {
31             wsdlURL = wsdlFile.toURL();
32         } else {
33             wsdlURL = new URL JavaDoc(args[0]);
34         }
35         
36         SOAPServiceRPCLit service = new SOAPServiceRPCLit(wsdlURL, SERVICE_NAME);
37         GreeterRPCLit greeter = (GreeterRPCLit)service.getPort(PORT_NAME, GreeterRPCLit.class);
38
39         System.out.println("Invoking sayHi...");
40         System.out.println("server responded with: " + greeter.sayHi());
41         System.out.println();
42
43         System.out.println("Invoking greetMe...");
44         System.out.println("server responded with: " + greeter.greetMe(System.getProperty("user.name")));
45         System.out.println();
46         
47         MyComplexStruct argument = new MyComplexStruct();
48         MyComplexStruct retVal = null;
49
50         String JavaDoc str1 = "this is element 1";
51         String JavaDoc str2 = "this is element 2";
52         int int1 = 42;
53
54         argument.setElem1(str1);
55         argument.setElem2(str2);
56         argument.setElem3(int1);
57         System.out.println("Invoking sendReceiveData...");
58
59         retVal = greeter.sendReceiveData(argument);
60
61         System.out.println("Response from sendReceiveData operation :");
62         System.out.println("Element-1 : " + retVal.getElem1());
63         System.out.println("Element-2 : " + retVal.getElem2());
64         System.out.println("Element-3 : " + retVal.getElem3());
65         System.out.println();
66
67
68         System.exit(0);
69     }
70 }
71
Popular Tags