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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:48:57+00:00 2026-05-18T01:48:57+00:00

I have a WCF Service that requires a security token issued by a separate

  • 0

I have a WCF Service that requires a security token issued by a separate WCF STS Service. This all works just dandy. In my application, I use the service like so:

MyServiceClient myService = new MyServiceClient();
myService.Open();
myService.DoStuff();

The STS Service is called to get a token and the token is used to call the service method DoStuff.

Once the initial handshake is over, though, the myService object has the token cached and re-uses it until it expires. This is fine behavior and all, but how would I force it to refresh the token?

myService.ClientCredentials.Invalidate(); // something like this?

Such that if I called DoStuff() again it would know it needs to go to the STS again much as it did the first time.

Am I stuck just making a new proxy class object, i.e. myService = new MyServiceClient();? This works but it seems like the nuclear bomb solution.

Alternatively, is there a way to just manually get a new token and replace the current one, i.e. myService.ClientCredentials.Renew();?

If I have to make a custom ClientCredentials class to do this, how would I implement the above example methods?

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

    In my codebase, we actually cache the token so we ensure that we don’t make repeated calls to the STS. Using the same method, you could definitely alter it manually request another token whenever you wish. Here’s how to hook into ClientCredentials:

    public class CustomClientCredentials : ClientCredentials
    {
        public CustomClientCredentials()
        {
        }
    
        protected CustomClientCredentials(ClientCredentials other)
            : base(other)
        {
        }
    
        protected override ClientCredentials CloneCore()
        {
            return new CustomClientCredentials(this);
        }
    
        /// <summary>
        /// Returns a custom security token manager
        /// </summary>
        /// <returns></returns>
        public override  SecurityTokenManager CreateSecurityTokenManager()
        {
            return new CustomClientCredentialsSecurityTokenManager(this);
        }
    }
    
    
    public class CustomClientCredentialsSecurityTokenManager : ClientCredentialsSecurityTokenManager
    {
        public CustomClientCredentialsSecurityTokenManager(ClientCredentials credentials)
            : base(credentials)
        {
        }
    
        /// <summary>
        /// Returns a custom token provider when a issued token is required
        /// </summary>
        public override SecurityTokenProvider CreateSecurityTokenProvider(SecurityTokenRequirement tokenRequirement)
        {
            if (IsIssuedSecurityTokenRequirement(tokenRequirement))
            {
                // Adds the endpoint behaviors for calling the issuer
                IssuedSecurityTokenProvider baseProvider = (IssuedSecurityTokenProvider)base.CreateSecurityTokenProvider(tokenRequirement);
    
                CustomIssuedSecurityTokenProvider provider = new CustomIssuedSecurityTokenProvider(baseProvider);
                return provider;
            }
            return base.CreateSecurityTokenProvider(tokenRequirement);
        }
    }
    
    
    public class CustomIssuedSecurityTokenProvider : IssuedSecurityTokenProvider
    {
        private readonly IssuedSecurityTokenProvider _innerProvider;
    
        public CustomIssuedSecurityTokenProvider(IssuedSecurityTokenProvider innerProvider)
        {
            _innerProvider = innerProvider;
            CacheIssuedTokens = innerProvider.CacheIssuedTokens;
            IdentityVerifier = innerProvider.IdentityVerifier;
            IssuedTokenRenewalThresholdPercentage = innerProvider.IssuedTokenRenewalThresholdPercentage;
            IssuerAddress = innerProvider.IssuerAddress;
            IssuerBinding = innerProvider.IssuerBinding;
            innerProvider.IssuerChannelBehaviors.ForEach(IssuerChannelBehaviors.Add);
            KeyEntropyMode = innerProvider.KeyEntropyMode;
            MaxIssuedTokenCachingTime = innerProvider.MaxIssuedTokenCachingTime;
            MessageSecurityVersion = innerProvider.MessageSecurityVersion;
            SecurityAlgorithmSuite = innerProvider.SecurityAlgorithmSuite;
            SecurityTokenSerializer = innerProvider.SecurityTokenSerializer;
            TargetAddress = innerProvider.TargetAddress;
            innerProvider.TokenRequestParameters.ForEach(TokenRequestParameters.Add);
    
            _innerProvider.Open();
        }
    
        ~CustomIssuedSecurityTokenProvider()
        {
            _innerProvider.Close();
        }
    
        protected override SecurityToken GetTokenCore(TimeSpan timeout)
        {
            // We're ignoring the CacheIssuedTokens property in order to force an STS call
            var securityToken = _innerProvider.GetToken(timeout);
            return securityToken;
        }
    }
    

    The GetTokenCore() method is where the STS gets called. When you call GetToken(), the STS will be asked to issue another token.

    From your question, I assume you know how to hook into your ClientCredentials from the app.config.

    There might be a way of setting the CacheIssuedTokens property in the App.config file, I’m just not sure of a way off the top of my head.

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

Sidebar

Related Questions

I have a WCF service that works ok if I create the service without
I have a WCF web service that works perfectly with an http address, but
I have a WCF service that requires some DateTime parameters to be passed in.
I have a WCF service that is exposed. In terms of security i need
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
I have a WCF service that I am consuming, and have been doing well

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.