Pages

Tuesday 11 March 2014

Connecting CRM to Dot NET Application

Here I am Creating  a WindowsForm Application which is conneced to CRM.
So I'll Create a new Solution in Visual Studio of Windows Application Type. Now Right click on that solution and Click on the properties. Change the Version of .Net Framework as 4.0

now In my Scenario I am Creating a Record using this Solution. Sor in my form I've added one Text Field and One Button. On clicking of button the record must be created using the textfield value from textbox.

so double click on button in form Design and paste the following code

---------------->
 try
            {
                ClientCredentials cre = new ClientCredentials();
                cre.UserName.UserName = "User Name";
                cre.UserName.Password = "Password";
               var a = "https://<org name>.crm5.dynamics.com";  //for online crm
                Uri serviceUri = new Uri(a+"/xrmservices/2011/Organization.svc");

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

                Entity ent = new Entity("entity name");
                ent.Attributes["Field attribute name"] = textBox1.Text;
                service.Create(ent);
            }
            catch (SoapException ex)
            {

            }
            catch (Exception ex)
            {

            }
---------------->

No comments:

Post a Comment