Creating records in CRM while Outlook client is in offline mode.

Hello All, I’m back with exciting new sample code to develop your own SDK application with offline capability. The application uses Cassini server URL. This article provides you step by step information how and what to write. I have also mentioned some environment step that you can keep handy.

Requirements

  1. CRM for Outlook (Offline Capability)
  2. Visual Studio 2010
  3. .NET Framework 4.0
  4. CRM 2011 SDK

Walkthrough Steps:

  1. Create a Windows application using Visual Studio
  2. Add appropriate references and declare the following namespace

using System.ServiceModel;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Client;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Client.Services;
using Microsoft.Xrm.Client.Configuration;

  1. Add the following source code

//Organization URL
Uri OrganizationUri = new Uri(String.Format("https://{0}/XRMServices/2011/Organization.svc","localhost:2525"));
//Discovery URL
Uri HomeRealmUri = new Uri(String.Format("https://{0}/XRMServices/2011/Discovery.svc", "localhost:2525"));
//Domain Credentials
ClientCredentials localCredentials = new ClientCredentials();
//Live Credentials - Used in CRM Online. I have just created instance, but I don't fill values.
ClientCredentials deviceCredentials = new ClientCredentials();
localCredentials.UserName.UserName = "XXXXXXXX";
localCredentials.UserName.Password = "XXXXXXXX";
using (serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, localCredentials, deviceCredentials))
{
    serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
     IOrganizationService service = (IOrganizationService)serviceProxy;
     Entity account = new Entity("account");
     accountId = serviceProxy.Create(account);
     MessageBox.Show("Account with name " + textBox1.Text + " is created successfully.");
}

This code is similar to what I have described in my first blog about creating web service here except I'm using cassini here instead of online URL.

You will also notice I have used "localhost:2525" which is the default port for cassini server. You can always change the default port. I have complied couple of articles related to this topic.

  1. FAQ’s on Cassini Server: https://support.microsoft.com/kb/893391
  2. Sample : Use Outlook Methods: https://msdn.microsoft.com/en-us/library/gg309513.aspx