java客户端调用webService

时间:2023-03-08 22:21:50
java客户端调用webService

啥也不想说,以前使用的方法突然不行了。各种网搜(记得别忘记到jar包哦:axis.jar)

看代码,第一种方式,也就是以前的方式:

改方式不用表名参数名称

 public static String invokeStrTypeInMethod(String wsdl, String dataStr,String methodName) throws ServiceException, RemoteException{
Service service = new Service();
Call call = null;
String result = null; call = (Call) service.createCall();
// call.setOption("soap.wsdl_cache_enabled", "0");
call.setTargetEndpointAddress(wsdl);
call.setOperationName(methodName);//WSDL里面描述的接口名称
call.addParameter("in", org.apache.axis.encoding.XMLType.XSD_DATE,
javax.xml.rpc.ParameterMode.IN);//接口的参数
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置返回类型
result = (String)call.invoke(new Object[]{dataStr});
return result;
}

目前遇见的情况是:part scanPay was not recognized(Does it exist in service WSDL?)

网搜过后,换了一种方式访问:

 public static String invokeHuanXunPayMethod(String huanXunEndpoint, String datas, String methodName,String methodParameterName) throws ServiceException, RemoteException {
Service service = new Service();
Call call = null;
String result = null; call = (Call) service.createCall();
call.setTargetEndpointAddress(huanXunEndpoint);
call.setOperationName(new QName(访问wsdl地址后的targetNamespace, methodName));
// call.setOperationName("insertProdutc");//WSDL里面描述的接口名称
call.addParameter(methodParameterName, org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);//接口的参数
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置返回类型
// String result = WebServicesUtils.invokeStrTypeInMethod(endpoint, dataStr, "insertProdutc");
// System.out.println(dataStr);
result = (String)call.invoke(new Object[]{datas});
return result;
}

这种方式是要指定明确的域名,以及方法参数名称,好了;欢迎各位丢板砖提意见,谢谢!!