tags:

views:

83

answers:

1

Is there a way of creating an instance of a third-party/external library when my WCF server is started and not create a new one everytime a request is received? I am looking for something sort-of like a Global.asax file in a asp.net website.

I am relatively new to WCF and I am currently only prototyping using a console app and serving my WCF service with System.ServiceModel.Web.WebServiceHost (I am doing REST on top of WCF). The library in question opens a TCP socket to a seperate (internal) service. I will eventually have quite a lot of load on the service and would prefer to only keep one socket open instead of opening and closing sockets as requests come in.

Any help or tips would be appreciated.

A: 

Sounds like you want a singleton service. This link may be of some use in how to set it up:

http://codeidol.com/csharp/wcf/Instance-Management/Singleton-Service/

You'll just keep the socket open at the service level, and access that instance in your method calls.

Jacob Ewald