标签:import call() 参数 return load ips oid param catch
1. 首先需要下载Axis1.4 jar包,这个必应搜索大把,下载下来后把jar包加入eclipse工程项目路径中即可.
2. 下载mail.jar和activation.jar 俩个包。下载地址:https://www.eclipse.org/webtools/wst/components/ws/download_instructions_for_jars.html
该网址中含有所有 java webServices 所需要的jar包。如果确实这俩个包,运行时会有:Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart) 异常.
以下为可以跑的通的代码,需要修改相应的账户密码,路径,方法名,方法参数(在Xmlbody中修改),下载好相应的jar包.
package frcProject; import javax.xml.rpc.ParameterMode; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.encoding.XMLType; /** * * WebService调用 通过AXIS1.4调用远程的web service * * * * * @author lb * * */ public class testWebService { public static void main(String[] args) { String endpoint = "http://s4dapp.eva-holdings.com:8000/sap/bc/srt/wsdl/flv_10002A101AD1/bndg_url/sap/bc/srt/rfc/sap/zcs_ws001/200/zcs_ws001/zcs_ws001";// 远程请求访问wsdl文件 String xmlBody = "<?xml version=\"1.0\" encoding=\"GBK\"?><request>" + "<num1>5</num1>" + "<num2>5</num2>" + "</request>";// 请求参数 String returnData = ""; try { Service service = new Service(); Call call = (Call) service.createCall(); call.setProperty(org.apache.axis.client.Call.USERNAME_PROPERTY, "account"); // 账号 call.setProperty(org.apache.axis.client.Call.PASSWORD_PROPERTY, "password");// 密码 call.setTargetEndpointAddress(endpoint);// 远程调用路径 call.setOperationName("remoteMethodName");// 调用的方法名 // 设置参数名: 参数名,参数类型,参数模式
call.addParameter("xmlBody", XMLType.XSD_STRING, ParameterMode.IN); call.setReturnType(XMLType.XSD_STRING);// 设置被调用方法的返回值类型 try { returnData = (String) call.invoke(new Object[] { xmlBody });// 远程调用 } catch (Exception e) { System.out.println(e); } System.out.println("result is " + returnData); } catch (Exception e) { System.err.println(e.toString()); } } }
java webservices 以Axis1.4方式 调用sap webservice接口.
标签:import call() 参数 return load ips oid param catch
原文地址:https://www.cnblogs.com/libo2019/p/10556064.html