2013-08-01 77 views
0

我試圖訪問第三方asmx服務(從我的ASP.Net MVC 4應用程序)。大多它工作正常,然後突然我開始看到一個錯誤:.Net SoapClient連接未關閉

The connection was not closed. The connection's current state is open. 

這個問題消失了一段時間,一切工作正常。然後它再次出現。

我懷疑代理或網絡設置,但更改這些設置沒有幫助。我能夠'沒有問題地更新服務參考',這意味着我可以正確訪問服務。

這個錯誤是否有可能在服務端產生,並冒泡到我的應用程序?

我可以確定問題是在客戶端還是我的?

感謝

詳情:

[System.ServiceModel.FaultException]: {"Server was unable to process request. ---> The connection was not closed. The connection's current state is open."} 

Server stack trace: 
    at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) 
    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) 
    at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) 
    at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) 

Exception rethrown at [0]: 
    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) 
    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 
    at MyTDI.ClientWebServices.TDIWS_SalesManagement.WS_SalesManagementModuleSoap.GetAgentCommissions(String Agency_RegNo, DateTime StartDate, DateTime EndDate, Int32 PageNo) 
    at MyTDI.ClientWebServices.TDIWS_SalesManagement.WS_SalesManagementModuleSoapClient.GetAgentCommissions(String Agency_RegNo, DateTime StartDate, DateTime EndDate, Int32 PageNo) in d:\Projects\TPLTDI\MyTDIPortal\MyTDI.ClientWebServices\Service References\TDIWS_SalesManagement\Reference.cs:line 111 
    at MyTDI.ClientWebServices.Sales.SalesManagementWebService.ListAgentCommissions(String agentId, DateTime startDate, DateTime endDate, Int32 pageNo) in d:\Projects\TPLTDI\MyTDIPortal\MyTDI.ClientWebServices\Sales\SalesManagementWebService.cs:line 31 

代碼

  DataSet ds = null; 
     using(WS_SalesManagementModuleSoapClient client = new WS_SalesManagementModuleSoapClient()) 
     { 
      try 
      { 
       ds = client.GetAgentCommissions(agentId , startDate , endDate , pageNo); 
      } 
      catch(Exception ex) 
      { 
       logger.Error(ex , ""); 
       throw new Exception("Unable to obtain commissions data from server."); 
      } 
     } 
+1

數據庫連接發生錯誤。確保'SqlConnection'對象正確地放置在你的服務器代碼中(''using'語句)。 –

+0

所以你的意思是我應該要求網絡服務所有者檢查他們的代碼? –

+0

絕對是這樣做的。 –

回答

0

在數據庫連接中出現的錯誤。確保SqlConnection對象正確地放置在您的服務器代碼中(最好的做法是用using語句包裝您的代碼)。