2

I'm developing a web site based on .NET MVC and I'm using WCF Service with ibatis.net.

In my controller I use a WCF service, but I don't dispose or close the WCF client. Should I close or dispose WCF clients?

public class HomeController : BaseResultController
{
    // 1. Create WCF Service 
    SomeWCFClient mSomeWcfC = new SomeWCFClient();

    public ActionResult Index(){

        // 2. Used/Consume some Service 
        IList<SomeModel> lResultData  = mSomeWcfC.GetSomeData(); 

        // 3. [Q]Should I close WCF Service, here? If Yes, let me know Where should i write code 
        //    If I don't have to do also let me know that              

        return View();
    }

}
MatthewMartin
  • 32,326
  • 33
  • 105
  • 164
  • Have a look at [this question](http://stackoverflow.com/questions/7184509/why-is-it-important-to-dispose-close-a-wcf-client-proxy). And when you are about to implement the disposing logic, make sure you read [this other question](http://stackoverflow.com/questions/573872/what-is-the-best-workaround-for-the-wcf-client-using-block-issue) – Daniel J.G. Aug 07 '14 at 08:28
  • Thanks @DanielJ.G. can i see a sample code on ASP.NET MVC because even though i red above URL usually they explain about NOT ASP.NET MVC.. so I just want to know in ASP.NET MVC case thanks man – Jeonhwan Won Aug 08 '14 at 01:02
  • They are not talking about MVC because it is a good practice when using a WCF client, no matter where do you use it. – Daniel J.G. Aug 08 '14 at 08:09
  • @DanielJ.G. Ah thanks ok i will make my code and update again thanks – Jeonhwan Won Aug 08 '14 at 08:20
  • I read links and I agree with you all.. but I also read this one: https://docs.microsoft.com/en-us/azure/azure-functions/manage-connections and now I have doubts again. It says: `A common question about the .NET HttpClient is "Should I be disposing my client?" In general, you dispose objects that implement IDisposable when you're done using them. But you don't dispose a static client because you aren't done using it when the function ends. You want the static client to live for the duration of your application.` Ok, it talks about azure function.. but its execution is not like an http request? – Simone Dec 03 '18 at 09:44

0 Answers0