Question

We have been having a lot of issues with a WCF Service that we have that makes a large amount of outbound requests. We have hanging IIS requests that just keep building up until the server ends up going down. We have taken stack dumps which lead us to believe it is happening when we call HttpWebResponse.GetResponse() in a using statement such as the following code bit.

        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        {
            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                str = reader.ReadToEnd();  //Not Being Hot When Exception Thrown

                reader.Close(); //Not Being Hot When Exception Thrown
                response.Close();  //Not Being Hit When Exception Thrown
            }
        }

I came across a few articles, including '"Do Not Usre 'Using for WCF Clients'

Although I am not creating a WCF client, I am wondering if this is happening because it is within the context of my WCF Service?

The Exception is a TimeoutException because the request is taking more than a minute. I am well aware I can change the timeout, but I am not looking for that fix. I want to know if I am bleeding connections when this exception occurs.

Was it helpful?

Solution

No, your connection will be closed when the object gets disposed. It' not necessary to call Close() here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top