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

  • Home
  • SEARCH
  • 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 6003179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:05:06+00:00 2026-05-23T01:05:06+00:00

I’ve got a WCF service and want to connect to it using a TCP

  • 0

I’ve got a WCF service and want to connect to it using a TCP binding. This is all well and good, but how are you supposed to handle the clients? I’ve noticed that if you create a new client for each call it doesn’t re-use the channel and leaves around a bunch of TCP connections until they time out.

Is it normal use to create a client, call a method on it, then close it?

What if you want to re-use the connection? What are the limitations on that? Can you make simultaneous calls from different threads? If you can’t, do you have to do your own connection pooling? And when re-using the connection, do you have to check the connection state before making calls and clean it up if it’s faulted?

  • 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-23T01:05:07+00:00Added an answer on May 23, 2026 at 1:05 am

    Well this is a lot of questions together and the situation is really little bit complicated. When you create a client you can do it either via service reference and get class derived from ClientBase<ServiceContract> or you can use ChannelFactory<ServiceContract> and create channels manually (the former case uses the ChannelFactory internally).

    How this relates to your question? Lets first look at real TCP connection. When you define NetTcpBinding you can set its MaxConnections property (default is 10). This property defines the number of pooled connection. It means that if you create client channel to the server and close the channel the connection is not terminated immediately. It remains opened in the pool until it is used by another opened client channel to the same server or until its idle timeout expires. You can open as many connections as the server allows you but only number defined by MaxConnections will be pooled once you close related client channels. Other connections will be terminated immediately. If you create CustomBinding you can use TCP transport directly where you can also control idle timeout (I think default is 2 minutes). Connections are pooled as long as the related ChannelFactory is not destroyed = use one ChannelFactory per application (ClientBase do it internally).

    Now lets talk about channel itself because it is related to your other questions. WCF differs sessionfull and sessionless channels. TcpTransportChannel is sessionfull. It means that once you open the channel you create a session. Session means that all requests from the single client proxy are by default always served by the same service instance (per session instancing). But the instance is by default single threaded. It means that you can have multiple threads using the same proxy but the service will handle requests in a sequential order. If you want your service to process multiple request simultaneously you must mark it with [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple]. Once you do it you are responsible for thread safe processing in the service (multiple threads accessing same service instance).

    Sessionful channels have one big disadvantage. Any failure or exception on the service will break the channel and you will usually know about it after you try to use the channel again (exception saying that channel is in faulted state and cannot be used). You must always correctly handle these situations and you must correctly close channels/proxies once you don’t want to use them or abort them once they are faulted. Faulted channel cannot be repaired – it must be aborted and you must create a new proxy/channel. I’m not sure if connections are returned to pool if you don’t do that.

    Reusing proxy/channel depends on the type of application you are building. I would definitely not reuse proxy/channel among multiple requests in web application but reusing is absolutely ok in WinForm or WPF application.

    Edit:

    Yes ClientBase uses ChannelFactory internally. The way how the ChannelFactory is used has changed over time. In .NET 3.0 the factory was created for each ClientBase instance. Since .NET 3.5 WCF uses internally MRU cache (Most recently used) which caches up to 32 lastly used factories. To take advantage of this caching you must use proxy constructor without parameters or with endpointConfigurationName and remoteAddress / EndpointAddress. You mustn’t create endpoint in the code – these proxies doesn’t use the cache. More about the topic is here.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace

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.