日期:2014-05-17  浏览次数:21086 次

WCF闲置报错问题,高手请近(急)
用的是WCF做了个服务让一个网站通过这个服务去访问数据等操作,一但闲置久了WCF就报以下的错误,这个怎么解决?


从另一方收到未进行安全处理或安全处理不正确的错误。有关错误代码和详细信息,请参见内部 FaultException.
System.ServiceModel.CommunicationObjectFaultedException: 通信对象 System.ServiceModel.Channels.ServiceChannel 无法用于通信,因为其处于“出错”状态。

Server stack trace:   
  在 System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrNotOpen()
  在 System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)
  在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
  在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
  在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
  在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:   
  在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
  在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
  在 Ris.IWCFDAL.IWCFDictionaryDAL.GetDictionaryList()


我在WCF(服务端)的项目里放了个TIMER,让他定时检查服务的状态,如果一出错就重启,但是服务一直是好的,只是WEB项目(客户端)闲置久了便会出上面这个错误,有人说
一个连接对象使用完就关闭,需要使用时再重新实例化。闲置久了是会报错,但我不知道在WEB端怎么关闭这个连接,我这边好像没有打开什么连接,只是调用WCF里的一些方法,连接要怎么关闭,请告诉我代码怎么写,刚接触WCF不太懂。
还有的说修改配置文件也可以,我不知道我的配置哪有问题,我把openTimeout,receiveTimeout,sendTimeout,inactivityTimeout都设成了10小时,但感觉只要闲置几分钟便会不出,很急,望高手指点,谢谢,真的很急。我把我的配置贴出来你们帮我看看
服务端配置(WCF项目):
wsHttpBinding>
        <binding name="WSHttpBinding_IDisService" closeTimeout="10:01:00" openTimeout="10:10:00" receiveTimeout="10:10:00" sendTimeout="10:10:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
          <security mode="Message">
            <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
            <message clientCredentialType="Windows" negotiateServiceCredential="true"
             algorithmSuite="Default" establishSecurityContext="true" />
          </security>
        </binding>