Java使用axis2呼叫wsdl形式的webservice
阿新 • • 發佈:2019-02-10
依賴架包:
axis.jar、jaxrpc.jar、commons-logging-1.0.4.jar、commons-discovery-0.2.jar、wsdl4j-1.5.1.jar
相關程式碼:
public final class OutboundQueueSystem {
/**
*
* @param endpoint 介面呼叫路徑
* @param operationName 呼叫的介面方法名
* @param input 前臺請求引數集
* @return
*/
@SuppressWarnings("rawtypes" )
public static String outbound(String endpoint,String operationName,Map<String,Object> input){
String result = "";
Service service = new Service();
Call call;
Object[] object = new Object[input.size()];
try {
call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);// 遠端呼叫路徑
call.setOperationName(operationName);// 呼叫的方法名
Set<Entry<String, Object>> set = input.entrySet();
int i = 0;
for (Entry entry : set) {
object[i] = entry.getValue().toString();i++;
call.addParameter(entry.getKey().toString(),//引數名
XMLType.XSD_STRING,// 引數型別: String
ParameterMode.IN);// 引數模式:'IN' or 'OUT'
}
call.setReturnType(XMLType.XSD_STRING);// 返回值型別:String
result = (String) call.invoke(object);// 遠端呼叫
} catch (ServiceException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
return result;
}
}