Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Console app for MS Dynamics CRM

Posted on by Microsoft Employee

I am using late binding to  connect to MS CRM using console application. My program.cs file looks like this

class Program
{
private static OrganizationServiceProxy _serviceProxy;
private static ClientCredentials _clientCreds;


static void Main(string[] args)
{
// Setup credential
_clientCreds = new ClientCredentials();
_clientCreds.Windows.ClientCredential.UserName = "userName";
_clientCreds.Windows.ClientCredential.Password = "Password";
_clientCreds.Windows.ClientCredential.Domain = "Domain";

Uri URL = new Uri("servername/.../Organization.svc");
// Connect to Crm WCF endpoint
using (_serviceProxy = new OrganizationServiceProxy(URL, null, _clientCreds, null))
{
OrganizationServiceContext orgContext = new OrganizationServiceContext(_serviceProxy);

WhoAmIRequest request = new WhoAmIRequest();
WhoAmIResponse response = (WhoAmIResponse)orgContext.Execute(request);
Console.WriteLine("Your Crm user Guid is {0}", , response.UserId);
Console.Read();

Can someone help me on what should I put in my app.config file. Everytime I run the program it gives me below error:

The type initializer for 'System.ServiceModel.Diagnostics.TraceUtility' threw an exception.

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Console app for MS Dynamics CRM

    Thanks a lot Guido. It worked!

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Console app for MS Dynamics CRM

    so can I delete the app.config file? Also, how to pass user name password in case of on premise?

    Thank you!

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Console app for MS Dynamics CRM

    Thanks Guido! What changes I need to make in app.config file?

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

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

Featured topics

Product updates

Dynamics 365 release plans