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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:24:20+00:00 2026-06-06T18:24:20+00:00

I have a WCF service that I am consuming, and have been doing well

  • 0

I have a WCF service that I am consuming, and have been doing well so far.

However on our production system with a lot of traffic, I am noticing that that after gradual consistent rise and falls in memory (time in between gradually elongates and the delta gradually increases), the memory consumption is trending higher.

I’m wondering if it could be due to the way I am consuming the DAL web service:

For example:

    public static int GetUserTypeFromProfileID(int profileID)
    {
        try
        {
            memberServiceClient = new MemberServiceClient();                                // connect to the data service
            return memberServiceClient.GetUserTypeFromProfileID(profileID);                 // get the profileID associated with the sessionID
        }
        catch (Exception ex)
        {
            ErrorLogging.Instance.Fatal(ex);
            return 0;
        }
    }

If I changed this to the following, using a using statement:

    public static int GetProfileIDFromSessionID(string sessionID)
    {
        try
        {
            using (memberServiceClient = new MemberServiceClient())                                // connect to the data service
            {
                return memberServiceClient.GetProfileIDFromSessionID(sessionID);                // get the profileID associated with the sessionID
            }

        }
        catch (Exception ex)
        {
            ErrorLogging.Instance.Fatal(ex);
            return 0;
        }
    }

Is it good form to perform the return inside the using section?

  • 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-06-06T18:24:22+00:00Added an answer on June 6, 2026 at 6:24 pm

    I believe there is nothing specific to WCF with using statement. It will dispose your MemberServiceClient before returning the value.

    However Dispose() method on a WCF service client calls Close() method inside, which can throw exceptions. So it’s better to call Close() method directly. You should also call Abort() method when exceptions occur. Here’s the recommended implementation.

    var result;
    try
    {
        memberServiceClient = new MemberServiceClient();
        result = memberServiceClient.GetUserTypeFromProfileID(profileID);
        memberServiceClient.Close();
    }
    catch (FaultException e)
    {
        //handle exception
        memberServiceClient.Abort();
    }
    catch (CommunicationException e)
    {
        //handle exception
        memberServiceClient.Abort();
    }
    catch (TimeoutException e)
    {
        //handle exception
        memberServiceClient.Abort();
    }
    

    Note: I have written a simple base class that handles these details. It’s on NuGet.

    Update:

    Here’s an example with WcfClientBase as requested:

    public class MemberServiceManager : ServiceClientBase<MemberServiceClient>
    {
        public int GetUserTypeFromProfileID(int profileID)
        {
            //makes a call to GetUserTypeFromProfileID operation, closes the channel and handles the exceptions
            //you may want to implement another base class for overriding exception handling methods
            //return value will be default of return type if any exceptions occur
            return PerformServiceOperation(item => item.GetUserTypeFromProfileID(profileID));
        }
    
        //or you can manually check if any exceptions occured with this overload
        public bool TryGetUserTypeFromProfileID(int profileID, out int userType)
        {
            return TryPerformServiceOperation(item => item.GetUserTypeFromProfileID(profileID), out userType);
        }
    
    
        //these exception handling methods should be overriden in another common subclass
        //they re-throw exceptions by default
        protected override void HandleCommunicationException(CommunicationException exception)
        {
            Console.WriteLine(exception.Message);
        }
    
        protected override void HandleFaultException(FaultException exception)
        {
            Console.WriteLine(exception.Message);
        }
    
        protected override void HandleTimeoutException(TimeoutException exception)
        {
            Console.WriteLine(exception.Message);
        }
    
    }
    

    You can also take a look at the source code on GitHub

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

Sidebar

Related Questions

I have a WCF web service using wsHttpBinding that I am consuming from a
I have a WCF service that has been working perfectly, and something has changed
I have a WCF service that stores and processes images. Consuming applications can download
We have a simple desktop app consuming a WCF Service. Sometime we upgrade our
I have a Silverlight 2 application that is consuming a WCF service. As such,
I have a WCF service that accesses a SQL database to fetch data .
I have a WCF service that I need to call in a ASP.NET web
I have a WCF service that I can debug. I put a breakpoint in
I have a WCF service that can return large amount of data depending on
I have a WCF service that needs to hosted using basicHttpBinding using SSL. So

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.