標籤:style blog http color io os 使用 ar java
axis全稱Apache EXtensible Interaction System.版本很多,axis1.x版本最終版是 1.4,之後就到了axis2.x;由於2.x 版本與 1.x版本使用起來的差異比較大(當然2.x版本相對來說會高效很多)。
這裡以訪問QQ號碼狀態為例,webservice地址:http://webservice.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl ,在瀏覽器中訪問可看到相關的要求標頭資訊、函數名稱、參數等。
Java項目中需要用到的Jar包(放在lib目錄下):
需要引用的類:
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
最後是調用代碼:
1 try { 2 3 String endpoint = "http://webservice.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl"; 4 5 //建立一個服務(service)調用(call) 6 Service service = new Service(); 7 Call call = (Call) service.createCall(); 8 9 //設定service所在的url 10 call.setTargetEndpointAddress(new java.net.URL(endpoint)); 11 12 //介面函數13 call.setOperationName(new QName("http://WebXml.com.cn/","qqCheckOnline")); 14 call.setSOAPActionURI("http://WebXml.com.cn/qqCheckOnline");15 16 //介面的參數17 call.addParameter(new QName("http://WebXml.com.cn/","qqCode"), org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);18 19 //設定傳回型別20 call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING); 21 22 String ret = (String)call.invoke(new Object[]{"997717740"}); 23 24 System.out.println("狀態:"+ret);25 26 }27 28 catch(Exception e) {29 BeanCtx.p(e.toString());30 }
Axis1.4 調用 Asp.Net 服務簡單樣本