WCF服务,如何增加超时?

JL.*_*JL. 87 wcf

可能看起来像一个愚蠢的问题,但WCF中的所有内容似乎都比asmx复杂得多,我怎样才能增加svc服务的超时?

这是我到目前为止:

<bindings>
      <basicHttpBinding>
        <binding name="IncreasedTimeout" 
          openTimeout="12:00:00" 
          receiveTimeout="12:00:00" closeTimeout="12:00:00"
          sendTimeout="12:00:00">
        </binding>
      </basicHttpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)

然后我的端点映射如下:

<endpoint address="" 
  binding="basicHttpBinding" bindingConfiguration="IncreasedTimeout"
             contract="ServiceLibrary.IDownloads">
             <identity>
                <dns value="localhost" />
             </identity>
          </endpoint>
Run Code Online (Sandbox Code Playgroud)

我得到的确切错误:

在00:00:59.9990000之后等待回复时,请求通道超时.增加传递给Request的调用的超时值或增加Binding上的SendTimeout值.分配给此操作的时间可能是较长超时的一部分.

在WCF测试客户端中,有一个配置图标,其中包含我的服务的运行时配置:

你可以看到它与我为它设定的值不一样吗?我究竟做错了什么?

<bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IDownloads" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01: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="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="">
                            <extendedProtectionPolicy policyEnforcement="Never" />
                        </transport>
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
Run Code Online (Sandbox Code Playgroud)

mar*_*c_s 172

在绑定配置中,您可以调整四个超时值:

<bindings>
  <basicHttpBinding>
    <binding name="IncreasedTimeout"
             sendTimeout="00:25:00">
    </binding>
  </basicHttpBinding>
Run Code Online (Sandbox Code Playgroud)

最重要的是sendTimeout,它表示客户端等待WCF服务响应的时间.您可以hours:minutes:seconds在设置中指定- 在我的示例中,我将超时设置为25分钟.

openTimeout顾名思义是时间你愿意,当你打开你的WCF服务的连接等待的时间量.类似地,closeTimeout是关闭连接(处置客户端代理)之前您将在抛出异常之前等待的时间量.

receiveTimeout有点像镜子sendTimeout- 虽然发送超时是你等待服务器响应receiveTimeout的时间,但是你给客户端接收和处理来自服务器的响应的时间量.服务器.

如果你来回发送"正常"消息,两者都可能非常短 - 尤其是receiveTimeout,因为接收SOAP消息,解密,检查和反序列化它应该几乎没有时间.故事与流式传输不同 - 在这种情况下,您可能需要更多时间在客户端上实际完成从服务器返回的流的"下载".

还有openTimeout,receiveTimeout和closeTimeout.有关绑定MSDN文档为您提供了有关这些内容的更多信息.

为了严格控制WCF的所有复杂性,我强烈建议您购买Michele Leroux Bustamante撰写的" 学习WCF "一书:

学习WCF http://ecx.images-amazon.com/images/I/51GNuqUJq%2BL._BO2,204,203,200_PIsitb-sticker-arrow-click,TopRight,35,-76_AA240_SH20_OU01_.jpg

你还花了一些时间看她的15部分" WCF Top to Bottom "截屏系列 - 强烈推荐!

对于更高级的主题,我建议您查看Juwal Lowy的编程WCF服务手册.

编程WCF http://ecx.images-amazon.com/images/I/41odWcLoGAL._BO2,204,203,200_PIsitb-sticker-arrow-click,TopRight,35,-76_AA240_SH20_OU01_.jpg


JL.*_*JL. 24

需要在客户端级别设置超时配置,因此我在web.config中设置的配置无效,WCF测试工具有自己的配置,您需要设置超时.

  • JL:你能说明你做了多少exaclty?我有相同的问题 (8认同)

小智 20

最好的方法是在代码中更改所需的任何设置.

看看下面的例子:

using(WCFServiceClient client = new WCFServiceClient ())
{ 
    client.Endpoint.Binding.SendTimeout = new TimeSpan(0, 1, 30);
}
Run Code Online (Sandbox Code Playgroud)