Initializing and setting DefaultCrendentials for OrganizationService in CRM 2011
Views (54)
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
- Microsoft.Xrm.Sdk.
- System.ServiceModel.
- 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.

Like
Report
*This post is locked for comments