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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:36:23+00:00 2026-05-29T07:36:23+00:00

I am currently looking at some code which basically reads data line-by-line from a

  • 0

I am currently looking at some code which basically reads data line-by-line from a file and calls an appropriate method on a WCF client for each line. My problem with the code is that a new client is created for each operation ie:

function CallSomeOp(line)
 {
   using (var client = new Client()
   {
       client.SomeOp(line);
   }
 }

This seems to make the client close the connection and reopen a new one for each line in the file which seems like a big overhead. What I would like to do is move the creation of the client outside the function and into initialization, so that multiple operations are called on one client, ie:

 using (var client = new Client())
 {
     for(var line in lines)
     {
        CallSomeOp(line, client);
     }
 }

But I’m not sure if this is OK or not. Is there some problem with calling multiple operations on a client, ie will I eventually run out of memory or something?

  • 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-29T07:36:25+00:00Added an answer on May 29, 2026 at 7:36 am

    An operation is typically stateless, so that’s expected behaviour. You can change the InstanceContextMode though. This determines if a new instance is created with each call or that there is a single instance. The question is, should you? Like I said, a single call is typically stateless. Having just a single instance doesn’t scale very well either. I’d suggest to keep InstanceContextMode to be PerCall, that way, for every call the webserver creates a single instance, I wouldn’t worry too much about overhead. If overhead really does become a problem, maybe a service isn’t what you need.

    Then there’s the ConcurrencyMode which allows you to specify multiple threads to be created.

    As far as the client is concerned, you don’t need to re-create it everytime you want to call an operation. Alternatively, you could also look at the ChannelFactory if both client and server have knowledge of the contract. This answer provides some detail.

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

Sidebar

Related Questions

I currently have some code that cycles through a text file looking for a
I'm running some code through FxCop and am currently looking at clearing all of
I am currently looking in to some file uploading using Java Server Faces. I've
We're currently looking into doing some performance tweaking on a website which relies heavily
I currently have some code in Python where I have entered the values from
I have some Ruby code which takes dates on the command line in the
We are currently looking to adopt some type of standard developer framework and have
I'm currently looking for a good (free) tool to do some PL/SQL development on
I'm looking for some information on Routing in MVC with C#. I'm currently very
I'm looking into some XSS prevention in my Java application. I currently have custom

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.