.Net SoapClient连接未关闭

时间:2013-08-01 11:03:56

标签: asp.net c#-4.0 soap

我正在尝试访问第三方asmx服务(来自我的ASP.Net MVC 4应用程序)。大多数情况下它工作正常,然后突然我开始看到一个错误:

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 个答案:

答案 0 :(得分:0)

数据库连接中发生错误。确保SqlConnection对象在服务器代码中正确处理(一个好的做法是用using语句包装代码。)