代码之家  ›  专栏  ›  技术社区  ›  MGSoto

为什么我的WCF频道失败了?

  •  3
  • MGSoto  · 技术社区  · 16 年前

    我有一台计算机,它运行一个程序,在另外4台计算机上管理多达48个单独的进程。我已将WCF服务(每个进程一个)设置为:

        public void StartService(Uri uri, string identifier)
        {
            unitMetaData = identifier;
            var binding = new WSDualHttpBinding(WSDualHttpSecurityMode.None);
            binding.ReliableSession.InactivityTimeout = TimeSpan.FromDays(20);
            var reader = binding.ReaderQuotas as XmlDictionaryReaderQuotas;
            reader.MaxStringContentLength = WCFContentSize; // 16777216
            service = new ServiceHost(this, uri);
            service.Faulted += TestService_Faulted;
            service.AddServiceEndpoint(
                typeof(IController),
                binding,
                identifier);
            service.Open();
        }
    

    以下是远程进程的代码:

        public void Connect()
        {
            // External binding used to change the WCF XML text content size
            var binding = new WSDualHttpBinding(WSDualHttpSecurityMode.None);
            binding.ReliableSession.InactivityTimeout = TimeSpan.FromDays(20);
            var reader = binding.ReaderQuotas as XmlDictionaryReaderQuotas;
            reader.MaxStringContentLength = WCFContentSize; // 16777216
            DuplexChannelFactory<IController> factory = new DuplexChannelFactory<IController>(new InstanceContext(this), binding);
            controllerChannel = factory.CreateChannel(new EndpointAddress(controllerAddress, new DnsEndpointIdentity(controllerAddress.DnsSafeHost), new System.ServiceModel.Channels.AddressHeaderCollection()));
            ((IClientChannel)controllerChannel).OperationTimeout = TimeSpan.FromSeconds(ChannelOperationTimeoutInSeconds); // 300
            controllerChannel.RequestTestData();
        }
    

    An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
    System.ServiceModel.CommunicationObjectFaultedException: The communication object, System.ServiceModel.Channels.ServerReliableDuplexSessionChannel, cannot be used for communication because it is in the Faulted state.
    
    Server stack trace: 
       at System.ServiceModel.Channels.TransmissionStrategy.WaitQueueAdder.Wait(TimeSpan timeout)
       at System.ServiceModel.Channels.TransmissionStrategy.InternalAdd(Message message, Boolean isLast, TimeSpan timeout, Object state, MessageAttemptInfo& attemptInfo)
       at System.ServiceModel.Channels.ReliableOutputConnection.InternalAddMessage(Message message, TimeSpan timeout, Object state, Boolean isLast)
       at System.ServiceModel.Channels.ReliableDuplexSessionChannel.OnSend(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.DuplexChannel.Send(Message message, TimeSpan timeout)
       at System.ServiceModel.Dispatcher.DuplexChannelBinder.Request(Message message, TimeSpan timeout)
       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 SEL.MfgTestDev.ESS.ServiceContracts.ITestProcessClient.Ping()
       at SEL.MfgTestDev.ESS.Testing.Service.TestService.Ping() in C:\Projects\Mfg_TestDev_ESS_Rev3\branches\MSU-5-18-2010\ESS.Testing.Service\TestService.cs:line 349
    

    怎么回事?为什么它突然变成了故障状态。有什么方法可以让我知道连接出现故障的原因吗?

    3 回复  |  直到 16 年前
        1
  •  9
  •   Ladislav Mrnka    16 年前

    对于生产环境不是一个好主意,但您可以尝试打开 WCF tracing

    顺便说一句,您的可靠会话有问题,因为它在10分钟不活动后超时。您为可靠会话设置了非活动超时,但绑定上也有接收超时,默认为10分钟。如果10分钟内没有消息到达,应用程序会话关闭=服务实例被销毁,可靠会话也关闭。

        2
  •  2
  •   Stefan Egli    16 年前

    如果不将服务异常包装到中,则通道可能处于故障状态 FaultException 或 FaultException<T> :

    http://blogs.msdn.com/b/pedram/archive/2008/01/25/wcf-error-handling-and-some-best-practices.aspx

        3
  •  0
  •   theburningmonk    16 年前

    另外,在ServiceBehaviors的配置中,“includeExceptionDetailInFaults”是否设置为true?例如

    <behaviors>
       <behavior name="MyServiceBehaviors">
          <serviceDebug includeExceptionDetailInFaults="true" />
       </behavior>
    </behaviors>
    

    在调试期间,这很有用,因为它允许您查看来自服务器的异常消息,但缺点是如果您的通道也出现故障,那么在生产环境中最好将其关闭。