axis.jar
commons-discovery.jar
commons-logging.jar
jaxrpc.jar
1. Soap方法定义接口
public interface SoapService {
public String getDatabaseConfiguration();
}
2. 代理执行Soap定义的方法
public class SoapInvokerHandler implements InvocationHandler {
private Call call;
public void initCall() throws ServiceException {
Service service = new Service();
call = (Call) service.createCall();
call.setTimeout(30000);
// call.addHeader(new SOAPHeaderElement("", "ClientType", "Test"));
call.setTargetEndpointAddress(String.format("http://%s/services/Test?wsdl", "127.0.0.1:8080"));
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return call.invoke(method.getName(), args);
}
}
3. 使用
public class SoapInvokerFactory {
public static SoapService getInvoker() throws ServiceException {
SoapInvokerHandler invokerHandler = new SoapInvokerHandler();
invokerHandler.initCall();
SoapService service = (SoapService) Proxy.newProxyInstance(SoapService.class.getClassLoader(), new Class[] { SoapService.class },
invokerHandler);
return service;
}
public static void main(String[] args) throws ServiceException {
System.out.println(SoapInvokerFactory.getInvoker().getDatabaseConfiguration());
}
}
本文介绍如何使用Java实现SOAP Web服务的调用,包括定义服务接口、创建代理执行器并调用远程方法的具体步骤。通过示例代码展示了如何初始化调用对象、设置超时时间和目标地址。
1179

被折叠的 条评论
为什么被折叠?



