How to get IOrganizationService Object of CRM Online using C#


Here is the code to get the IOrganizationService Object of CRM online using C#

public static IOrganizationService GetOrganizationService(string strUserName, string strPassword, string strServiceURL)

       ClientCredentials userCredentials = new ClientCredentials();
       userCredentials.UserName.UserName = strUserName;
       userCredentials.UserName.Password = strPassword;
       var orgService = new OrganizationServiceProxy(new Uri(strServiceURL + “/XRMServices/2011/Organization.svc”), null, userCredentials, null);
       orgService.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
       return orgService;

Hope this helps.

Happy CRM’ing

Leave a Reply

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

You are commenting using your 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