01: package complexsoap.client.dynamic;
02:
03: import javax.xml.namespace.QName;
04:
05: import org.apache.wsif.WSIFMessage;
06: import org.apache.wsif.WSIFOperation;
07: import org.apache.wsif.WSIFPort;
08: import org.apache.wsif.WSIFService;
09: 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[] args) throws Exception {
15:
16: // args[0] is the zip code
17: if (args.length != 2) {
18: System.out
19: .println("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 = factory.getService(args[0], null, null,
26: "http://ws.cdyne.com", "Zip2GeoSoap");
27:
28: // map types
29: service
30: .mapType(
31: new QName("http://ws.cdyne.com",
32: "LatLongReturn"),
33: Class
34: .forName("complexsoap.client.stub.com.cdyne.ws.LatLongReturn"));
35:
36: // get the port
37: WSIFPort port = service.getPort();
38:
39: // create the operation
40: WSIFOperation operation = port.createOperation("GetLatLong");
41:
42: // create the input, output and fault messages associated with this operation
43: WSIFMessage input = operation.createInputMessage();
44: WSIFMessage output = operation.createOutputMessage();
45: WSIFMessage fault = operation.createFaultMessage();
46:
47: // populate the input message
48: input.setObjectPart("zipcode", args[1]);
49: input.setObjectPart("LicenseKey", "");
50:
51: // do the invocation
52: if (operation.executeRequestResponseOperation(input, output,
53: fault)) {
54: // invocation succeeded, extract information from output
55: // message
56: LatLongReturn zipInfo = (LatLongReturn) output
57: .getObjectPart("GetLatLongResult");
58: System.out.println("This zip code is in "
59: + zipInfo.getCity() + ","
60: + zipInfo.getStateAbbrev() + " in "
61: + zipInfo.getCounty() + " county\n"
62: + "It extends from longitude "
63: + zipInfo.getFromLongitude() + " to longitude "
64: + zipInfo.getToLongitude()
65: + "\n and from latitude "
66: + zipInfo.getFromLatitude() + " to latitude "
67: + zipInfo.getToLatitude());
68: } else {
69: System.out.println("Invocation failed");
70: // extract fault message info
71: }
72: }
73: }
|