4

我这里有一个 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

4

2 回答 2

4

绑定超时的简要总结...

客户端:

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

服务器端:

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

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

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

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

<endpoint behaviorConfiguration="MyCallbackBehavior" />
于 2010-02-11T09:25:09.837 回答
3

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

我做了 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"/>
于 2010-02-11T12:40:51.500 回答