Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Exception while connecting to CRM

Posted on by 50

Hi,

IOrganizationService _service = null;

try

 {

 ClientCredentials clientCredentials = new ClientCredentials();

 clientCredentials.UserName.UserName = "<UserName>@<OrgName>.onmicrosoft.com";

 clientCredentials.UserName.Password = "Password;

_service! = (IOrganizationService)new OrganizationServiceProxy(new Uri("https://<OrgName>.api.crm8.dynamics.com/XRMServices/2011/Organization.svc"),

 null, clientCredentials, null);

if (_service!= null)

 {

 Guid userid = ((WhoAmIResponse)_service.Execute(new WhoAmIRequest())).UserId;

if (userid != Guid.Empty)

 {

 Console.WriteLine("Connection Successful!...");

 }

 }

 else

 {

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

 }

 }

 catch (Exception ex)

 {

 Console.WriteLine("Exception caught - " + ex.Message); 

 }

 Console.ReadKey();

I tried this code to connect to CRM but i'm unable to connect to that and getting this exception.

"An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail"

 Can anyone help me in finding out the reason.

  • Priya_1 Profile Picture
    Priya_1 50 on at
    RE: Exception while connecting to CRM

    Thank you,

    I'll try using this

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Exception while connecting to CRM

    Hello,

    Don't use this approach. It won't work because it's deprecated. My recommendation - start using XrmTooling:

    docs.microsoft.com/.../use-xrm-tooling-execute-actions

    docs.microsoft.com/.../use-connection-strings-xrm-tooling-connect

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans