Connect to MS CRM 2011 Online using C# Sdk

Posted: May 23, 2013 in Code Snippets, CRM 2011

Create record in MS CRM 2011 Online using C# Code

Add "Microsoft.Xrm.Sdk" reference from your sdk bin folder.

Then add the following namespaces
1) using Microsoft.Xrm.Sdk;
2) using Microsoft.Xrm.Sdk.Client;
3) using System.ServiceModel.Description;
4) using System.Web.Services.Protocols;

Finally add the below code :


try
            {
                ClientCredentials cre = new ClientCredentials();
                cre.UserName.UserName = "<username>.onmicrosoft.com";
                cre.UserName.Password = "<password>";

                Uri serviceUri = new Uri("https://<orgname>.api.crm5.dynamics.com/XRMServices/2011/Organization.svc");

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

                Entity ent = new Entity("<entitySchemaName>");
                ent.Attributes["new_name"] = "Created from Console App4";
                service.Create(ent);
            }
            catch (SoapException ex)
            {

            }
            catch (Exception ex)
            {

            }

Happy Coding 🙂

Advertisements
Comments
  1. Nagarjuna says:

    Thanks sir, very nice article.

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