Programmatically set WCF timeout in debug mode

后端 未结 2 1308
遥遥无期
遥遥无期 2021-02-06 00:50

I\'m using WCF in communication between a server and client (both written in C#).

In release-mode, the timouts should be set to ~20 seconds, but in debug mode I want to

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-06 01:23

    You could do the following:

    • create the binding and the endpoint in code
    • set the timeouts on the binding instance
    • then create your client proxy using those two elements

    Something like:

    BasicHttpBinding myBinding = new BasicHttpBinding("ConfigName");
    myBinding.CloseTimeout = .......
    myBinding.OpenTimeout = .......
    myBinding.ReceiveTimeout = .......
    myBinding.SendTimeout = .......
    
    EndpointAddress myEndpoint = new EndpointAddress("http://server:8181/yourservice");
    
    YourServiceClient proxy = new YourServiceClient(myBinding, myEndpoint);
    

    That way, you can leverage the basic config when describing binding timeouts and yet you can tweak the settings you want and create your client proxy from it.

提交回复
热议问题