Bhubaneswar, Odisha, India
+91-8328865778
support@softchief.com

An error occurred when processing the security tokens in the message:You are using Ws-Tust authentication which has been deprecated and no longer supported in your environment. Please use oAuth2.0 authentication in Dynamics 365 / CDS – Console App

An error occurred when processing the security tokens in the message:You are using Ws-Tust authentication which has been deprecated and no longer supported in your environment. Please use oAuth2.0 authentication in Dynamics 365 / CDS – Console App

If you are facing error while connecting Dynamics 365 from Console Application then use OAuth to connect using below code. update your code as per below.

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Tooling.Connector;
using System;

namespace MFACRUDD365
{
    class Program
    {
        static void Main(string[] args)
        {
            string authType = "OAuth";
            string userName = "XXX@XXX.onmicrosoft.com";
            string password = "XXX@XXX";
            string url = "https://XXX.crm.dynamics.com";
            string appId = "51f81489-12ee-4a9e-aaae-a2591f45987d";
            string reDirectURI = "app://58145B91-0C36-4500-8554-080854F2AC97";
            string loginPrompt = "Auto";
            string ConnectionString = string.Format("AuthType = {0};Username = {1};Password = {2}; Url = {3}; AppId={4}; RedirectUri={5};LoginPrompt={6}",
                                                    authType,userName,password,url,appId,reDirectURI,loginPrompt);

            CrmServiceClient svc = new CrmServiceClient(ConnectionString);

            if (svc.IsReady)
            {
                PerformCRUD(svc);
            }
        }

        private static void PerformCRUD(CrmServiceClient svc)
        {
            //CREATE
            var myContact = new Entity("contact");
            myContact.Attributes["lastname"] = "Sample";
            myContact.Attributes["firstname"] = "Contact";
            Guid RecordID = svc.Create(myContact);
            Console.WriteLine("Contact created...");


            //RETRIEVE
            Console.WriteLine("Retrieving Contact...");
            Entity contact = svc.Retrieve("contact", RecordID, new ColumnSet("firstname", "lastname"));
            Console.WriteLine("Contact First Name:"+ contact["firstname"]);

            //UPDATE
            Console.WriteLine("Updating Contact...");
            Entity entContact = new Entity("contact");
            entContact.Id = RecordID;
            entContact.Attributes["lastname"] = "Sample New";
            svc.Update(entContact);
            Console.WriteLine("Contact updated");

            //DELETE
            Console.WriteLine("Contact Deleting");
            svc.Delete("contact", RecordID);
            Console.WriteLine("Contact Deleted");
            Console.ReadLine();
        }
    }
}
You can enroll now !We are giving 30% discount on our Internship Program

Don’t miss the chance to participate in the upcoming Internship Program which will be done using Microsoft Dot Net Web Development Full Stack Technology. The new batch will be starting from May 20, 2024.  We will have most experienced trainers for you to successfully complete the internship with live project experience.

Why to choose Our Internship Program?

Industry-Relevant Projects
Tailored Assignments: We offer projects that align with your academic background and career aspirations.
Real-World Challenges: Tackle industry-specific problems and contribute to meaningful projects that make a difference.

Professional Mentorship
Guidance from Experts: Benefit from one-on-one mentorship from seasoned professionals in your field.
Career Development Workshops: Participate in workshops that focus on resume building, interview skills, and career planning.

Networking Opportunities
Connect with Industry Leaders: Build relationships with professionals and expand your professional network.
Peer Interaction: Collaborate with fellow interns and exchange ideas, fostering a supportive and collaborative environment.

Skill Enhancement
Hands-On Experience: Gain practical skills and learn new technologies through project-based learning.
Soft Skills Development: Enhance communication, teamwork, and problem-solving skills essential for career success.

Free Demo Class Available