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 8465269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:59:34+00:00 2026-06-10T14:59:34+00:00

I have a TimeoutException problem, I am using C# 4.0 (can’t upgrade to 4.5

  • 0

I have a TimeoutException problem, I am using C# 4.0 (can’t upgrade to 4.5 anytime soon) and WCF. Note that I do not control the Server and cannot see the code and or technology that are used. The problem happens with different servers made by different people.

I send as many request as I can to many servers (let’s say 10), one per server at any time. They go from 2 to 30 requests per second. Between 30 seconds to 5 minutes, I will get some TimeoutException :

exception   {"The HTTP request to 'http://xx.xx.xx.xx/service/test_service' has exceeded the allotted timeout of 00:02:10. The time allotted to this operation may have been a portion of a longer timeout."}   System.Exception {System.TimeoutException}.

Stack Trace :
Server stack trace: 
   at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult     result)
   at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeEndService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,  IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Device.EndTest(IAsyncResult result)
   at DeviceClient.EndTest(IAsyncResult result) in ...
   at TestAsync(IAsyncResult ar) in ...

The InnerException is :

[System.Net.WebException]   {"The request was aborted: The request was canceled."}  System.Net.WebException
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)

Wireshark tells me that I do not even open a connection (no SYN). So this should be a client problem. I have many TIME_WAIT connections in TCPView

Using Sync calls is working, but not possible.

Note that in the following code example, there is one method call per server. (In my case, 10 concurrent TestAsync)

(in the real project, we use CCR instead of Semaphore, same result)

private void AsyncTest()
{   
    //GetServiceObject Will add custom bindings and more..
    Client client = ClientBuilder.GetServiceObject();

    while (true)
    {
         Semaphore semaphore = new Semaphore(0,1);
         client.BeginTest(BeginTestCallback, new AsyncState
         {
             Client = client,
             Semaphore = semaphore
         });

         semaphore.WaitOne();   
    }   
 }

private void BeginTestCallback(IAsyncResult asyncResult)
{
    try
    {
        AsyncState state = asyncResult.AsyncState as AsyncState;

        Client client = state.Client;
        Semaphore semaphore = state.Semaphore;

        Client.EndTest(asyncResult);    

        semaphore.Release();
    }
    catch (Exception e)
    {
        //Will catch the exception here because of Client.EndTest(asyncResult)
        Debug.Assert(false, e.Message);
    }
}

I tried with

ServicePointManager.DefaultConnectionLimit = 200;
ServicePointManager.MaxServicePointIdleTime = 2000;

As some post suggested, without success.

Even if I set really High Open, send, receive and close timeouts, it will do the same exception. WCF seems to be “stuck” at sending the request. The server continues to respond correctly to other requests.

Have any idea?

Also, If I do this (BeginTest in Callback instead of while(true)), it will never do the exception?!?!

private void AsyncTest()
{
    //GetServiceObject Will add custom bindings and more..
    Client client = ClientBuilder.GetServiceObject();
    try
    {
        client.BeginTest(BeginTestCallback, new AsyncState
        {
            Client  = client            
        });
    }
    catch (Exception e)
    {
        Debug.Assert(false, e.Message);
    }
}

private void BeginTestCallback(IAsyncResult asyncResult)
{
    try
    {
        AsyncState state = asyncResult.AsyncState as AsyncState;        

        state.Client.EndTest(asyncResult);

        state.Client.BeginTest(BeginTestCallback, state);
    }
    catch (Exception e)
    {
        //No Exception here
        Debug.Assert(false, e.Message);
    }
}
  • 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-06-10T14:59:36+00:00Added an answer on June 10, 2026 at 2:59 pm

    After more testing, I found out that if the begin/end mechanism is not executed on the same thread pool, it will randomly do this behavior.

    In the first case, “AsyncTest” was spawned within a new thread with ThreadStart and Thread. In the second case, only the first “begin” is called on the dedicated thread and since the problem occurs at random, there is a small chance that the exception would happen on first request. The other “begin” are made on the .net ThreadPool.

    By using Task.Factory.StartNew(() => AsyncTest()) in the first case, the problem is gone.

    In my real project, I still use CCR (and the CCR threadpool) to do everything until I have to call the begin/end.. I will use the .net threadpool and everything is working now.

    Anyone have better explanation of why WCF doesn’t like to be called on another threadpool?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with WCF NetNamedPipeBinding. When I run my server and client
I have a WCF application that sometimes performs long running queries. I have created
I have an Activity that retrieves information from a remote server and displays it
I have a WCF service that implements the 'Custom-Username-Password-Validator'. The service itself checks the
I have web application with WCF service. That service contains method that implements message
We have an asynchronous WCF service operation that gets log files from all of
I have the following code: class TimeOutException {}; template <typename T> class MultiThreadedBuffer {
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I'm using the following code to accept bad server certificates: ServicePointManager.ServerCertificateValidationCallback = delegate(object s,
I have just started the Hello World App using Blackberry Eclipse Plugin. I have

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.