locked
Closing WCF Connections

    Question

  • I have a LOB app that I am developing that hits a WCF service for access our SQL database.

    What I am seeing is that when the app makes a call to the server to get data, a connection is made from the IIS server to the backend database.

    What is happening is these connections from the IIS server to the database are never dropped. How can I force the connections to be dropped, either at the IIS level or the app level when the app is done with them.

    Wednesday, February 26, 2014 4:38 PM

All replies

  • There is not much info about how your service or data access layer is implemented but probably the wcf service is designed by default session mode, so as long as the proxy exists the service instance exists, hence the connection is not closed..

    quick approach would be to use [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]  (this is the service behavior attribute that goes over the service implementation class - more info on InstanceContextMode ) for creating Per-Call service and destroying the client proxy as soon as you finish the call...


    Can Bilgin
    Blog Samples CompuSight

    Wednesday, February 26, 2014 7:04 PM
  • I put [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]  in my DataProvider.svc in my Service. I think that is where it goes.

    How does that work with the client. In my client I am doing this to call the service.

    ServiceReference1.DataProviderClient myservice = new ServiceReference1.DataProviderClient();

    What should I do to properly close the connections when the 'myservice' is finished it work so that the WCF and database connections are closed.

    Sorry, I am new to this.

    Wednesday, February 26, 2014 8:14 PM