java: axis2 客户端调用三种方法

方法一:
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new EndpointReference(
                "http://localhost:8080/axis2/services/AddressBookService");
options.setTo(targetEPR);
QName opAddEntry = new QName("http://service.addressbook.sample", "addEntry");

Object[] opAddEntryArgs = new Object[] { entry };
serviceClient.invokeRobust(opAddEntry, opAddEntryArgs);

方法二:
 public static OMElement getEchoOMElement() {
        OMFactory fac = OMAbstractFactory.getOMFactory();
        OMNamespace omNs = fac.createOMNamespace(
                "http://example1.org/example1", "example1");
        OMElement method = fac.createOMElement("echo", omNs);
        OMElement value = fac.createOMElement("Text", omNs);
        value.addChild(fac.createOMText(value, "Axis2 Echo String "));
        method.addChild(value);

        return method;
    }

 public static void main(String[] args) {
        try {
           OMElement payload = ClientUtil.getEchoOMElement();
            Options options = new Options();
           
            options.setTo(targetEPR);
            options.setAction("urn:echo");

            //Blocking invocation
            ServiceClient sender = new ServiceClient();
            sender.setOptions(options);
            OMElement result = sender.sendReceive(payload);

            System.out.println(result);
           
            System.out.println(options.getTo());

        } catch (AxisFault axisFault) {
            axisFault.printStackTrace();
        }
    }

方法三:
利用插件生成客户端
private static String URL="http://localhost:8080/axis2/services/WeatherService";
 
    public static void main(String[] args) throws RemoteException {
        try {
            WeatherServiceStub stub;
            if (args != null && args.length != 0) {
                stub = new WeatherServiceStub(args[0]);
               
            } else {
                stub = new WeatherServiceStub(URL);
            }
            WeatherServiceStub.SetWeather setWether = new WeatherServiceStub.SetWeather();
            WeatherServiceStub.Weather wether = new WeatherServiceStub.Weather();
           
            wether.setForecast("east");
            wether.setRain(true);
            wether.setTemperature(12.3f);
            wether.setForecast("big");
           
            setWether.setWeather(wether);
            stub.setWeather(setWether);
           
            WeatherServiceStub.GetWeatherResponse gw = new WeatherServiceStub.GetWeatherResponse();
            System.out.println(gw.get_return());        
           
        } catch (AxisFault e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

你可能感兴趣的:(java)