Amazon

Wednesday 29 April 2015

Dynamics CRM integration through c# - Create leads customers from your applications



You can add the necessary dll from SDK which is available on internet or Click Here.

The code which is given below


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using System.ServiceModel.Description;
using System.Web.Services.Protocols;
using System.Runtime.Serialization;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Xrm.Sdk.Query;

namespace WebAppWalkthrough
{
    public partial class _Default : System.Web.UI.Page
    {

        private OrganizationServiceProxy _serviceProxy;
        private IOrganizationService _Orgservice;
       
        protected void Page_Load(object sender, EventArgs e)
        {
          
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                ClientCredentials cre = new ClientCredentials();
                cre.UserName.UserName = "URNAME@DOMAINNAME.onmicrosoft.com";
                cre.UserName.Password = "PASSWORD";
                Uri serviceUri = new Uri("https://DOMAINNAME.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("lead");
                ent.Attributes["firstname"] = txtLeadNAme.Text;
                ent.Attributes["subject"] = "Test by Aravind";
                service.Create(ent);
            
            }
            catch (SoapException ex)
            {

            }
            catch (Exception ex)
            {

            }

        }
}
}