您的位置:首页 > 其它

使用Axis框架对WebService调用进行封装

2017-04-16 00:00 141 查看
以前学习过WebService调用,是通过WSDL文件生成接口,然后在通过接口RPC进行调用,这种方法比较麻烦。于是找到了下面的方法,不需要根据文件来生成,直接给出WSDL文件的地址即可完成服务的调用:

try {
Service service = new Service();
Call call = new Call(service);
call.setTargetEndpointAddress(esbService.getEndPointURL());
call.setSOAPActionURI(esbService.getSOAPActionURI());
InputStream input = new ByteArrayInputStream(reqStr.trim().getBytes(ESBConsts.UTF_8));// 请求的xml文件输入流
SOAPEnvelope request = new SOAPEnvelope(input);
SOAPEnvelope response = call.invoke(request);
Document resultDoc = response.getAsDocument();
} catch (Exception e) {
e.printStackTrace();

}

注:使用前需要引入jar包 axis.jar
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐