作者: | 来源:互联网 | 2023-12-12 12:43
本文介绍了如何使用Axis、XFire、CXF等工具来实现webservice客户端的调用,以及提供了使用Java代码进行调用的示例。示例代码中设置了服务接口类、地址,并调用了sayHello方法。
Axis客户端调用 webservice:
Java代码
- URL endpointURL = new URL("http://localhost:8080/webservice/HelloService");
- String requestText = "javalinjx"
- Service service = new Service();
- Call call = (Call) service.createCall();
- call.setTargetEndpointAddress(endpointURL);
- call.setOperationName("sayHello");
- call.addParameter("xml", XMLType.XSD_STRING, ParameterMode.IN);
- call.setReturnClass(String.class);
- call.setReturnType(XMLType.XSD_STRING);
- Object [] obj = new Object[]{ requestText };
- String result = (String) call.invoke(obj);
XFire客户端调用 :
Java代码
- public void call() throws Exception {
- Service service = new ObjectServiceFactory().create(HelloService.class);
- XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());
- String url = "http://localhost:8080/webservice/HelloService";
- SmsService it = (SmsService)factory.create(service, url);
- int b = it.sayHello("javalinjx");
- }
CXF客户端调用:
JaxWsProxyFactoryBean factory1 = new JaxWsProxyFactoryBean();
Java代码
- factory1.setServiceClass(UaAuthInterfaces.class);
- factory1.setAddress("http://localhost:8080/webservices/HelloService");
- UaAuthInterfaces u = (UaAuthInterfaces) factory1.create();
- u.sayHello("javalinjx");