KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > acme > MagicGBallJaxRpcClient


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.acme;
18
19 import java.net.URL JavaDoc;
20 import javax.xml.namespace.QName JavaDoc;
21 import javax.xml.rpc.Service JavaDoc;
22 import javax.xml.rpc.ServiceFactory JavaDoc;
23
24 public class MagicGBallJaxRpcClient {
25     public static void main(String JavaDoc[] args) {
26         if (args.length < 1) {
27             System.err.println("Please ask a question");
28             System.exit(-1);
29         }
30
31         try {
32             URL JavaDoc wsdlURL = new URL JavaDoc("http://localhost:8000/services/MagicGBall?wsdl");
33             String JavaDoc namespaceURI = "http://acme.org/magicGball";
34             QName JavaDoc serviceQName = new QName JavaDoc(namespaceURI, "MagicGBallService");
35             QName JavaDoc portQName = new QName JavaDoc(namespaceURI, "MagicGBallPort");
36
37             ServiceFactory JavaDoc serviceFactory = ServiceFactory.newInstance();
38             Service JavaDoc service = serviceFactory.createService(wsdlURL, serviceQName);
39             MagicGBallEndpoint mGball = (MagicGBallEndpoint) service.getPort(portQName, MagicGBallEndpoint.class);
40
41             for (int i = 0; i < args.length; i++) {
42                 String JavaDoc question = args[i];
43                 String JavaDoc answer = mGball.ask(question);
44                 System.out.println(answer);
45             }
46         } catch (Exception JavaDoc e) {
47             System.err.println(e.toString());
48         }
49     }
50 }
51
Popular Tags