Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WCF服务,如何增加超时?_Wcf - Fatal编程技术网

WCF服务,如何增加超时?

WCF服务,如何增加超时?,wcf,Wcf,这似乎是一个愚蠢的问题,但WCF中的所有内容似乎都比asmx复杂得多,如何增加svc服务的超时 以下是我到目前为止的情况: <bindings> <basicHttpBinding> <binding name="IncreasedTimeout" openTimeout="12:00:00" receiveTimeout="12:00:00" closeTimeout="12:00:00"

这似乎是一个愚蠢的问题,但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>

然后我的端点映射如下:

<endpoint address="" 
  binding="basicHttpBinding" bindingConfiguration="IncreasedTimeout"
             contract="ServiceLibrary.IDownloads">
             <identity>
                <dns value="localhost" />
             </identity>
          </endpoint>

我得到的确切错误是:

请求通道在00:00:59.9990000之后等待答复时超时。增加传递给请求调用的超时值或增加绑定上的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>

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

<bindings>
  <basicHttpBinding>
    <binding name="IncreasedTimeout"
             sendTimeout="00:25:00">
    </binding>
  </basicHttpBinding>

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

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

receiveTimeout
有点像
sendTimeout
的镜像-发送超时是您等待服务器响应的时间量,而
receiveTimeout
是您给客户端接收和处理服务器响应的时间量

在来回发送“正常”消息的情况下,这两条消息可能都很短,尤其是
接收超时时间
,因为接收SOAP消息、解密、检查和反序列化几乎不需要时间。与流媒体不同的是,在这种情况下,您可能需要更多的时间在客户端上完成从服务器返回的流的“下载”

还有openTimeout、receiveTimeout和closeTimeout。将为您提供有关这些功能的更多信息

为了认真掌握WCF的所有复杂之处,我强烈建议您购买Michele Leroux Bustamante的“”一书:

您还可以花一些时间观看她由15集组成的“剧集”—强烈推荐

关于更高级的主题,我建议你查阅Juwal Lowy的服务书籍


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

最近收到了相同的错误,但能够通过确保关闭每个WCF客户端调用来修复它。 例如


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

请查看以下示例:

using(WCFServiceClient client = new WCFServiceClient ())
{ 
    client.Endpoint.Binding.SendTimeout = new TimeSpan(0, 1, 30);
}

我试图将绑定部分添加到web.config中,但现在抛出了一个错误。。。。我还将我的服务中的端点更改为“我想我明白了”-binding=“basicHttpBinding”bindingConfiguration=“IncreasedTimeout”确切地说-绑定是您使用的协议类型-basicHttp、wsHttp、netTcp。绑定配置是您在配置中创建的用于修改超时等的配置。有趣的是,即使执行此操作后,仍然会出现超时错误,您能否提供尽可能多的信息?嗯,是的-通常,它必须在客户端和服务器上进行设置,甚至-例如,在“inactivityTimeout”的情况下你能展示一下你做了什么吗?我也遇到同样的问题如果您使用“WCF测试客户端”,请右键单击服务树中的“配置文件”,然后单击“使用SvcConfigEditor编辑”,并更改绑定内的超时。不要使用“使用”方法:在的注释中,有一些示例说明了如何在不处理故障通道对象的情况下仍使用
。下面是另一位blogger,其方法更兼容使用
块的
。这是一个更好的解决方案,而不是更新配置,以便我可以为不同的调用和服务配置不同的值,非常感谢
using(WCFServiceClient client = new WCFServiceClient ())
{ 
    //More codes here 
}
using(WCFServiceClient client = new WCFServiceClient ())
{ 
    client.Endpoint.Binding.SendTimeout = new TimeSpan(0, 1, 30);
}