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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

i'm getting the error as below for an console app as" An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail."

(1) ShareShare
ReportReport
Posted on by 10

IOrganizationService organizationService = null;
try
{
ClientCredentials clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = "......onmicrosoft.com";
clientCredentials.UserName.Password = "password";
// For Dynamics 365 Customer Engagement V9.X, set Security Protocol as TLS12
// ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

organizationService = (IOrganizationService)new OrganizationServiceProxy(new Uri("">-------.api.crm8.dynamics.com/.../Organization.svc"),
null, clientCredentials, null);
if (organizationService != null)
{
// Guid userid = ((WhoAmIResponse)organizationService.Execute(new WhoAmIRequest())).OrganizationId;
Guid userid = ((WhoAmIResponse)organizationService.Execute(new WhoAmIRequest())).UserId;

if (userid != Guid.Empty)
{
Console.WriteLine("Connection Successful!...");
}

}
else
{
Console.WriteLine("Failed to Established Connection!!!");
}

I have the same question (0)
  • cmrtest1 Profile Picture
    10 on at

    can anyone helpme here?

  • Verified answer
    meelamri Profile Picture
    13,218 User Group Leader on at

    Hi, 

    Use of the WS-Trust authentication security protocol when connecting to Microsoft Dataverse is no longer recommended and has been deprecated.  You need to switch over to using an OAuth based connection string. Please refer to the sample code below: 

    using Microsoft.Crm.Sdk.Messages;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Query;
    using Microsoft.Xrm.Tooling.Connector;
    using System;
    
    namespace Dynamics365ConsoleApp
    {
        class Program
        {
            static void Main(string[] args)
            {
                CrmServiceClient crmSvc = getOrganizationService();
                Console.ReadLine();
               
            }
    
            public static CrmServiceClient getOrganizationService()
            {
                CrmServiceClient crmSvc = null;
                String connString = "AuthType=OAuth;Username=xxxx@xxxx.onmicrosoft.com;Password=xxxxxx;Url=https://xxxxxx.crm4.dynamics.com;AppId=51f81489-12ee-4a9e-aaae-a2591f45987d;RedirectUri=app://58145B91-0C36-4500-8554-080854F2AC97;TokenCacheStorePath=c:\\MyTokenCache;LoginPrompt=Auto";
                try
                {
                    crmSvc = new CrmServiceClient(connString);
                    if (crmSvc != null)
                    {
                        var whoAmIResponse = ((WhoAmIResponse)crmSvc.Execute(new WhoAmIRequest()));
                        if (whoAmIResponse != null)
                        {
                            Console.WriteLine("Connection OK....");
                            Console.WriteLine(whoAmIResponse.UserId);
    
                        }
                        else
                        {
                            Console.WriteLine("Connection KO....");
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("ERROR...");
                    Console.WriteLine(e.Message);
                }
                return crmSvc;
            }
        }
    }
    

    Please note: The AppId and RedirectUri provided above are examples of working application registration values. These values work everywhere online services are deployed. However, they are provided here as examples and you are encouraged to create your own application registration in Azure Active Directory (AAD) for applications running in your tenant.

    Documentation: https://docs.microsoft.com/en-us/powerapps/developer/data-platform/authenticate-office365-deprecation

  • cmrtest1 Profile Picture
    10 on at

    tq so much,@Mehdi

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Nagaraju_Matta Profile Picture

Nagaraju_Matta 123

#2
Hamza H Profile Picture

Hamza H 96 Super User 2026 Season 1

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 66 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans