How can I set the receiveTimeout and sendTimeout to infinity with this WCF contact?

*爱你&永不变心* 提交于 2019-12-22 01:27:55

问题


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?


回答1:


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.




回答2:


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

sendTimeout="10675199.02:48:05.4775807"



回答3:


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;

}



来源:https://stackoverflow.com/questions/6178300/how-can-i-set-the-receivetimeout-and-sendtimeout-to-infinity-with-this-wcf-conta

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!