web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

How to Re-Authenticating connection using a new CrmServiceClient?

(0) ShareShare
ReportReport
Posted on by 5
I am using the latest version of Microsoft.CrmSdk.XrmTooling.CoreAssembly.9.1.0.108
My service use multiple Dynamics 365 users, so I cached a CrmServiceClient instance for every user.

But I can't find a proper way how to update a token when it has expired.

OrganizationService.CheckIfTokenIsExpired  is deprecated.

This is my connection cache code
        private static readonly Dictionary _crmClientCache = new Dictionary();

        private static readonly Object _orgServiceLock = new Object();

        private static readonly string _authType = "OAuth";
        private static readonly string _requireNewInstance = "true";
        private static readonly string _appId = "51f81489-12ee-4a9e-aaae-a2591f45987d";
        private static readonly string _reDirectURI = "app://58145B91-0C36-4500-8554-080854F2AC97";


        public static CrmServiceClient GetCrmClient(string userName, string password, string url)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            string ConnectionString = string.Format("AuthType={0};Username={1};Password={2};Url={3};AppId={4};RedirectUri={5};RequireNewInstance={6};",
            _authType, userName, password, url, _appId, _reDirectURI, _requireNewInstance);

            CrmServiceClient crmClient;

            lock (_orgServiceLock)
            {
                if (!_crmClientCache.ContainsKey(ConnectionString))
                {
                    crmClient = new CrmServiceClient(ConnectionString);
                    _crmClientCache.Add(ConnectionString, crmClient);
                }
            }

            crmClient = _crmClientCache[ConnectionString];

            if (crmClient.IsReady)
            {
                return crmClient;
            }
            throw new Exception(crmClient.LastCrmError);
        }
Thanks for help!
I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 202 Super User 2026 Season 1

#2
CU11031447-0 Profile Picture

CU11031447-0 100

#3
NeerajPawar Profile Picture

NeerajPawar 70

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans