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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:43:32+00:00 2026-05-13T08:43:32+00:00

When a single ClientBase<T> instance is used for multiple WCF service calls, it can

  • 0

When a single ClientBase<T> instance is used for multiple WCF service calls, it can get a channel into a faulted state (ie. when the service is down).

I would like to heal the channel automatically when the service comes up again. The only way I found is to call the following code before each method call:

if (clientBase.InnerChannel.State == CommunicationState.Faulted)
{
      clientBase.Abort();
      ((IDisposable)clientBase).Dispose();
      clientBase = new SampleServiceClientBase();
}

I got the feeling that this isn’t the right way to do it. Anyone got a better idea?

  • 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-13T08:43:32+00:00Added an answer on May 13, 2026 at 8:43 am

    You can’t. Once a channel is faulted, it’s faulted for good. You must create a new channel. WCF channels are stateful (in a manner of speaking), so a faulted channel means the state may be corrupted.

    What you can do is put the logic you’re using into a utility method:

    public static class Service<T> where T : class, ICommunicationObject, new()
    {
        public static void AutoRepair(ref T co)
        {
            AutoRepair(ref co, () => new T());
        }
    
        public static void AutoRepair(ref T co, Func<T> createMethod)
        {
            if ((co != null) && (co.State == CommunicationState.Faulted))
            {
                co.Abort();
                co = null;
            }
            if (co == null)
            {
                co = createMethod();
            }
        }
    }
    

    Then you can invoke your service with the following:

    Service<SampleServiceClient>.AutoRepair(ref service,
        () => new SampleServiceClient(someParameter));
    service.SomeMethod();
    

    Or if you want to use the default parameterless constructor, just:

    Service<SampleServiceClient>.AutoRepair(ref service);
    service.SomeMethod();
    

    Since it also handles the case where the service is null, you don’t need to initialize the service before calling it.

    Pretty much the best I can offer. Maybe somebody else has a better way.

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

Sidebar

Related Questions

A single Biztalk Server can have multiple Host processes. Is it possible to create
Given the URL (single line): http://test.example.com/dir/subdir/file.html How can I extract the following parts using
I'm a single developer looking to get off of Visual Source Safe and move
I load a single instance of a window on php-gtk, I have a button
I want a single generic class that can accept either reference or value types,
I need to implement single sign-on in my java web application which can achieve
What single aspect of agile development should we implement first to improve our development
What is the single most effective practice to prevent arithmetic overflow and underflow ?
How to match a single quote in sed if the expression is enclosed in
Trying to perform a single boolean NOT operation, it appears that under MS SQL

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.