【问题标题】:Change WCF default timeout更改 WCF 默认超时
【发布时间】:2011-01-15 06:24:04
【问题描述】:

我这里有一个 WCF 双工服务,要求是回调到客户端应该有 10 秒的超时,因此我的服务的 web.config 文件如下所示:

        <bindings>
        <basicHttpBinding>
            <binding name="simulatorEndpoint" closeTimeout="00:00:10" openTimeout="00:00:10" 
                receiveTimeout="00:00:10" sendTimeout="00:00:10" 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="None">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
        <wsDualHttpBinding>
            <binding name="wsdualEndpoint" closeTimeout="00:00:10" openTimeout="00:00:10"
                receiveTimeout="00:00:10" sendTimeout="00:00:10" bypassProxyOnLocal="false"
                transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536" clientBaseAddress="http://localhost:1235"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:00:10"  />
                <security mode="Message">
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        algorithmSuite="Default" />
                </security>
            </binding>
        </wsDualHttpBinding>
    </bindings>

在客户端,app.config 文件中的绑定具有相同的超时值。

现在的效果是,如果客户端向服务器发送请求,则超时为 10 秒。但另一方面,如果服务向客户端发送回调,则超时为 1 分钟。这很奇怪...显然超时设置在客户端正确..但不是在服务上...如何更改服务上的超时?

PS:我正在使用 Visual Studio 2010 及其调试模式和适当的 ASP.NET 开发服务器 10.0.0.0

【问题讨论】:

    标签: wcf timeout default duplex


    【解决方案1】:

    binding timeouts的简要总结...

    客户端:

    • SendTimeout 用于初始化 OperationTimeout,它控制发送消息的整个交互(包括 在请求-回复情况下接收回复消息)。这个超时也 从 CallbackContract 方法发送回复消息时适用。
    • OpenTimeout 和 CloseTimeout 在打开和关闭通道时使用(当没有传递明确的超时值时)。
    • 没有使用ReceiveTimeout。

    服务器端:

    • 发送、打开和关闭超时与客户端相同(用于回调)。
    • ServiceFramework 层使用ReceiveTimeout 来初始化会话空闲超时。

    [编辑:一些代码] 也尝试将此添加到您的服务配置中

    <behaviors>
       <endpointBehaviors>
          <behavior name="MyCallbackBehavior">       
             <callbackTimeouts transactionTimeout="00:00:10"/>
          </behavior>
       </endpointBehaviors>
    <behaviors>
    

    然后将行为添加到您的端点

    <endpoint behaviorConfiguration="MyCallbackBehavior" />
    

    【讨论】:

    • 当我设置此行为时,客户端第一次尝试调用服务上的方法时会卡住,并且其他超时(如您在代码 sn-p 中所见)已经设置。 WCF 是否有可能以某种方式忽略我的设置并将所有 TimeOut 值设置回默认值?有没有办法以编程方式设置服务超时我在这里阅读了一个线程,但是解决方案对我并不真正有吸引力但是我的假设是否正确,即当服务回调到客户端时..这个超时持续时间什么都没有与客户端的超时设置有关吗?
    • 这似乎是逐字逐句地从msdn.microsoft.com/en-us/library/hh924831(v=vs.110).aspx获取的。当您从在线来源逐字复制时,您必须引用来源。我已经为你修好了。
    【解决方案2】:

    好的,我发现了错误...

    我使用了正确的 bindingConfiguration

            <wsDualHttpBinding>
            <binding name="wsdualEndpoint" closeTimeout="00:00:10" openTimeout="00:00:10"
                receiveTimeout="00:00:10" sendTimeout="00:00:10" bypassProxyOnLocal="false"
                transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536" clientBaseAddress="http://localhost:1235"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:00:10"  />
                <security mode="Message">
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        algorithmSuite="Default" />
                </security>
            </binding>
        </wsDualHttpBinding>
    

    但线索是这是我对端点的声明:

            <endpoint address="dual" binding="wsDualHttpBinding" 
          name="wsdualEndpoint" contract="INotificationService"/>
    

    因为我的假设是他会获取上面定义的绑定配置并将它们用于我的端点,但这是错误的,我必须将 bindingConfiguration="THE NAME of THE CONFIGURATION" 添加到端点声明中。

    因此,仅供参考,我的工作配置如下所示:

          <wsDualHttpBinding>
        <binding name="MywsdualEndpoint" sendTimeout="00:00:05" bypassProxyOnLocal="false"
            transactionFlow="false" hostNameComparisonMode="StrongWildcard"
            maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
            messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true"/>
          <security mode="Message">
            <message clientCredentialType="Windows" negotiateServiceCredential="true"
                algorithmSuite="Default" />
          </security>
        </binding>
      </wsDualHttpBinding>
    

    正确的端点声明是:

            <endpoint address="dual" binding="wsDualHttpBinding" bindingConfiguration="MywsdualEndpoint" contract="INotificationService"/>
    

    【讨论】:

      猜你喜欢
      • 2014-06-22
      • 1970-01-01
      • 1970-01-01
      • 2013-06-24
      • 1970-01-01
      • 2015-08-15
      • 1970-01-01
      • 2010-10-23
      • 2019-11-11
      相关资源
      最近更新 更多