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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:17:52+00:00 2026-05-20T10:17:52+00:00

In a WCF client application, there are a number of parameterless methods for which

  • 0

In a WCF client application, there are a number of parameterless methods for which we’d like to cache the results – GetAllFoo() , GetAllBar(). These are used to populate dropdowns and the like, and the results don’t change during the running life of the client.

These results are currently being cached by a unique string stored in a Resource file – for example, GetAllCountries() is cached against the CountryKey Resource. The service is only called when the cache doesn’t contain the requested key.

public T Get<T, V>(string key, Func<V, T> serviceCall, V proxy)
{
    if (!cache.Contains(key))
    {
        cache.Add(key, serviceCall(proxy));
    }   
    return cache.GetData(key) as T;
}

This is fine except we need to maintain the keys in the Resource file, and need to make sure that every method uses the correct cache key otherwise things break. The old Control+C, Control+V causes a few headaches here and I don’t want to have to go check every place that calls this method.

So the question:

The serviceCall delegate has a Method property on it which describes the method to execute. This is a MethodInfo instance, which in turn contains a MethodHandle property. Am I right in assuming that the MethodHandle property uniquely and consistently identifies the method that is referenced?

I’d change the wrapper to

public T Get<T, V>(Func<V, T> serviceCall, V proxy)
{
    var key = serviceCall.Method.MethodHandle;
    // etc

which properly encapsulates the caching and key concerns, & removes any dependency on the caller ‘doing the right thing’.

  • Don’t care if the MethodHandle changes between instances – the caching is only per instance
  • Don’t care if the MethodHandle is not consistent across clients – caching is per client
  • DO care if the MethodHandle is not consistent within an instance on a client – I actually want the cache to be used, rather than every request resulting in a new service call and the cache being full of unused data
  • DO care if the MethodHandle is not unique within an instance on a client – I have to be sure that the correct data (and type) is returned when the wrapper is used.
  • 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-20T10:17:53+00:00Added an answer on May 20, 2026 at 10:17 am

    MSDN, referring to the MethodHandle property, says “this property is for access to managed classes from unmanaged code and should not be called from managed code.”

    http://msdn.microsoft.com/en-us/library/system.runtime.interopservices._methodbase.methodhandle.aspx

    Suggestions:

    • Use serviceCall.Method.MethodHandle anyway since it is supposed to be unique within the same AppDomain.
    • Research serviceCall.Method.GetHashCode() to see if this would work for you as your caching key.
    • Change your caching mechanism to be a Dictionary, T> and use serviceCall as the actual caching key. (This may not work depending on how you’re code is calling the wrapper method.)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a class that determines which of number of registered WCF client
I have a client/server style application which communicates using WCF which all works great.
I have client application that uses WCF service to insert some data to backend
I will have a client application using a proxy to a WCF Service. This
WCF uses http://tempuri/1/number for Content-ID uri references when handling streamed MTOM requests. Is there
I am working on a WCF application with a server and a client (naturally).
I am developing an application which includes a WCF service and its ASP.NET MVC
Say I have a simple WCF application that the client calls in order to
I'm developing a .NET 2.0 client application that needs to connect to a WCF
I've an application using WCF on client and server side. I get errors when

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.