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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:33:54+00:00 2026-05-23T04:33:54+00:00

I’m experimenting with making async WCF calls. I’m looking at making multiple calls to

  • 0

I’m experimenting with making async WCF calls. I’m looking at making multiple calls to the same service.

From the client I create a new channel for each call, make the call (giving it a callback method), and then in the callback I close the channel.

In the service I have added a call to thread.sleep to simulate the service doing some work.

The first 20 or so calls complete ok (this number varies each time). So after what seems a random number of calls, I receive this exception on the client:

Could not connect to net.tcp://localhost:61501/Calulator. The connection attempt lasted for a time span of 00:00:02.9332933. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:61501.

So I have a couple of questions:

  1. Am I right to be opening a new
    channel for each call?
  2. What is causing this exception?

Many thanks in advance for any help.

My code is as follows, and can also be found here:
https://subversion.assembla.com/svn/agilenet/tags/WcfStackOverflow/Wcf

Service:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace Service
{
    class Program
    {
        static void Main(string[] args)
        {
            NetTcpBinding netBinding = new NetTcpBinding();

            ServiceHost host = null;
            host = new ServiceHost(
                    typeof(Calculator),
                    new Uri("net.tcp://localhost:61501/Calulator"));
            host.AddServiceEndpoint(
                    typeof(ICalculator),
                    netBinding,
                    string.Empty);
            host.Open();

            Console.ReadLine();
        }
    }

    [ServiceContract]
    public interface ICalculator
    {
        [OperationContract]
        int Add(int value1, int value2);

        [OperationContract(AsyncPattern = true)]
        IAsyncResult BeginAdd(int value1, int value2, AsyncCallback callback, object state);

        int EndAdd(IAsyncResult result);
    }

    public class Calculator : ICalculator
    {
        public int Add(int value1, int value2)
        {
            Console.WriteLine(
                "Incoming Add request {0}, {1}",
                value1.ToString(),
                value2.ToString());
            System.Threading.Thread.Sleep(500);
            return value1 + value2;
        }

        public IAsyncResult BeginAdd(int value1, int value2, AsyncCallback callback, object state)
        {
            throw new NotImplementedException();
        }

        public int EndAdd(IAsyncResult result)
        {
            throw new NotImplementedException();
        }

    }
}

Client:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using Service;

namespace Client
{
    class Program
    {
        static void Main(string[] args)
        {

            NetTcpBinding netBinding = new NetTcpBinding();
            ChannelFactory<ICalculator> factory = new ChannelFactory<ICalculator>(
                netBinding,
                "net.tcp://localhost:61501/Calulator");

            for (int i = 0; i < 100; i++)
            {
                ICalculator service = factory.CreateChannel();
                service.BeginAdd(i, 0, SaveCallback, service);
            }

            Console.ReadLine();
        }

        static void SaveCallback(IAsyncResult ar)
        {
            ICalculator service = (ICalculator)ar.AsyncState;
            Console.WriteLine(service.EndAdd(ar).ToString());
            ((IContextChannel)service).Close();

        }

    }

}
  • 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-23T04:33:54+00:00Added an answer on May 23, 2026 at 4:33 am

    I think that you have encountered windows (7/Vista/XP) tcp connection limit. These OS:s limit the number of (inbound) tcp connections to 20. Googling “windows tcp connection limit” gives you a lot of more information about the subject.

    SuperUser has also a thread about this subject: https://superuser.com/questions/253141/inbound-tcp-connection-limit-in-windows-7. More information also in ServerFault (linked from SU).

    So to answer your question:

    1. No, you should not open new channel for each call.
    2. You hit the limit of non-server version of windows (probably 7 or Vista because you can get 20 connections). You get random number of successful connections because some times the OS is quick enough to clean few first connections, but the request rate is so high, that you are going to hit the maximum eventually.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.