1. 程式人生 > >WebService報org.apache.cxf.interceptor.Fault: Could not send Message 錯誤

WebService報org.apache.cxf.interceptor.Fault: Could not send Message 錯誤

問題描述

在專案中程式設計發現,原來WebService能夠正常返回結果,但是後續改變查詢條件,導致服務端檢索時間過長,客戶端丟擲:org.apache.cxf.interceptor.Fault: Could not send Message 錯誤。

解決方案

在客戶端延長超時時間,程式碼如下:

        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
        factory.setServiceClass(IEvalService.class);//註冊WebService介面
        factory.setAddress
(CoreConst.PATENT_URL);//設定WebService地址 factory.getOutInterceptors().add(new ClientLoginInterceptor(CoreConst.PARENT_USERNAME,CoreConst.PARENT_PASSWORD)); IEvalService client = (IEvalService)factory.create();//客戶端物件 //設定客戶端的配置資訊,超時等. Client proxy = ClientProxy.getClient
(client); HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(30000); //連線超時時間 policy.setReceiveTimeout(180000);//請求超時時間. conduit.setClient(policy); ResultData info = client.loadDataFromSearch
(pa,ipc, api_key, sign);//呼叫服務

如上,設定請求超時時間為3分鐘,能正常返回結果了。