2

I have a situation where I have two programs (one exe and one dll loaded into the process space of another third-party exe) communicating requests with each other using a local machine wcf service (using net named pipe binding). There's a third host exe that starts hosting the service. It all works great (so far anyways... I'm still learning), but I got to thinking about what would happen if the channel faults or the service times out. What would be the best practice for checking and handling faults as well as keep the channel alive?

In my case it will be up to the user to keep the applications open or close them and we do have those users who tend to keep them open overnight, over the weekend, etc... It seems to me this could open the possibility of a fault or loss of service and I don't have a clue how to recover. Any help would be greatly appreciated.

bjhuffine
  • 924
  • 1
  • 11
  • 23

1 Answers1

1

Firstly, why would you keep the channel alive indefinitely?

Imagine you are connecting to a database from which you want to read over the course of one day. Would you create the database connection in the morning and then close it in the evening?

It is relatively cheap to construct a channel in WCF for each call, unless you know you are going to be making multiple calls within a few seconds of each other, in which case you should reuse the channel.

EDIT

This post explains how to do it. It's pretty complicated and it may be easier to just set a huge timeout value for the binding in code (as suggested at the end of the post):

Do WCF Callbacks TimeOut

EDIT

There's tons of stuff on google about this: http://bit.ly/10ZPWE2

Community
  • 1
  • 1
tom redfern
  • 30,562
  • 14
  • 91
  • 126
  • In the case of a duplex channel, if it gets closed doesn't that prevent the callback's from working? – bjhuffine May 16 '13 at 14:40
  • Yes, for duplex you need to keep the channel open. One of the MANY reasons not to use duplex channels in WCF. – tom redfern May 16 '13 at 14:45
  • In my case, I don't have a choice... I'm basically creating a home-grown messaging/request service to operate between the dll and the exe due to my current requirements and environment. So... between both the ServiceHost and the Channel... what's the best way to handle faults and keep them alive? – bjhuffine May 16 '13 at 14:55
  • Okay, I didn't know if with faults and other potential communication-ending events and/or issues if the answer would be beyond just adjusting timeouts... For example, the DuplexChannelFactory object has a Faulted event. Is this worth monitoring... if so, use abort and reset? Also, most of what I'm seeing seems to involve the channel, but what about the ServiceHost? Are there events worth monitoring there? Or special ways of handling it to ensure the service and channel stays alive? I was just figuring someone's been here before themselves. – bjhuffine May 16 '13 at 19:43
  • Not me. I built an auction service and client using duplex wcf calls - if either channel faulted the user just had to restart the client and everything was fine. – tom redfern May 17 '13 at 08:14