Google Code Prettify

2009年6月26日 星期五

Dynamic Web service client

//多個回傳參數用法

String wsdl = "http://localhost:8080/SOA-DO1/PortTypeBndPort?WSDL";

org.apache.axis.client.Service service = new org.apache.axis.client.Service();

Call call = service.createCall();
call.setTargetEndpointAddress(wsdl);
call.setOperationName(new QName("http://schemas.xmlsoap.org/wsdl/soap/","Add"));

//Input
call.addParameter( "machineid",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
call.addParameter( "passcode",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
call.addParameter( "uid",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
call.addParameter( "url",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
call.addParameter( "note",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
call.addParameter( "handle_time",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);

//Output
call.addParameter( "status",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.OUT);
call.addParameter( "message",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.OUT);
call.addParameter( "time",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.OUT);
call.addParameter( "sno",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.OUT);

call.setUseSOAPAction(true);
call.setSOAPActionURI("do1.soa.com/PortType/Add");

String machineid = "sdfs";
String passcode = "sdfsf";
String uid = "C123456789";
String url = "http://www.google.com.tw";
String note = "測試網站-新增測試";
String handle_time = "";


List list = new ArrayList();
list.add(machineid);
list.add(passcode);
list.add(uid);
list.add(url);
list.add(note);
list.add(handle_time);


Object [] inputParams = list.toArray();
List outputParams = new ArrayList();

//取得第一個回傳值
outputParams.add(call.invoke(inputParams));

//取得剩餘的回傳值
outputParams.addAll(call.getOutputValues());

for(int i=0;i<outputParams.size();i++){
      System.out.println(i+"="+outputParams.get(i));
}