Home > CRM 2011 > Creating OrganizationServiceProxy in CRM2011 custom applications

Creating OrganizationServiceProxy in CRM2011 custom applications


Below are the steps to instantiate “Organization Service Proxy” which can be used to consume CRM service and perform operations in a  custom application

– Refer “Microsoft.Xrm.Sdk & Microsoft.Xrm.Sdk.Client” .dll’s to your custom application

using Microsoft.Xrm.Sdk;

using Microsoft.Xrm.Sdk.Client;

using System.Net.Security;

using System.ServiceModel.Description;

using System.Security.Cryptography.X509Certificates;

private Uri homeRealmUri = null;

private ClientCredentials credentials;

private Uri organizationUri;

private IOrganizationService service;

private OrganizationServiceProxy serviceProxy;

 credentials = new ClientCredentials();

// If CRM On-Premise

// To use custom credentials pass user credentials

credentials.Windows.ClientCredential = new NetworkCredential( {userId},{ password},{ domain} );

// To use Default Credentials; Uncomment below line and comment above

// credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

// If CRM Online

credentials.UserName.UserName = “Office 365 ID”; // i.e.,  name@domain.onmicrosoft.com

credentials.UserName.Password = “Office 365 Password”;

// Use “https” if CRM is SSL configured

string orgUrl= “http://ServerName/OrganizationName/XRMServices/2011/Organization.svc”;

// Add this line if URL has “https” (i.e.,CRM is SSL configured)

if (!string.IsNullOrEmpty(orgUrl) && orgUrl.Contains(“https”)) {

ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain,
SslPolicyErrors sslPolicyErrors) { return true; };


organizationUri = new Uri(orgUrl);

using (

serviceProxy =

new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, null))


// To impersonate set the GUID of CRM user here

serviceProxy.CallerId = {GUID of CRM User};

serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

service = serviceProxy;


Hope it helps 🙂

  1. Shyam
    April 4, 2013 at 12:33 PM

    you have missed to include using System.ServiceModel.Description;

  2. April 25, 2013 at 6:52 PM

    Great post…..:)
    It’s working cool…..

  3. LS
    February 4, 2014 at 1:36 PM

    Regards to https : Excelent! Spot on!

  4. PPC
    May 26, 2015 at 12:23 PM

    It’s working

  1. November 7, 2012 at 11:53 PM
  2. March 13, 2013 at 9:41 PM
  3. July 1, 2015 at 3:36 PM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: