How to Reconnect WCF Service after disconnected c# RRS feed

  • Question

  • User2038048451 posted

    I am creating a WCF Service using c#.I want some suggestions on what is the best way to reconnect wcf service.
    for example, during some operation due to network issues wcf connection is lost so how can I reconnect during operation. one more example is during some operation some exception occured here i want to reconnect wcf service again.need some suggestions on these.

    Tuesday, November 8, 2016 3:08 AM

All replies

  • User1428471904 posted

    There are many ways to do that. 

    1. In the middle of the operation, If you get an exception and you would like to retry it. In this case simply declare a retryCount (=2) variable and loop it if exception is happend.

    2. If you would like to handle it in background process, then log  the failures (In DB or file). Create a new background job to retry these jobs.

    Tuesday, November 8, 2016 5:13 AM
  • User-2057865890 posted

    Hi Nrk_hi,

    You could use try...catch.. block to detect exception occurs during operation call, and try regenerating the client proxy object and connect to the service again.

    reference: https://social.msdn.microsoft.com/Forums/en-US/b8c3a5b5-2c31-4c9e-9b9c-ecc446258756/wcf-reconnect-automatically?forum=wcf 

    Best Regards,


    Wednesday, November 9, 2016 5:40 AM