# doc **Repository Path**: yxk123/doc ## Basic Information - **Project Name**: doc - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-08-21 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SAP WebService接口调用 WebService 方式跨平台通用性高,可以同时发布和调用一个服务,可以调用内部服务和外部服务。缺点是调用对方服务需要生成本地客户端代码,数据传输采用soap协议,调用调试有一定的不便。 ## 1.调用一个WebService ### 1.pom.xml文件中加入webservice调用相关jar包 ```pom org.apache.cxf cxf-spring-boot-starter-jaxws 3.2.5 ``` ### 2.在cxf官网下载相关jar包 cxf官网 http://cxf.apache.org/download.html 下载地址 http://www.apache.org/dyn/closer.lua/cxf/3.2.6/apache-cxf-3.2.6.zip 1. 将下载后的文件解压到一定的目录,用于后续配置系统环境变量。 2. 配置cxf环境变量 新建 CXF_HOME D:\Program Files (x86)\apache-cxf-3.2.6 在PATH中添加 %CXF_HOME%\bin ### 3.在soapui官网下载soapui 官网地址 https://www.soapui.org/ ![Image text](img/20180820151644 (1).png) 1. 使用wsdl地址建立项目 选择File,点击new soapUI project 2. 使用soapui生成javacode 选中项目下节点,右键Generate Code,选择Apache CXF 3. 注意配置生成参数 点击 【Custom Args】标签,在 【Tool Args】 中填入参数: -encoding utf-8 -wsdlLocation classpath:wsdl/xxx.wsdl ps: -encoding 解决生成的代码中中文乱码问题,和工作空间编码格式同步。 ps: -wsdlLocation为开发项目中wsdl的读取地址。 4. 将wsdl文件和生成的Java代码copy到项目相应的目录。 ### 4.在项目中开发使用webService 1. 在yml中设置相应的请求参数 ``` yml sap: wsUserName: xiadongliang wsPwd: 654321 wsReqUrl: zlmara: http://it-sapdevelop.chinacloudapp.cn:8000/sap/bc/srt/rfc/sap/zlmara_upd/200/zlmara_upd/zlmara_upd ``` ps: 请求地址为wsdl文件中 " + result + ";调用返回信息--->" + message); SN_ITEM.clear(); ``` 2. 查询操作 ``` demo JSONObject json=new JSONObject(); JCoDestination destination = SAPConn.connect(); JCoFunction function; function = destination.getRepository().getFunction("ZFML_MARA_GET"); JCoParameterList input = function.getImportParameterList(); input.setValue("IV_MATNR", iv_mantr); function.execute(destination); JCoParameterList paraList = function.getExportParameterList(); String result = paraList.getString("EV_ERROR");// 调用接口返回状态 String message = paraList.getString("EV_MSG");// 调用接口返回信息 JCoStructure exportStructure = function.getExportParameterList().getStructure("ES_MARA"); for (int i = 0; i < exportStructure.getMetaData().getFieldCount(); i++) { log.info(exportStructure.getMetaData().getName(i) + ":\t" + exportStructure.getString(i)); } for (JCoField field : exportStructure) { json.put(field.getName(),field.getString()); } ```