001    /**
002     *
003     * Copyright 2003-2004 The Apache Software Foundation
004     *
005     *  Licensed under the Apache License, Version 2.0 (the "License");
006     *  you may not use this file except in compliance with the License.
007     *  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package org.acme;
018    
019    import java.net.URL;
020    import javax.xml.namespace.QName;
021    import javax.xml.rpc.Service;
022    import javax.xml.rpc.ServiceFactory;
023    
024    public class MagicGBallJaxRpcClient {
025        public static void main(String[] args) {
026            if (args.length < 1) {
027                System.err.println("Please ask a question");
028                System.exit(-1);
029            }
030    
031            try {
032                URL wsdlURL = new URL("http://localhost:8000/services/MagicGBall?wsdl");
033                String namespaceURI = "http://acme.org/magicGball";
034                QName serviceQName = new QName(namespaceURI, "MagicGBallService");
035                QName portQName = new QName(namespaceURI, "MagicGBallPort");
036    
037                ServiceFactory serviceFactory = ServiceFactory.newInstance();
038                Service service = serviceFactory.createService(wsdlURL, serviceQName);
039                MagicGBallEndpoint mGball = (MagicGBallEndpoint) service.getPort(portQName, MagicGBallEndpoint.class);
040    
041                for (int i = 0; i < args.length; i++) {
042                    String question = args[i];
043                    String answer = mGball.ask(question);
044                    System.out.println(answer);
045                }
046            } catch (Exception e) {
047                System.err.println(e.toString());
048            }
049        }
050    }