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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:45:02+00:00 2026-05-26T06:45:02+00:00

This answer was posted in response to this question . It’s a little above

  • 0

This answer was posted in response to this question.

It’s a little above my head right now, but is the “higher order function” supposed to be used within a client proxy class? Is this correct usage?:

public class MyProxy
{
    readonly IMyService service =
        new ChannelFactory<IMyService>("IMyService").CreateChannel();

    public ResponseObject Foo(RequestObject request)
    {
        return UseService((IMyService service) =>
            service.Bar(request));
    }

    T UseService<T>(Func<IIssueTrackerService, T> code)
    {
        bool error = true;

        try
        {
            T result = code(issueTrackerChannel);
            ((IClientChannel)issueTrackerChannel).Close();
            error = false;
            return result;
        }
        finally
        {
            if (error)
            {
                ((IClientChannel)issueTrackerChannel).Abort();
            }
        }
    } 
}

All I’m really looking for is some guidance here, and the correct way to do this.

  • 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-26T06:45:02+00:00Added an answer on May 26, 2026 at 6:45 am

    This is actually not to bad. Perhaps you can cast to an ICommunicationObject instead, as the same code is required for your hosts as well.

    The way to think about it is close is the friendly call. Please finish my call and return the proxy to the connection pool. Abort is “I don’t care, shut the proxy because it’s dead and also remove it from the pool because it’s dead”.

    Depending on your code, you might want to abstract the “WCF Proxy” parts of the code from the function call parts if it’s possible. That way you can unit test your application logic separately from the WCF proxy code.

    You may want to look at a try {} catch (CommunicationException) so you can treat your WCF exceptions separately to an application level exception too, instead of the finally.

    i.e

    try 
    {
        try 
        {
            proxy.call();
            //app logic
    
            ((ICommunicationObject)proxy).Close();
        } 
        catch (SomeAppException)
        {
        //recover app exception
        }
    }
    catch (CommunicationException) 
    {
        ((ICommunicationObject)proxy).Abort();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been posted before... but I haven't found any answer
This question was posted on some site. I didnt find right answers there, so
I have a question about this question . I posted a reply there but
i searched a lot for an answer to this question but i did not
I posted this question on the MSDN forums, but my experience has been a
As demonstrated in this answer I recently posted, I seem to be confused about
I am sure that the answer to this has been posted before. Forgive me
In this answer to this question , Lachlan-Hunt writes the following: With HTML5, you
I know that I was already posted similar question but I just can't find
Recently I posted a answer to a question that I thought was quite an

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.