How To Connect Crm 2007 c#

6:27 PM

Microsoft Dynamic CRM 4
Microsoft Dynamic CRM 4.0
CRM is a business solution that helps companies improve marketing, sales, service and commitment to its customers to increase the efficiency of the organization, while helping to improve the customer experience. Now I want to share a little bit experience in development crm. Acctualy I am Microsoft Dynamic CRM 2011, but for some project still use crm 2007. so I have to migrate my code from dynamic crm 2011 to dynamic crm 2007. It's very defferent code. here we go !
  1. config file
  2. <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
        </startup>
    
     <appSettings>
      <add key="CRMServerURL" value="http://{{your crm address}}/MSCRMServices/2007/crmservice.asmx?wsdl"/>
      <add key="CRMOrganization" value="yourorganization"/>
      <add key="CRMUsername" value="yuorusername"/>
      <add key="CRMPassword" value="yourpasword"/>
      <add key="CRMDomain" value="yourdomain"/>
    
     </appSettings>
    </configuration>
    
  3. I usualy create new class for crm connection function, retrieve entity etc.
  4. using Microsoft.Crm.Sdk;
    using Microsoft.Crm.Sdk.Query;
    using Microsoft.Crm.SdkTypeProxy;
    using Microsoft.Crm.Sdk.Metadata;
    using Microsoft.Crm.SdkTypeProxy.Metadata;
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Linq;
    using System.Net;
    using System.Text;
    using System.Threading.Tasks;
    using System.IO;
    using System.Xml;
    
    namespace CRMTutorial
    {
        class CRMClass
        {
            string _crmserviceurl = ConfigurationManager.AppSettings["CRMServerURL"];
            string _organization = ConfigurationManager.AppSettings["CRMOrganization"];
            string _username = ConfigurationManager.AppSettings["CRMUsername"];
            string _password = ConfigurationManager.AppSettings["CRMPassword"];
            string _domain = ConfigurationManager.AppSettings["CRMDomain"];
    
            public CrmService crmservice_conn()
            {       
                CrmAuthenticationToken mytoken = new CrmAuthenticationToken();
                mytoken.AuthenticationType = 0;
                mytoken.OrganizationName = this._organization;
    
                NetworkCredential mycredential = new NetworkCredential();
                mycredential.UserName = this._username;
                mycredential.Password = this._password;
                mycredential.Domain = this._domain;
    
                CrmService myservice = new CrmService();
                myservice.Url = _crmserviceurl;
                myservice.UseDefaultCredentials = false;
                myservice.CrmAuthenticationTokenValue = mytoken;
                myservice.Credentials = mycredential;
    
                return myservice;
            }
    }
    
  5. main program
  6. using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.Crm.Sdk;
    using Microsoft.Crm.Sdk.Query;
    using Microsoft.Crm.SdkTypeProxy;
    using Microsoft.Crm.Sdk.Metadata;
    using Microsoft.Crm.SdkTypeProxy.Metadata;
    using System.IO;
    using System.Xml.Linq;
    using System.Xml;
    using System.Configuration;
    
    
    namespace CRMTutorial
    {
        class Program
        {
            static void Main(string[] args)
            {
                CRMClass crmclass = new CRMClass();
       //call service you have created
                CrmService service = crmclass.crmservice_conn();
       
       /*
       *your code here
       */   
            }
        }
    }
    
Thanks for visiting...
happy coding :)

You Might Also Like

0 comments

Popular Posts

Like us on Facebook

Flickr Images