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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:47:12+00:00 2026-05-12T16:47:12+00:00

This is my first attempt to use WCF so there may be something fundamentally

  • 0

This is my first attempt to use WCF so there may be something fundamentally wrong with this approach – if so I’m happy to switch to a different model. At quick glance, I thought the answer to this question would have worked, but my scenario appears to be different.

I have an ASP.NET MVC website where the controllers access the WCF client class through an intermediate repository. The repository is just a wrapper around the WCF client that instantiates it once and sets the proper endpoint address.

public class WcfRepository : IRepository
{
    private MyWCFServiceClient client;

    public WcfRepository()
    {
        client = new MyWCFServiceClient();
    }

    public bool MyMethod1()
    {
         return client.MyMethod1();
    }

    ... etc       
}

I can access different pages on the website until a seemingly random point where the WCF service will start timing out. It doesn’t matter which method I call either – it timesout on different ones. I cannot see any exceptions on the IIS machine hosting the WCF service either; the event log there is empty. A simple method like GetCustomerByName() which worked two minutes earlier will no longer so I think it’s more to do with WCF communication rather than the service itself.

If I try to use the WCF Test Client after one of these timeouts occurs, it will also fail. But, if I wait a while (and choose ‘start a new proxy’) then things will work again.

I’m very confused – should I be creating a new instance of the WCF client each time I want to use it in my repository? Is there another way I should be using the client? Wrapping each call in Open()/Close() doesn’t work either since the first call to Close() puts the object in a disposed state.

  • 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-12T16:47:12+00:00Added an answer on May 12, 2026 at 4:47 pm

    When you are done with your WCF client, you must explicitly close it because it will otherwise keep a ‘connection’ open to the service, and there’s a (configurable) limit to how many concurrent connection you can have.

    Although it is possible to tweak that limit, the correct solution is to create a new WCF client, invoke one or more methods on it and close it again when you are done. This is considered best practice, and should neatly avoid the sort of problems you are currently experiencing.

    This means that your implementation should rather go something like this:

    public class WcfRepository : IRepository
    {
        public bool MyMethod1()
        {
             var client = new MyWCFServiceClient();
             try
             {
                 return client.MyMethod1();
             }
             finally
             {
                 try
                 {
                     client.Close();
                 }
                 catch(CommunicationException)
                 {
                     // handle exception here
                 }
                 catch(TimeoutException)
                 {
                     // handle exception here
                 }
    
             }
        }
    
        ... etc       
    }
    

    Notice the nasty try/finally construct, which is necessary because Close may throw. Read more about this here.

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

Sidebar

Related Questions

this is my first question to stackoverflow so here it goes... I use cruise
problem euler #5 i found the solution but i don't know why this first
This is my first post here and I wanted to get some input from
This is my first experience using the Zend Framework. I am attempting to follow
This is my first time attempting to call an ASP.NET page method from jQuery.
this is my first question here so I hope I can articulate it well
This is my first time using joomla. I don't know if I'm using the
This is my first crack at a method that is run periodically during the
This is my first time with Web services. I have to develop web services
This is my first post and I'm quite a novice on C++ and compiling

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.