首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

WCF闲置报错有关问题,高手请近(急)

2013-03-06 
WCF闲置报错问题,高手请近(急)用的是WCF做了个服务让一个网站通过这个服务去访问数据等操作,一但闲置久了W

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>
      </wsHttpBinding>

客户端配置(WEB项目):
<basicHttpBinding>
    <binding name="BasicHttpBinding_IQueueCall" closeTimeout="10:01:00"


     openTimeout="10:01:00" receiveTimeout="10:10:00" sendTimeout="10:10:00"
     allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
     maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
     messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
     useDefaultWebProxy="true">
     <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
      maxBytesPerRead="4096" maxNameTableCharCount="16384" />
     <security mode="Message">
      <transport clientCredentialType="None" proxyCredentialType="None"
       realm="" />
      <message clientCredentialType="UserName" algorithmSuite="Default" />
     </security>
    </binding>
   </basicHttpBinding>
   <wsHttpBinding>
    <binding name="WSHttpBinding_ISystemMgrDAL" 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="2147483647"
      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>
   </wsHttpBinding>

wsHttpBinding,basicHttpBinding这个配置我都加了,我不知道读的到底是哪个,因为我网上看有些说用basicHttpBinding,我就干脆二个都加了。

高手帮帮忙,真的很急
[解决办法]
客户端使用连接对象后销毁
using(WCFClient client=new WCFClient){}
再个服务器端
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession]
[解决办法]
先部署WCF服务,保证已经启动Host。
通道已经出错了,需要重新建立一次连接。然后调用
[解决办法]
就是你客户端创建的连接对象 我是举个列子 名称肯能不一样的
[解决办法]
关于静态对象,看看下面的描述是否对你有帮助。
=================================
前段时间在学习用IIS的时候发现了下面的现象以及解决方法
前段时间学习IIS的时候用ASP.net做了个小网站,里面使用了单件模式,下面是单件模式的实现代码,发现隔一段时间(大概20分钟)使用ServerInstance对象时, serverInstance为空,百思不得其解,后面经过试验发现是在IIS配置上出现问题了。



        static private PCServer serverInstance = null;
        static public PCServer ServerInstance
        {
            get
            {
                if (serverInstance == null)
                {
                      serverInstance = new PCServer();
                }

                return serverInstance;
            }
        }
下面是解决方法,打开IIS(信息管理器)选择应用程序池,右键属性,打开属性窗口,进入性能页,你会发现空闲超时设置的是20分钟,这就是原因所在。设定了这个时间应用程序池会每隔20分钟回收一次,所以会造成serverInstance为空,经过试验大家也要多注意应用程序池属性页里面的其他配置,对程序的回收都关系密切。希望对大家有所帮助。

热点排行