Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3980284
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:16:20+00:00 2026-05-20T05:16:20+00:00

There are several questions on StackOverflow regarding closing WCF connections, however the highest ranking

  • 0

There are several questions on StackOverflow regarding closing WCF connections, however the highest ranking answers refers to this blog:

http://marcgravell.blogspot.com/2008/11/dontdontuse-using.html

I have a problem with this technique when I set a breakpoint at the server and let the client hang for more than one minute. (I’m intentionally creating a timeout exception)

The issue is that the client appears to “hang” until the server is done processing. My guess is that everything is being cleaned up post-exception.

In regard to the TimeOutException it appears that the retry() logic of the client will continue to resubmit the query to the server over and over again, where I can see the server-side debugger queue up the requests and then execute each queued request concurrently. My code wan’t expecting WCF to act this way and may be the cause of data corruption issues I’m seeing.

Something doesn’t totally add up with this solution.

What is the all-encompassing modern way
of dealing with faults and exceptions
in a WCF proxy?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:16:20+00:00Added an answer on May 20, 2026 at 5:16 am

    Update

    Admittedly, this is a bit of mundane code to write. I currently prefer this linked answer, and don’t see any “hacks” in that code that may cause issues down the road.


    This is Microsoft’s recommended way to handle WCF client calls:

    For more detail see: Expected Exceptions

    try
    {
        ...
        double result = client.Add(value1, value2);
        ...
        client.Close();
    }
    catch (TimeoutException exception)
    {
        Console.WriteLine("Got {0}", exception.GetType());
        client.Abort();
    }
    catch (CommunicationException exception)
    {
        Console.WriteLine("Got {0}", exception.GetType());
        client.Abort();
    }
    

    Additional information
    So many people seem to be asking this question on WCF that Microsoft even created a dedicated sample to demonstrate how to handle exceptions:

    c:\WF_WCF_Samples\WCF\Basic\Client\ExpectedExceptions\CS\client

    Download the sample:
    C# or VB

    Considering that there are so many issues involving the using statement, (heated?) Internal discussions and threads on this issue, I’m not going to waste my time trying to become a code cowboy and find a cleaner way. I’ll just suck it up, and implement WCF clients this verbose (yet trusted) way for my server applications.

    Optional Additional Failures to catch

    Many exceptions derive from CommunicationException and I don’t think most of those exceptions should be retried. I drudged through each exception on MSDN and found a short list of retry-able exceptions (in addition to TimeOutException above). Do let me know if I missed an exception that should be retried.

    Exception   mostRecentEx = null;
    for(int i=0; i<5; i++)  // Attempt a maximum of 5 times 
    {
        try
        {
           ...
           double result = client.Add(value1, value2);
           ...
           client.Close();
        }
    
        // The following is typically thrown on the client when a channel is terminated due to the server closing the connection.
        catch (ChannelTerminatedException cte)
        {
    
          mostRecentEx = cte;
          secureSecretService.Abort();
            //  delay (backoff) and retry 
            Thread.Sleep(1000 * (i + 1)); 
        }
    
        // The following is thrown when a remote endpoint could not be found or reached.  The endpoint may not be found or 
        // reachable because the remote endpoint is down, the remote endpoint is unreachable, or because the remote network is unreachable.
        catch (EndpointNotFoundException enfe)
        {
    
          mostRecentEx = enfe;
         secureSecretService.Abort();
            //  delay (backoff) and retry 
            Thread.Sleep(1000 * (i + 1)); 
        }
    
        // The following exception that is thrown when a server is too busy to accept a message.
        catch (ServerTooBusyException stbe)
        {
          mostRecentEx = stbe;
            secureSecretService.Abort();
    
            //  delay (backoff) and retry 
            Thread.Sleep(1000 * (i + 1)); 
        }
    
        catch(Exception ex)
        { 
             throw ex;  // rethrow any other exception not defined here
        }
    }
    if (mostRecentEx != null) 
    {
        throw new Exception("WCF call failed after 5 retries.", mostRecentEx );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there are a few hundred answers to questions like this on StackOverflow
I have searched on google and stackoverflow for this problem there are several questions
There is some precedent for search-engine-ranking-related questions on StackOverflow, so please don't close this
I've seen several other posts similar to this (namely https://stackoverflow.com/questions/5237/solutions-for-working-with-multiple-branches-in-asp-net ) but there are
There are several questions on StackOverflow discussing the question of when one should use
I know that there are already several questions on StackOverflow about std::string versus std::wstring
There are several questions on StackOverflow along the lines of How do I use
I realize there are several other questions pertaining to this - but either they
There are several questions about text-diff libraries for Java on SO, but none about
There are several questions discussing ways in which progress indication can be added to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.