Michael Philip's Blog

Writing about MS Tech with strong focus on Azure & CRM

Creating Organization Service Proxy in Microsoft Dynamics CRM 2011

1 Comment

Hi,
I am gonna show in this article how to create a proxy for the organization service which helps you to perform many operations regarding the CRM ,before getting into the code make sure the have referenced  the following “Microsoft.Xrm.Sdk & Microsoft.Xrm.Sdk.Client”

Code:
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

private Uri homeRealmUri = null;

private ClientCredentials credentials;

private Uri organizationUri;

private IOrganizationService service;

private OrganizationServiceProxy serviceProxy;

credentials = new ClientCredentials();

// To use custom credentials pass user credentials

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

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

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

// 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;

}

Original Article :http://rajeevpentyala.wordpress.com/2012/02/26/creating-organizationserviceproxy-in-crm2011/

Advertisements

One thought on “Creating Organization Service Proxy in Microsoft Dynamics CRM 2011

  1. That’s a pretty cool information about how to create private proxies you have written there. I appreciate that.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s