【webservice】818開發webservice過程中遇到的異常

來源:互聯網
上載者:User

標籤:webservice   axis   

還是關於axis2的知識哦。webservice的開發,包括服務端的開發、用戶端的開發。在“服務端的開發”方面通常是部署好axis2的環境、完成工程的設計與編程、打包發布,一般來說不會出現異常(前提是基本功紮實),然而,在“用戶端的開發”方面就不好說了。下面就簡單說一下用戶端開發可能會出現的問題吧。

1、產生用戶端代碼時報錯。例如用axis2的產生工具去搞axis1的wsdl(這個可以參考前面的博文哦),報錯資訊是org.apache.axis2.wsdl.codegen.CodeGenerationException  : java.lang.RuntimeException: java.lang.reflect.InvocationTargetException。網上的說法一致是wsdl有問題,說法是正確的,但不夠詳細。後來webservice服務端廠家提示要用axis1的產生工具,這才解決了問題。貌似沒看到其他朋友有這樣的遭遇呢,犯錯就是學習,呵呵。

2、axis2產生CXF的webservice的wsdl。有一次遇到一個wsdl,和平時看的axis2的wsdl有點不一樣,而最後還是可以順利產生用戶端代碼,也就是stub類。但是,拿到了這個stub類,卻不能和平常一樣寫用戶端代碼(平常的做法是,new一個stub類對象,直接調用其子類、子方法就完事了)。後來有群友幫忙,才知道這是csf產生的wsdl,熱心的群友還幫我產生了cxf的用戶端代碼。可是我用axis2的啊,但是還是非常感謝他。再後來,我問廠家拿了報文,根據報文的xml(是soap協議的)一步一步調用才解決了問題。說多了都是淚,直接上代碼:

//set值過程  --- 注意參考報文ISPPNPIServiceStub sub = new ISPPNPIServiceStub();ISPPNPIServiceStub.Root rootSend = new ISPPNPIServiceStub.Root();ISPPNPIServiceStub.Msg_head rMsg_head = new ISPPNPIServiceStub.Msg_head();ISPPNPIServiceStub.Interface_msg rInterfaceMsg = new ISPPNPIServiceStub.Interface_msg();ISPPNPIServiceStub.Directive rDirective = new ISPPNPIServiceStub.Directive();ISPPNPIServiceStub.ServiceClass rServiceClass = new ISPPNPIServiceStub.ServiceClass();ISPPNPIServiceStub.ServiceSubClass rServiceSubClass = new ISPPNPIServiceStub.ServiceSubClass();ISPPNPIServiceStub.Method rMethod = new ISPPNPIServiceStub.Method();rMsg_head.setTime("String");rMsg_head.setFrom("String");rMsg_head.setTo("String");rMsg_head.setMsg_type("String");rMsg_head.setSerial(ipString);rMethod.setName("IssuePpcCard");//對於報文:<Method Name="IssuePpcCard"> rMethod.setMDN(number);rMethod.setPWD(pwd);rServiceSubClass.setName("CSPpcMemberService");rServiceSubClass.setName("CSService");rServiceSubClass.setMethod(rMethod);rServiceClass.setServiceSubClass(rServiceSubClass);rDirective.setServiceClass(rServiceClass);rInterfaceMsg.setDirective(rDirective);rootSend.setInterface_msg(rInterfaceMsg);rootSend.setMsg_head(rMsg_head);ISPPNPIServiceStub.Root rootRS = sub.SYNNPIAPI(rootSend, null, null, null, null);ISPPNPIServiceStub.ResponseSubClass responseSubClass = new ISPPNPIServiceStub.ResponseSubClass();responseSubClass = rootRS.getInterface_msg().getMsg_response().getResponseClass().getResponseSubClass();String returnData = JSONObject.fromObject(responseSubClass).toString();

3、查詢逾時。這個異常就是connect timeout了,因為服務端資料量太大,查詢速度慢,返回資料也比較多,整個調用過程超出了預設的時間,解決辦法是在產生的stub類的建構函式(有多個哦,別弄錯了哦)裡面添加這行: _serviceClient.getOptions().setTimeOutInMilliSeconds(600000L);//10 mins timeout。這樣一來,stub類執行個體化的時候會重設連線時間。

4、出現常見的 nullPointException、sqlException等等,那估計就是自己的代碼有問題了。

總而言之:服務端開發一般不出錯;用戶端開發時,先問廠家拿wsdl和url,調不通就問廠家拿報文就是了,如果拿了報文後還是怎麼弄也弄不好?最後一招:放棄axis,直接寫servlet(也就是要弄javaweb系統了)!

老鳥勿噴哦~ 轉載請說明出自whilejolly:http://blog.csdn.net/seedingly/article/details/39052189

【webservice】818開發webservice過程中遇到的異常

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.