java webservice 開發總結

來源:互聯網
上載者:User

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 
http://203.156.207.216:81/webService/PJCSService.asmx?WSDL

 

註:-t, --testCase…… ,不加-O參數,預設輸出到項目目錄下。

 

 

然後:  貼代碼

com.xxxxx.ws.client.PJCSServiceSoap_BindingStubbinding;

            

                binding =(com.xxxxx.ws.client.PJCSServiceSoap_BindingStub)

                             
new
com.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..

 

抓包工具smsniff.exe

可以抓取發出的SO CKET包。除了可以看到發出的XML,更可以看到全面的SOCKET資訊。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.