【问题标题】:"The request channel timed out while waiting for a reply" in WCF serviceWCF 服务中的“请求通道在等待回复时超时”
【发布时间】:2011-01-04 13:57:17
【问题描述】:

我正在运行由 Windows 服务托管的 WCF 服务(从 asp.net 站点调用)。

当我通过“BasicHttp”端点调用时超时(因为已超出 sendTimeout 属性),我会收到预期的错误消息:

“请求通道在 00:01:00 后等待回复时超时。....”

但是当通过 NetTcp 端点(具有传输安全性)调用时,我得到更一般的错误:

“通信对象 System.ServiceModel.Channels.ServiceChannel 不能用于通信,因为它处于故障状态。”

有人知道这是为什么吗?我在配置中遗漏了什么吗?

我的客户端配置是:

    <netTcpBinding>
            <binding name="netTcpBindingConfig" closeTimeout="00:01:00"
             openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:00:10"
             transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
             hostNameComparisonMode="StrongWildcard" listenBacklog="10"
             maxBufferPoolSize="524288" maxBufferSize="655360" maxConnections="10"
             maxReceivedMessageSize="65536000">
                <readerQuotas maxDepth="32" maxStringContentLength="65536000" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="false" />
                <security mode="Transport">
                    <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                    <message clientCredentialType="Windows"  />
                </security>
            </binding>
        </netTcpBinding>


        <basicHttpBinding>

            <binding name="basicHttpBindingConfig" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:00:00.500"
                bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536000"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="65536000" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            </binding>

        </basicHttpBinding>

服务配置:

    <basicHttpBinding>
      <binding name="basicHttpBinding_config" maxReceivedMessageSize="5000000">
        <readerQuotas maxDepth="9000000" maxStringContentLength="9000000"
        maxArrayLength="9000000" maxBytesPerRead="9000000" maxNameTableCharCount="9000000" />
      </binding>
    </basicHttpBinding>

    <netTcpBinding>
      <binding name="tcpBinding_config" maxReceivedMessageSize="5000000" maxBufferSize="5000000" maxBufferPoolSize="5000000" >
        <readerQuotas maxDepth="9000000" maxStringContentLength="9000000"
          maxArrayLength="9000000" maxBytesPerRead="9000000" maxNameTableCharCount="9000000" />
      </binding>
    </netTcpBinding>

非常感谢任何帮助! 谢谢!

乔恩

【问题讨论】:

    标签: wcf wcf-binding


    【解决方案1】:

    超时异常导致您的代理进入故障状态。

    BasicHttpBinding 没有出现此异常的原因是此绑定不使用会话。如果使用会话的绑定出现异常,则通道将出现故障并且会话将被销毁。

    这往往会隐藏问题的真正原因。调查原始异常的一种方法是使用 WCF 跟踪。

    WCF 可以配置为跨应用程序的所有组件输出进程里程碑的跟踪,例如操作调用、代码异常、警告和其他重要的处理事件。

    以下是启用跟踪的.config 示例。

    <configuration>
      <system.diagnostics>
        <sources>
          <source name="System.ServiceModel" switchValue="Warning" propagateActivity="true" >
            <listeners>
              <add name="xml"/>
            </listeners>
          </source>
    
          <source name="myUserTraceSource" switchValue="Warning, ActivityTracing">
            <listeners>
              <add name="xml"/>
            </listeners>
          </source>
        </sources>
    
        <sharedListeners>
          <add name="xml" 
               type="System.Diagnostics.XmlWriterTraceListener" 
               initializeData="C:\logs\TraceLog.svclog" />
        </sharedListeners>
    
      </system.diagnostics>
    </configuration>
    

    确保initializeData 中定义的路径可由您的服务写入。您可以从MSDN: Configuring Tracing 阅读有关 WCF 跟踪的更多信息。

    Microsoft 提供了一个Service Trace Viewer Tool 来读取 .svclog 文件。

    【讨论】:

    • 感谢您的快速回复,丹尼尔!这不是我一直在寻找的解决方案,因此我将进一步阐述我的问题:在我的客户端应用程序(ASP.NET 站点)中,当与 WCF 服务的通信失败时,我发现了错误。当我(在调试期间)引发 Timeout 场景时,我在运行 BasicHttp 绑定时收到 TimeoutException,但是当切换到 NetTcp 绑定(保持其他所有内容不变)时,它会引发“Faultet State”异常。所以,我知道是什么导致了错误(即超时),那么为什么 NetTcp 绑定不报告呢?乔恩
    • BasicHttpBinding 没有出现此异常的原因是此绑定不使用会话。如果使用会话的绑定出现异常,则通道将出现故障,会话将被销毁。
    • 好的,回顾一下;使用 NetTcp 绑定时,我无法从通道中捕获超时异常?我在端点/服务配置中是否无法禁用 NetTcp 绑定中的会话? (我不需要会话,所以这对我来说可能是一个有效的选择)。
    • 我不确定您是否可以配置 NetTcpBinding 来传递原始异常。一般来说,故障通道会得到相应的识别和处理:通常是中止并重新创建。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多