Posted in Code Snippets, CRM, Plugin

Creating CRM Organisation Service

Creating CRM Organisation Service :

Connecting to dynamics CRM through API with service proxy

// Credentials

 string username = "admin@xxxxx.onmicrosoft.com";
 string password = "xxxxxx";
 string url="https://xxxxxxx.api.crm.dynamics.com/XRMServices/2011/Organization.svc";
//Connection
 
 Uri organisationurl = new Uri(url);
 ClientCredentials credentials = new ClientCredentials();
 credentials.UserName.UserName = username;
 credentials.UserName.Password = password;
 OrganizationServiceProxy service = new OrganizationServiceProxy(organisationurl, null, credentials, null);
 service.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

or

OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, credentials, null);
proxy.EnableProxyTypes();
IOrganizationService service = (IOrganizationService)proxy;

// It will connected and enjoy
Advertisements

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