如何使用此WCF联系人将receiveTimeout和sendTimeout设置为无穷大?

时间:2011-05-30 15:46:25

标签: wcf wcf-binding

我的主机中有以下app.config:

  

<services>
  <service name="DCC_Service.DCCService" behaviorConfiguration="serviceBehavior">
    <endpoint binding="netNamedPipeBinding" contract="DCC_Service.IDCCService" address="DCCService" />
    <endpoint binding="mexNamedPipeBinding" contract="IMetadataExchange" address="mex" />
    <host>
      <baseAddresses>
        <add baseAddress="net.pipe://localhost/"/>
      </baseAddresses>
    </host>
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="serviceBehavior">
      <serviceMetadata httpGetEnabled="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

如何将netNamedPipeBinding超时设置为无限又名Timespan.MaxValue

3 个答案:

答案 0 :(得分:23)

使用infinite表示各种超时值 - 关闭,打开,接收和发送。您可以在绑定配置中指定这些超时。

<bindings>
    <netNamedPipeBinding>
        <binding name="mybinding" closeTimeout="infinite" openTimeout="infinite"
            receiveTimeout="infinite" sendTimeout="infinite" />
    </netNamedPipeBinding>
</bindings>

bindings部分与servicesbehaviors部分处于同一级别。唯一剩下的就是引用服务端点中的绑定配置。

<services>
  <service name="DCC_Service.DCCService" behaviorConfiguration="serviceBehavior">
    <endpoint binding="netNamedPipeBinding"
        contract="DCC_Service.IDCCService"
        address="DCCService"
        bindingConfiguration="mybinding"/>         <!-- SEE THIS LINE -->
    <endpoint binding="mexNamedPipeBinding"
        contract="IMetadataExchange"
        address="mex" />
    <host>
      <baseAddresses>
        <add baseAddress="net.pipe://localhost/"/>
      </baseAddresses>
    </host>
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="serviceBehavior">
      <serviceMetadata httpGetEnabled="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

我不记得具体(我现在没有时间看),但你可能不得不把这些东西放在你的客户端配置中。

答案 1 :(得分:8)

将其设置为最大时间跨度,即10675199.02:48:05.4775807

sendTimeout="10675199.02:48:05.4775807"

答案 2 :(得分:5)

你也可以给出最长的时间,如下所示

{

            binding.CloseTimeout = TimeSpan.MaxValue;

            binding.OpenTimeout = TimeSpan.MaxValue;

            binding.ReceiveTimeout = TimeSpan.MaxValue;

            binding.SendTimeout = TimeSpan.MaxValue;

}