Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best approach for WCF client

Tags:

wcf

I have client application that uses WCF service to insert some data to backend database. Client application is going to call service on per event basis (it can be every hour or every second).

I'm wondering what's the best way of calling that service.

Should I create communication channel and keep it open all the time, or should I close channel after each call and create it again?

like image 378
Slav Avatar asked Oct 29 '08 12:10

Slav


2 Answers

The first question is whether your server needs to maintain any state about the client directly (i.e. are you doing session-like transactions?) If you are, you will need to be able to manage how the server holds the information between communications.

My initial feeling of your question is that if there is no need to leave a connection open, then close it each time and recreate a new connection on demand. This will avoid issues where a connection can be placed into a faulted state between calls. The overhead of creating and destroying connections is minimal, and it will (probably) save you a lot of time in debugging when something goes wrong.

like image 123
ZombieSheep Avatar answered Oct 12 '22 23:10

ZombieSheep


I would think you probably wanna implement a Keep Alive pattern, with a configurable duration to inform your underlying mechanism to close the connection if past beyond the Keep-alive duration with zero communication activity.

like image 32
icelava Avatar answered Oct 12 '22 22:10

icelava