IIS stops connecting to WCF service until app pool is recycled

795 Views Asked by At

I have an ASP.NET MVC application hosted on IIS 8.5. The site will function for anything between hours to days without issue but eventually starts getting EndpointNotFoundException when attempting to connect to a WCF service hosted over net.tcp on another machine.

If I try to connect to the WCF service from the IIS machine using a different app pool, console application, etc. they all connect without error. It is not every connection attempt that is failing either, just most of them.

As soon as I recycle the app pool everything starts working again.

I do not see anything in the Event Viewer and Elmah shows no other errors before the EndpointNotFoundException starts showing up.

I have all WCF calls wrapped in try/catch blocks that will perform the necessary close/abort commands to make sure all clients are properly closed. Here's the code that's being used.

try
{
    action();
}
finally
{
    try
    {
        client.Close();
    }
    catch
    {
        client.Abort();
    }
}

I have also created an application that monitors the server. If it sees that the server starts getting errors it tries to recycle the app pool with the following code:

var serverManager = new ServerManager();
var pool = serverManager.ApplicationPools.Single(p => p.Name == "POOLNAME");
pool.Recycle();

However, even this code doesn't stop the exceptions. I have to manually log into the machine, open IIS Manager, right-click the app pool, and click recycle.

I have several other WCF servers/clients in apps like Winforms and windows services which do not have this issue. It is only the client app being hosted on IIS that is having problems.

Any suggestions on how to track down what is causing this error?

0

There are 0 best solutions below