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