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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:34:56+00:00 2026-05-26T01:34:56+00:00

Having a WCF service and a Consumer I’m not really sure how to handle

  • 0

Having a WCF service and a Consumer I’m not really sure how to handle the Open and Close methods and the lifetime of my Client.

I created the client myself extending and implementing ClientBase and IMyService. Let’s call it MyServiceClient

One place I use it for example is MembershipProvider. So I gave MembershipProvider a MyClient as member variable.

I would like to have it instanced once in the MembershipProvider (via IoC container) and then perhaps do a Open and Close call inside every method call in the client.

    public bool ValidateUser(string username, string password)
    {
        this.Open();
        bool b = Channel.ValidateUser(username, password);
        this.Close();
        return b;
    }

Is this the right way to go about it. I don’t really understand what’s really happening when open/close is called and how having one instance of client affects the service (if at all).

  • 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-26T01:34:57+00:00Added an answer on May 26, 2026 at 1:34 am

    One of the problems with using a single client (WCF proxy) instance is that when a fault occurs the proxy enters a faulted state, and it cannot be reused or Dispose-d, only Abort-ed and created anew. On the other hand, if you use/require Sessions on the service side you need the same proxy instance across multiple calls.

    In any case, if you would like to use proxy now and worry about transport, sessions or faults later I suggest a wrapper like this that I use for my WCF proxies:

    TResult ExecuteServiceMethod<TResult>(Func<MyService, TResult> method)
    {
        var proxy = new MyService(); //...Or reuse an existing if not faulted
        try
        {        
            return method(proxy);
        }
        catch(Exception e)
        {
            //...Handle exceptions
        }
        finally
        {
            //...Per-call cleanup, for example proxy.Abort() if faulted...
        }
    }
    

    and you call your service methods like this:

    var result = ExecuteServiceMethod((MyService s) => s.VerifyUser(username, password));
    

    Replace MyService with your actual client type. This way you can later change your opening/closing/reusing strategy, add logging, etc. for all service calls by adding code before or after the line return method(client).

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

Sidebar

Related Questions

Perhaps I'm overlooking something, but can client WCF not handle a server response that
What are the pro / cons to having the client consume a WCF service
Having successfully got a WCF service and client to talk to one another using
I am having a WCF service secured by X509, a client and they are
I'm having a simple WCF service, deployed to IIS. I used simplified configuration with
Since i am new to WCF and Having configured a WCF service endpoint in
I am having a minor problem with WCF service proxies where the message contains
Hi All I am currently having an issue calling a WCF service from a
I'm wanting to get a WCF-over-TCP service working. I was having some problems with
I'm having a problem with a .NET WCF client connecting to a Java web

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.