日期:2014-05-17 浏览次数:20768 次
import javax.xml.namespace.QName;
import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
public class AV {
/**
* @param args
* 航班接口测试
*/
public static void main(String[] args) {
//AV参数
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<ParamsXml><Params>" +
"<AgentID>HBJT</AgentID>" +
"<DepartureAirport>CAN</DepartureAirport>" +
"<ArriveAirport>PEK</ArriveAirport>" +
"<DepartureDate>2014-02-20</DepartureDate>" +
"<CarrierCode>CZ</CarrierCode>" +
"<FS>D</FS>" +
"</Params></ParamsXml>";
System.out.println("输出参数"+xml);
//WebService 调用工具
String url = "http://ws04.itour.cn:8084/ItourAgentCRSService.asmx";
//操作命名控件 和 方法
QName qname = new QName("http://itour.cn/","AV");
//设定参数类型
Object param[] = new Object[] { xml };
try {
//实例化远程服务调用客户端对象
RPCServiceClient client = new RPCServiceClient();
//实例化Options对象
Options options = new Options();
//设置Options对象的连接终端地址
options.setTo(new EndpointReference(url));
//设置Options对象的操作事件对象
options.setAction("http://itour.cn/AV");
//为远程服务调用客户端对象设置Options子对象
client.setOptions(options);
//传递参数,调用服务,获取服务返回结果集
OMElement element = client.invokeBlocking(qname, param);
//获取返回结果集中第一条结果的返回内容
String result=element.getFirstElement().getText();
System.out.println("返回结果"+result);
} catch (AxisFault e) {
e.printStackTrace();
}
}
}
输出参数<?xml version="1.0" encoding="UTF-8"?><ParamsXml><Params><AgentID>HBJT</AgentID><DepartureAirport>CAN</DepartureAirport><ArriveAirport>PEK</ArriveAirport><DepartureDate>2014-02-20</DepartureDate><CarrierCode>CZ</CarrierCode><FS>D</FS></Para