Skip to main content

Notifications

Announcements

No record found.

Customer Service forum

Exception caught:An unsecured or incorrectly secured fault was received from the other party. Inner Exception:System.ServiceModel.FaultException: Authentication Failure

Posted on by Microsoft Employee

Hi,

I am new to Dynamics Environment. I am trying to connect to my Trial Instance of Dynamics 365 from .net Console Application.

I can login with my Username and Password from browser. But I can't login from application.

 private static string GetCrmService(string name)
        {
            IOrganizationService OrganizationService = null;
            try
            {
                ClientCredentials mycredentials = new ClientCredentials();
                mycredentials.UserName.UserName = "My UserName";
                mycredentials.UserName.Password = "My Password";
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                OrganizationService = (IOrganizationService)new OrganizationServiceProxy(new Uri("My Organisation Service Api"), null, mycredentials, null);
                if (OrganizationService != null)
                {
                    Guid userId = ((WhoAmIResponse)OrganizationService.Execute(new WhoAmIRequest())).UserId;
                    if (userId.Equals(Guid.Empty))
                    {
                        Console.WriteLine("Connection can't be established");
                        return userId.ToString();
                    }
                    return "";
                }
                else
                {
                    Console.WriteLine("Connection Established Successfully");
                    return "";
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine("Exception caught:" + ex.Message);
                Console.WriteLine("Inner Exception:" + ex.InnerException+"\nMesssage:"+ex.InnerException.Message);
                return "";
            }
        }

It shows Authentication Error. But I am using same Username and Password for Browser login. That is fine.

Can someone help me out

Categories:
  • Suggested answer
    Scott Moore Profile Picture
    Scott Moore 15 on at
    RE: Exception caught:An unsecured or incorrectly secured fault was received from the other party. Inner Exception:System.ServiceModel.FaultException: Authentication Failure

    We found Azure AD Conditional Access could cause this as well, details in article linked below

    http://teameasi.com/blog/azure-ad-conditional-access-and-dynamics-service-connection-errors

  • Johnny Gong Profile Picture
    Johnny Gong 6,482 on at
    RE: Exception caught:An unsecured or incorrectly secured fault was received from the other party. Inner Exception:System.ServiceModel.FaultException: Authentication Failure

    Hi Sulthan@dev,

    Glad to see the issue fixed. We would be great appreciate if you could help to mark any helpful answer to close this question in the community.

    Have a nice day.

    Regards

    Johnny

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Exception caught:An unsecured or incorrectly secured fault was received from the other party. Inner Exception:System.ServiceModel.FaultException: Authentication Failure

    Hi guys,

    I just figured out problem is not with Dynamics but rather with mail Id I used for trial instance. Its my organization Id and my organization firewall preventing me from accessing application.

    I created a new instance with different Id and its working perfectly.

    Thanks all for your reply. All your responses were very helpful since I am a beginner.

  • Johnny Gong Profile Picture
    Johnny Gong 6,482 on at
    RE: Exception caught:An unsecured or incorrectly secured fault was received from the other party. Inner Exception:System.ServiceModel.FaultException: Authentication Failure

    Hi sulthan,

    It's strange as I could successfully run the above function. I found one old post which shares the similar issue which is due to the incorrect timezone or if same timezone but different 5 min.

    [View:https://community.dynamics.com/crm/f/117/t/204264:750:50]

    You could check the timezone in personal options.

    tz.PNG

    Hope the above would help.

    Regards

    Johnny

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Exception caught:An unsecured or incorrectly secured fault was received from the other party. Inner Exception:System.ServiceModel.FaultException: Authentication Failure

    Hi,

    When you say the user credentials worked fine in browser, did you type in the user credentials or it logged you in automatically (saved password). If you have your credential stored/ saved in browser then browser will let you in even if your credentials I changed for sometime.

    Try inprivate browser to login and confirm if you are able to login. Alternatively you can try login into any of the other tools like plugin registration, Xrm toolbox etc to isolate if the issue is related to credentials or your app. If you are able to login to other tools then it must be something with your app. Try different .net framework in this case.

    If you are unable to login to other tools then it must be your credentials, and you should use correct credentials.

    Hope this helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Exception caught:An unsecured or incorrectly secured fault was received from the other party. Inner Exception:System.ServiceModel.FaultException: Authentication Failure

    Hi Gong,

    Thanks for reply. But that exception still comes.

    When I tried to debug it , I found that this error comes when I try to get Response from execute method.

    Can you please provide any help regarding that?

  • Suggested answer
    Johnny Gong Profile Picture
    Johnny Gong 6,482 on at
    RE: Exception caught:An unsecured or incorrectly secured fault was received from the other party. Inner Exception:System.ServiceModel.FaultException: Authentication Failure

    Hi Partner,

    Your logic is something wrong as 'Connection Established Successfully' is due to userid could be successfully validated.

    In addition, why the connection is built successfully when the OrganizationService = null? The logic is completely in reverse.

    Change the If Logic as follow:

    if (OrganizationService != null)
                    {
                        Guid userId = ((WhoAmIResponse)OrganizationService.Execute(new WhoAmIRequest())).UserId;
                        if (userId != Guid.Empty)
                        {
                            Console.WriteLine("Connection Established Successfully");
                            return userId.ToString();
                        }
                        return "";
                    }
                    else
                    {
                        Console.WriteLine("Failed to Established Connection!!!");
                        return "";
                    }

    tt.PNG

    Then you could successfully access your Organization Service Endpoint Address.

    Hope the above would help.

    Regards

    Johnny

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans