webservice 開發總結
環境:服務端是.NET的ASMX,用戶端為JAVA AXIS1.4
方式1:使用call.invoke 直接調用WSDL,缺點:麻煩,不推薦……特别是JAVA調用.NET的WS時,會有不少的問題需要解決。
String endpoint = "http://www.autobao.com/vin/services/VinService?wsdl";
endpoint = "http://203.156.207.216:81/webService/PJCSService.asmx?WSDL";
Service service =
new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
String namespace = "http://tempuri.org/";
call.setSOAPActionURI("http://tempuri.org/GetCXInfoByVIN");
call.setReturnType(XMLType.XSD_STRING);
// call.setOperationStyle("wrapped");
// call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS,Boolean.FALSE);
call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR,
Boolean.FALSE);
call.setEncodingStyle(null);
QName q = new QName(namespace,"GetCXInfoByVIN");
call.setOperationName(q);// LSJW26H35BS047598
call.addParameter(new QName(namespace,"vin"),
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
// call.setReturnClass(org.w3c.dom.Element.class);
Object obj = call.invoke(new Object[] {"LSJW26H35BS147598" });// LSJW26H35BS147598
方式2:生成測試STUB……此種方法更快捷。如果用.NET開發WS用戶端,就是用的這種方式……
Myeclipse>run as >open run diaglog >運作org.apache.axis.wsdl.WSDL2Java ,參數
-o %Output_Path% -t -p packagex
注:-t, --testCase…… ,不加-O參數,預設輸出到項目目錄下。
然後: 貼代碼
com.xxxxx.ws.client.PJCSServiceSoap_BindingStubbinding;
binding =(com.xxxxx.ws.client.PJCSServiceSoap_BindingStub)
newcom.xxxxx.ws.client.PJCSServiceLocator().getPJCSServiceSoap();
// Time out after a minute
binding.setTimeout(10000);
// Test operation
java.lang.String[]value =
null;
value = binding.getCXInfoByVIN("WBABU31098LH65425");
***********開發WEB SERVICE相關工具
WEB SERVICE測試工具Storm……。
Storm是一款用于測試Web服務的免費并且開源的工具。是用F#編寫…………可以調用WEVSEERVICE,輸入參數,并可以看到發出的XML和傳回的XML..