Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

What happened to my first WhoAmiIRequest code?

Posted on by 135

This is my first coding of CRM, I am trying to connect my Microsoft Dynamic 365 for Customer Engagement trial version.

from here: https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/org-service/quick-start-org-service-console-app

static void Main(string[] args)

{

string url = "testtoronto.crm3.dynamics.com/main.aspx";

string userName = "mike@testtoronto.onmicrosoft.com";

string password = "test1234$";

string conn = $@"

Url = {url};

AuthType = Office365;

UserName = {userName};

Password = {password};

RequireNewInstance = True";

using (var svc = new CrmServiceClient(conn))

{

WhoAmIRequest request = new WhoAmIRequest();

WhoAmIResponse response = (WhoAmIResponse)svc.Execute(request); // here is not compiled, "object variable not defined"

Console.WriteLine("Your UserId is {0}", response.UserId);

Console.WriteLine("Press anykey to exit.");

Console.ReadLine();

}

}

Sorry, this is my first CRM coding, Can anybody help me to fix it? much appreciated!

*This post is locked for comments

  • Peter Cong Profile Picture
    Peter Cong 135 on at
    RE: What happened to my first WhoAmiIRequest code?

    [quote user="Goutam Das"]

    Hi ,

    Please have a look below reference . Also you should use below line -

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

    arunpotti.wordpress.com/.../comment-page-1

    [/quote]

    after added this line code:

    xxxxxxxxxxxxx

    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // just added this line code before service call, it works great

    using (var svc = new CrmServiceClient(conn))

    {

    xxxxxxxxxxxxxx

    it works great, thank you so much,

  • Peter Cong Profile Picture
    Peter Cong 135 on at
    RE: What happened to my first WhoAmiIRequest code?

    Actually, I am using .net framework 4.7.1 under Visual Studio 2015.

  • Peter Cong Profile Picture
    Peter Cong 135 on at
    RE: What happened to my first WhoAmiIRequest code?

    [quote user="David Jennaway"]

    Check the LastCrmError or LastCrmException property of the CrmServiceClient - this should give you information about why the connection failed. If you get the error 'An existing connection was forcibly closed by the remote host', then this indicates that you need to use TLS1.2, as per the suggestions above

    [/quote]

    This is the error log of LastCrmError:

    Unable to Login to Dynamics CRM
    Unable to Login to Dynamics CRM************ NullReferenceException - WhoAmI : Execute (WhoAmI) request to CRM from IOrganizationService |=> Object reference not set to an instance of an object.
    Object reference not set to an instance of an object.[TerminalFailure] Failed to Execute Command - WhoAmI : RequestID=b751109c-c482-49f7-987a-7ee37bf6a90a : Execute (WhoAmI) request to CRM from IOrganizationService duration=00:00:00.0052088 ExceptionMessage = Object reference not set to an instance of an object.
    Object reference not set to an instance of an object.

  • Peter Cong Profile Picture
    Peter Cong 135 on at
    RE: What happened to my first WhoAmiIRequest code?

    [quote user="Guido Preite"]

    the url format in your case should be

    testtoronto.crm3.dynamics.com

    I know it's a trial, but if you posted your real password, please edit the message and remove it

    make sure also that there are no syntax errors in the conn variable

    [/quote]

    I changed the url as you mentioned, but unfortunately, I got the same error.

    The error is still on this line: WhoAmIResponse response = (WhoAmIResponse)svc.Execute(request);  //Object reference not set to an instance of an object.

  • David Jennaway Profile Picture
    David Jennaway 14,063 on at
    RE: What happened to my first WhoAmiIRequest code?

    Check the LastCrmError or LastCrmException property of the CrmServiceClient - this should give you information about why the connection failed. If you get the error 'An existing connection was forcibly closed by the remote host', then this indicates that you need to use TLS1.2, as per the suggestions above

  • Verified answer
    Sreevalli Profile Picture
    Sreevalli 3,256 on at
    RE: What happened to my first WhoAmiIRequest code?

    Hi,

    If you are using .net framework 4.5 or below you should enforce the security protocol type to TLS 1.2. so you should add below code line before calling service.

    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

    As a side note, avoid sharing urls, creddentails. always its good to mask :)

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: What happened to my first WhoAmiIRequest code?

    Hi ,

    Please have a look below reference . Also you should use below line -

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

    arunpotti.wordpress.com/.../comment-page-1

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at
    RE: What happened to my first WhoAmiIRequest code?

    the url format in your case should be

    testtoronto.crm3.dynamics.com

    I know it's a trial, but if you posted your real password, please edit the message and remove it

    make sure also that there are no syntax errors in the conn variable

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans