Set up the CRM Service

This code snippets setups a Crm service provided the url & organization name
Add the following include files
using System;
using System.Collections.Generic;
using System.Text;
using CrmSdk;
using MetadataServiceSdk;
 



Create a CRMService

/// <summary>
      /// Set up the CRM Service.
      /// </summary>
      /// <param name="organizationName">My Organization</param>
      /// <returns>CrmService configured with AD Authentication</returns>
      public static CrmService GetCrmService(string crmServerUrl, string organizationName)
      {
         // Get the CRM Users appointments
         // Setup the Authentication Token
         CrmSdk.CrmAuthenticationToken token = new CrmSdk.CrmAuthenticationToken();
         token.OrganizationName = organizationName;
      
         CrmService service = new CrmService();
 
         if (crmServerUrl != null &&
            crmServerUrl.Length > 0)
         {
            UriBuilder builder = new UriBuilder(crmServerUrl);            
            builder.Path = "//MSCRMServices//2007//CrmService.asmx";
            service.Url = builder.Uri.ToString();
         }
 
         service.Credentials = System.Net.CredentialCache.DefaultCredentials;
         service.CrmAuthenticationTokenValue = token;
 
         return service;
      }