KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > complexsoap > client > dynamic > Run


1 package complexsoap.client.dynamic;
2
3 import javax.xml.namespace.QName JavaDoc;
4
5 import org.apache.wsif.WSIFMessage;
6 import org.apache.wsif.WSIFOperation;
7 import org.apache.wsif.WSIFPort;
8 import org.apache.wsif.WSIFService;
9 import org.apache.wsif.WSIFServiceFactory;
10
11 import complexsoap.client.stub.com.cdyne.ws.LatLongReturn;
12
13 public class Run {
14     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
15         
16         // args[0] is the zip code
17
if (args.length != 2) {
18             System.out.println(
19                 "Usage: java complexsoap.client.dynamic.Run <wsdl location> <zip code>");
20             System.exit(1);
21         }
22         
23         // create a service factory
24
WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
25         WSIFService service =
26             factory.getService(
27                 args[0],
28                 null,
29                 null,
30                 "http://ws.cdyne.com",
31                 "Zip2GeoSoap");
32
33         // map types
34
service.mapType(
35             new QName JavaDoc("http://ws.cdyne.com", "LatLongReturn"),
36             Class.forName(
37                 "complexsoap.client.stub.com.cdyne.ws.LatLongReturn"));
38
39         // get the port
40
WSIFPort port = service.getPort();
41
42         // create the operation
43
WSIFOperation operation = port.createOperation("GetLatLong");
44
45         // create the input, output and fault messages associated with this operation
46
WSIFMessage input = operation.createInputMessage();
47         WSIFMessage output = operation.createOutputMessage();
48         WSIFMessage fault = operation.createFaultMessage();
49
50         // populate the input message
51
input.setObjectPart("zipcode", args[1]);
52         input.setObjectPart("LicenseKey", "");
53
54         // do the invocation
55
if (operation.executeRequestResponseOperation(input, output, fault)) {
56             // invocation succeeded, extract information from output
57
// message
58
LatLongReturn zipInfo =
59                 (LatLongReturn) output.getObjectPart("GetLatLongResult");
60             System.out.println(
61                 "This zip code is in "
62                     + zipInfo.getCity()
63                     + ","
64                     + zipInfo.getStateAbbrev()
65                     + " in "
66                     + zipInfo.getCounty()
67                     + " county\n"
68                     + "It extends from longitude "
69                     + zipInfo.getFromLongitude()
70                     + " to longitude "
71                     + zipInfo.getToLongitude()
72                     + "\n and from latitude "
73                     + zipInfo.getFromLatitude()
74                     + " to latitude "
75                     + zipInfo.getToLatitude());
76         } else {
77             System.out.println("Invocation failed");
78             // extract fault message info
79
}
80     }
81 }
82
Popular Tags