Programmatically set WCF timeout in debug mode

后端 未结 2 1300
遥遥无期
遥遥无期 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.

    0 讨论(0)
  • 2021-02-06 01:27

    You can create a second binding in the web.config and set a longer sendTimeout.

            if (debug)
            {
                proxy =  new MyClient("WSHttpBinding_MyLocal");
            }
            else
            {
                proxy = new MyClient("WSHttpBinding_MyDev");
            }
    
            <wsHttpBinding>
                <binding name="WSHttpBinding_MyLocal" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:20:00"
    

    ...

    0 讨论(0)
提交回复
热议问题