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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Console app for MS Dynamics CRM

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Community Member Profile Picture
    on at

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

  • Community Member Profile Picture
    on at

    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
    on at

    Thanks a lot Guido. It worked!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
AS-17030037-0 Profile Picture

AS-17030037-0 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans