19

I have the following app.config in my Host:

<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>

How do I set the netNamedPipeBinding timeouts to infinite aka Timespan.MaxValue?

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
Ryan R
  • 8,342
  • 15
  • 84
  • 111

3 Answers3

25

Use infinite for the various timeout values - close, open, receive, and send. You specify these timeouts in a binding configuration like so.

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

The bindings section goes at the same level as the services and behaviors sections. The only thing left is to reference the binding configuration in your service endpoint.

<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>

I don't remember specifically (and I don't have time to look right now), but you may have to put this stuff in your client configuration as well.

Matt Davis
  • 45,297
  • 16
  • 93
  • 124
  • 3
    Thanks Matt. I added the following to my Client: `NetNamedPipeBinding binding = new NetNamedPipeBinding(); binding.SendTimeout = TimeSpan.MaxValue; binding.ReceiveTimeout = TimeSpan.MaxValue;` And then used that binding when instantiating my Duplex Channel Factory. – Ryan R May 30 '11 at 16:15
  • I added the ` ... ` but VS is underlining each `"infinite"` value in blue with an invalid parameter message. e.g. `The \`openTimeout\` attribute is invalid - The value \`infinite\` is invalid according to its datatype \`String\` - The Pattern constraint failed.` – Ryan R May 30 '11 at 16:21
  • 6
    I believe that's a Visual Studio artifact. The "infinite" string is processed correctly when used at runtime. See the answer here: http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/46f9f3ad-da26-493d-9743-895ee9bd4c61/ – Matt Davis May 30 '11 at 16:28
  • Great! However, when I open the auto-generated app.config in my `client` I still see the following: `` The timeouts were not set when I updated my service reference? Are these overridden by the timeouts I set programmatically in the client (see my first comment)? – Ryan R May 30 '11 at 16:41
  • I don't believe these configuration settings are updated when updating the service reference, so you'll have to configure them on the client side manually. I'm pretty sure the timeouts you use programmatically override the default settings in the config file. – Matt Davis May 30 '11 at 16:54
  • Great thanks Matt, your feedback with WCF related stuff is very valuable. – Ryan R May 30 '11 at 17:00
  • Also note that the WCF configuaration editor doesn't like this value in any of the time related fields either, so you'll have to add it manually – noonand Aug 01 '13 at 10:59
8

Set it as max timespan which is 10675199.02:48:05.4775807

sendTimeout="10675199.02:48:05.4775807"
Libish Jacob
  • 308
  • 4
  • 8
  • 1
    I had to use this since "infinite" gave a warning in the config: Value "infinite" is invalid according to its data type: string. Although your prescription is finite, I'll be long dead when when it finally times out, and so will be my app :) – I Stand With Russia Aug 20 '16 at 00:02
5

You can also give maximum time out like below

{

            binding.CloseTimeout = TimeSpan.MaxValue;

            binding.OpenTimeout = TimeSpan.MaxValue;

            binding.ReceiveTimeout = TimeSpan.MaxValue;

            binding.SendTimeout = TimeSpan.MaxValue;

}

Hari
  • 416
  • 1
  • 6
  • 20
  • @Ricardo Pontual : Apart from adding spaces I could find any improvements in the answer. This is NOT how you improve the answer. Removed your changes, – Hari Nov 02 '16 at 08:11
  • 2
    You should know that the `{ }` is part of code, I've edited to put in code block. Really this does not improve the question, but a well formatted code is a good practice for all developers. – Ricardo Pontual Nov 03 '16 at 00:55