今天遇到一个对接web service的需求,因为之前没有对接过,踩了不少坑,今天我来分享一下本次对接的经验

SOAP 1.1
以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。POST /DCLService.asmx HTTP/1.1
Host: 59.36.172.251
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://xxxx123.org/TestInterface"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><TestInterfacexmlns="http://xxxx123.org/"><MethodName>string</MethodName><XMLData>string</XMLData></TestInterface></soap:Body>
</soap:Envelope>HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><TestResponse xmlns="http://xxxx123.org/"><DCResult>string</DCResult></TestResponse></soap:Body>
</soap:Envelope>

以上是对方接口对接的一个示例

我编写的代码如下:

package com.oxy.demo.webservice;import lombok.extern.slf4j.Slf4j;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.junit.jupiter.api.Test;import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;@Slf4j
public class WebServiceTest {@Testpublic void test() {String url = "http://xx.xx.xxx.xxx:8094/TestService.asmx";// 提供接口的地址String soapaction = "http://xxxx123.org/";// 域名,这是在以上 server定义的String monitorDate = pdfParam();String callMethodName = "TestInterface"; // 这个为需要调用的方法名String methodName = "GetPatientReport"; Service service = new Service();try {Call call = (Call) service.createCall();call.setTargetEndpointAddress(url);call.setOperationName(new QName(soapaction, callMethodName)); // 设置要调用哪个方法call.addParameter(new QName(soapaction, "MethodName"), // 设置要传递的参数org.apache.axis.encoding.XMLType.XSD_STRING, ParameterMode.INOUT);call.addParameter(new QName(soapaction, "XMLData"), // 设置要传递的参数org.apache.axis.encoding.XMLType.XSD_STRING, ParameterMode.INOUT);call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// (标准的类型)call.setSOAPActionURI(soapaction + callMethodName);String res = String.valueOf(call.invoke(new Object[] { methodName ,monitorDate}));// 调用方法并传递参数System.out.println(res);} catch (Exception ex) {ex.printStackTrace();}}private String pdfParam(){String str ="<?xml version=\"1.0\" encoding=\"utf-8\"?><Request><RepID>xxxxxxxxxx</RepID><CustomReportSuffix>英文</CustomReportSuffix></Request>";return str;}}

需要在pom文件中添加的依赖如下:

<!-- https://mvnrepository.com/artifact/org.apache.axis/axis --><dependency><groupId>org.apache.axis</groupId><artifactId>axis</artifactId><version>1.4</version></dependency><!-- https://mvnrepository.com/artifact/axis/axis-jaxrpc --><dependency><groupId>axis</groupId><artifactId>axis-jaxrpc</artifactId><version>1.4</version></dependency><!-- https://mvnrepository.com/artifact/commons-discovery/commons-discovery --><dependency><groupId>commons-discovery</groupId><artifactId>commons-discovery</artifactId><version>0.5</version></dependency><!-- https://mvnrepository.com/artifact/axis/axis-wsdl4j --><dependency><groupId>axis</groupId><artifactId>axis-wsdl4j</artifactId><version>1.5.1</version></dependency>

java 详细教程AXIS调用webservice(直接上代码)相关推荐

  1. java:浅谈axis调用webservice接口

     [申明:此代码已经经过测试可以正确使用:但内容解释为个人见解,如有不准确之处,请指教.              阅读前请先仔细阅读"[]"中的说明文字,以免与您的需求不符而 ...

  2. Java通过axis调用WebService

    转载地址:http://www.linuxidc.com/Linux/2015-06/118460.htm ------------------------------------------分割线- ...

  3. java:AXIS调用webService接口,返回String类型xml,并用dom4j简单解析xml

    一.使用axis调用webService接口,返回String类型xml 1.导入axis依赖 2.直接贴代码 /*** 调用webservice接口的方法,并返回String类型的xml* @par ...

  4. 系统开发系列 之MyEclipse创建WebService详细教程和调用教程(spring框架+maven+CXF框架)

    1 回顾 [系统开发系列 之MyEclipse创建WebService详细教程和调用教程]介绍了使用JWS实现WebService接口的发布和调用,主要涉及的点有: (1)MyEclipse点击Fil ...

  5. axis调用webservice不同参数的方法

    //axis调用webservice不同参数的方法总结 // 调用输入参数是String,返回参数是String的webservice private static boolean doString( ...

  6. 利用axis调用webservice

    比如我们需要调用第三方webservice接口,如这个地址:获得随机数字或字母 http://www.webxml.com.cn/WebServices/RandomFontsWebService.a ...

  7. axis调用webservice客户端开发

    第一步:wsdl2Java.bat文件编写 Axis_Lib表示依赖的jar包路径 Output_Path表示生成的class路径 Package包名 还需要手动更改 -p %Package%表示we ...

  8. Java并发教程–可调用,将来

    从Java的第一个发行版开始,Java的美丽之处之一就是我们可以轻松编写多线程程序并将异步处理引入我们的设计中. Thread类和Runnable接口与Java的内存管理模型结合使用,意味着可以进行简 ...

  9. 利用axis调用webservice接口

    package test;import javax.xml.namespace.QName;import org.apache.axis.client.Call; import org.apache. ...

最新文章

  1. LeetCode: Longest Consecutive Sequence
  2. python网页爬虫-Python网页爬虫
  3. linux下yum安装最新稳定版nginx
  4. LSMW批处理使用方法(11)_步骤14、15
  5. 黑马程序员pink老师前端入门教程,零基础必看的h5(html5)+css3+移动端前端视频教程(权重,盒子模型)
  6. GPIO几种配置的作用
  7. flash 林度_flash动画的视频应用
  8. redux 和 mobX对比
  9. ASP.NET Core远程调试
  10. proxychains-ng 工作原理分析
  11. Effective C++ 读书笔记之Part4.Design and Declarations
  12. sql语句用变量替换表名_使用内存优化表替换SQL临时表和表变量
  13. Socket TCP UDP
  14. 并查集基础 模板题 hdu1232 畅通工程
  15. 现代程序设计 作业1
  16. CPU测评程序、指标、工具
  17. 解决同一办公环境局域网下无法添加打印机的情况
  18. 怎样查自己电脑系统的版本
  19. 加州房价篇 (二) : 处理数据
  20. 在线任务管理服务大汇总

热门文章

  1. Lua进行二进制文件的位操作
  2. 汉字转换为拼音Java工具类
  3. 开学“收心”指南来了
  4. Selenium Chrome设置代理之后验证依旧是本机ip原因
  5. python3.6.国家政策文本分析代码
  6. Unity 计算角度和方向
  7. 随笔——雪雁飞过马赛克群导
  8. 【正点原子MP157连载】第四十三章 外置RTC芯片PCF8563实验-摘自【正点原子】STM32MP1嵌入式Linux驱动开发指南V1.7
  9. hive2.3.2+mysql5.7.21驱动包_2018-08-30期 Hive外部元数据库配置
  10. python TypeError: Descriptors cannot not be created directly错误解决