標籤:type des com remote 介面 public rac str 儲存
溫馨提示:axis2 jar包喲
public static String pubRemoteFuc() {
String endpoint = "http://cnblogs.com/qgc/xxxx/Service?wsdl";
String result = "error";
Service service = new Service();
Call call;
//參數對象
SearchInfoVo d=new SearchInfoVo();
d.setName("李建");
d.setCardNum("44xxxxx");
Object[] object = new Object[1];
object[0] = d;//Object是用來儲存方法的參數
try {
call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);// 遠程調用路徑
QName qn = new QName("http://nciic.com.cn", "check" ); //介面的命名空間,請根據您的實際介面填寫,和方法名稱:<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:nci="http://nciic.com.cn"
call.setOperationName(qn);
//設定參數的類型(這裡是實體物件“SearchInfoVo”)http://cnblogs.com/qgc
call.registerTypeMapping(SearchInfoVo.class,qn,
new BeanSerializerFactory(SearchInfoVo.class, qn),
new BeanDeserializerFactory(SearchInfoVo.class, qn));
call.addParameter("arg0", qn, ParameterMode.IN ); //"arg0"不用改喲,我這裡只有一個參數,並且參數是一個實體物件 http://cnblogs.com/qgc
// // 設定參數名:http://cnblogs.com/qgc
// call.addParameter("name", // 參數名
// XMLType.XSD_STRING,// 參數類型:String
// ParameterMode.IN);// 參數模式:‘IN‘ or ‘OUT‘
/* // 設定參數名:http://cnblogs.com/qgc
call.addParameter("cardNum", // 參數名
XMLType.XSD_STRING,// 參數類型:String
ParameterMode.IN);// 參數模式:‘IN‘ or ‘OUT‘
// 設定參數名:http://cnblogs.com/qgc
call.addParameter("citizenId", // 參數名
XMLType.XSD_STRING,// 參數類型:String
ParameterMode.IN);// 參數模式:‘IN‘ or ‘OUT‘
*/ // 設定傳回值類型:
//call.setReturnType(XMLType.XSD_STRING);// 傳回值類型:String
call.setReturnType(XMLType.XSD_STRING);// 傳回值類型:String
result = (String) call.invoke(object);// 遠程調用
System.out.println(result);
} catch (ServiceException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
return result;
}
public static void main(String[] args) throws Exception {
pubRemoteFuc();//調用
}
java調用(axis2)WebService傳遞物件類型參數(源碼)