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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

still possible to write command line utilities w/SDK?

(0) ShareShare
ReportReport
Posted on by 1,030

Downloaded https://code.msdn.microsoft.com/Sample-Quick-start-for-650dbcaa/view/Discussions#content

Using NuGet packages for reference assemblies

  • .Crm.Sdk.Proxy & .Xrm.Sdk                                   9.0.0.0
  • .Xrm.Sdk.Deployment & .Xrm.Sdk.Workflow        8.0.0.0
  • .Xrm.Tooling.Connector                                        2.0.0.0
  • it compiles

Verified it is a .NET framework 4.6.2 project 

Modified app.config for the QuickStart with Simplified Connection with my info for name & connectionstring (Online using Office 365 formats)

Did nothing else...  This is a current Online installation v 9.1.0.2450

I cannot connect.  Can anyone tell me what is wrong here or a better sample to start with?

CrmServiceClient conn = new Xrm.Tooling.Connector.CrmServiceClient(connectionString);

======================================
Inner Exception Level 1 :
Source  : Not Provided
Method  : Not Provided
Date    : 3/7/2019
Time    : 9:28:14 AM
Error   : Authentication Failure
Stack Trace     : Not Provided
======================================

Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : Unable to Login to Dynamics CRM
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : OrganizationWebProxyClient is null
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : OrganizationServiceProxy is null
The application terminated with an error.
Object reference not set to an instance of an object.
Press <Enter> to exit.

thank you!

*This post is locked for comments

I have the same question (0)
  • Rawish Kumar Profile Picture
    13,758 on at

    Hi Martin,

    Use this code of line before initialisation of the connection :

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

  • Martin Donnelly Profile Picture
    1,030 on at

    I kicked up the Tooling.Connector to 3.0.0.0 and added that line.

    No joy.  No difference.

  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    pay attention to the nuget package version of ADAL (Microsoft.IdentityModel.Clients.ActiveDirectory) I normally use the 2.29 version, all the other packages you can update to the latest version. Personally I just add this one as first

    www.nuget.org/.../Microsoft.CrmSdk.XrmTooling.CoreAssembly

  • Martin Donnelly Profile Picture
    1,030 on at

    Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : Invalid Login Information : An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.

    Both ADAL 2.29.0 and 4.5.1

  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    start with an empty console project, load the nuget package I mentioned and update all the others except ADAL (or up to 2.29)

    after in your code write directly a:

    CrmServiceClient service = new CrmServiceClient("Url=https://XXX.crmX.dynamics.com; Username=XXX@XXX.onmicrosoft.com; Password=XXX; AuthType=Office365");

    WhoAmIResponse whoAmIResponse = (WhoAmIResponse)service.Execute(new WhoAmIRequest());

    check if works and see what whoAmIResponse contains.

  • Suggested answer
    Kokulan Profile Picture
    18,054 on at

    Hi

    I use CrmServiceClient a lot in my console and other windows applications.  I found the following way of connecting seem very stable and have no issues

    Microsoft.Xrm.Tooling.Connector.CrmServiceClient CrmService = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(

                       "Your office 365 Login - Email / Username",

                       Microsoft.Xrm.Tooling.Connector.CrmServiceClient.MakeSecureString("password"),

                       "", "unique org id -> you can get it from Settings -> Customizations -> Developer Resources  -> Unique Name",

                       useUniqueInstance: true,

                       useSsl: true, isOffice365: true);

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

    var results = (WhoAmIResponse) CrmService.Execute(new WhoAmIRequest());

    if (results.Results.Any())

                   {

                       Console.WriteLine("Successfully connected to CRM");

                       Console.WriteLine($"Your user id is : {results.UserId}");

                   }

                   else

                   {

                       Console.WriteLine("The Connetion was not successful");

                   }

    I have pushed my connection code to Github and feel free to download and use this

    My github repo : https://github.com/Kokulan365/CRMServiceClientQuickStart 

    Note: Project target is .NET 4.6, you can change the target version but then you will have to update the nuget packages and find the correct matching version of the following package

    Microsoft.CrmSdk.XrmTooling.CoreAssembly : www.nuget.org/.../Microsoft.CrmSdk.XrmTooling.CoreAssembly

    Hope this helps

  • Martin Donnelly Profile Picture
    1,030 on at

    You guys are the greatest.

    I tried Kokulan's project with both ADAL 2.22 and 2.29, both Unique Name & instance GUID and the Tls12 above and below call to the connector.

    ------------"Unable to Login to Dynamics CRM"

    Then I commented out the call and went with the signature in Guido's constructor.

    ------------"Unable to Login to Dynamics CRM"

    Let me add some other detail because this reminds me of problems with 2013 on-premise when the HomeRealmUrl wasn't being set.  When I log in manually, I am challenged for the password at the company's ADFS dialog AND by second factor authentication.  I don't see how these methods are handling that -- just wondering if that might be the concern.

    thanks so much for helping

    PS- also, my username is not of onmicrosoft.com.  It is in the company's domain.

  • Verified answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    the 2FA is an important information you missed.

    The easiest way is to create an application password, you can find the procedure in this post:

    d365demystified.com/.../use-azure-app-passwords-for-mfa-enabled-d365-authentication-from-console-app

    regarding the username, of course you need to use your username with the company domain if that is configured and not the onmicrosoft.com

  • Martin Donnelly Profile Picture
    1,030 on at

    No luck.

    thanks again.

  • Verified answer
    Kokulan Profile Picture
    18,054 on at

    You could ask your sys admin to switch off two-factor authentication for the account you are using to connect to CRM.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans