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 :

Initializing and setting DefaultCrendentials for OrganizationService in CRM 2011

Nishant Rana Profile Picture Nishant Rana 11,325 Microsoft Employee

I created a simple windows application just to see how to make use of IOrganizationService within CRM 2011.

Here we need to add references to the following dlls

  1. Microsoft.Xrm.Sdk.
  2. System.ServiceModel.
  3. System.Runtime.Serialization.

This is the sample code

Uri organizationUri = new Uri("http://crmservername/orgname/XRMServices/2011/Organization.svc");
Uri homeRealmUri = null;
ClientCredentials credentials = new ClientCredentials();
// set default credentials for OrganizationService
credentials.Windows.ClientCredential = (NetworkCredential)CredentialCache.DefaultCredentials;
// or
credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
OrganizationServiceProxy orgProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, null);
IOrganizationService _service = (IOrganizationService)orgProxy;
try
{
    Entity myAccount = new Entity("account");
    myAccount["name"] = "Test Account";
    _service.Create(myAccount);
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}
}

Filed under: CRM, CRM 2011, Microsoft Dynamics CRM Tagged: CRM 2011, Microsoft Dynamics CRM

This was originally posted here.

Comments

*This post is locked for comments