Chris
Chris

Reputation: 4495

c# ChannelFactory: How to reconnect/reopen connection after FaultException|TimeoutException?

I am using a ChannelFactory with netTcpBinding. Sometimes I get exceptions and after these I can not use the channel anymore because it is in faulted state.

What should I do to reestablish the connection? Should I call abort(), then close/open. Or Close(), then open(), or should I just use a new object like:

myPublicChannel = this.ChannelFactory.CreateChannel();

Should I reopen the connection just in my catch block? Will I need a special locking mechanism because other threads could also use this channel and then try to reestablish the connection simultaneously.

Thank you very much for your answer in advance!

Thank you for your answer. Here is a link I found that could be helpfull for others with the same problem/question:

Link

Upvotes: 1

Views: 1663

Answers (1)

Jesus Ramos
Jesus Ramos

Reputation: 23268

I would actually close and set it to null to dispose anything from the connection then use open, I have written some web services before where not disposing the ChannelFactory caused some memory leaks and other problems.

Upvotes: 1

Related Questions