CRM 2011, C#: Connect CRM 2011 without using SDK/using .Net Framework 3.5

Recently I had a situation where I was already done with coding with C# 4.0 and CRM 2011 SDK. The issue was the project was built on Visual Studio 2008 with .Net framework 3.5. Now the client did not mention that they do not want to move to .Net framework 4.0. But to use CRM 2011 SDK assemblies I had to convert it to 4.0. I had to convert the project back to .Net framework 3.5.

I searched for solution to this issue and found an interesting posts on MSDN and  this post just follow these steps and connect CRM 2011 with .net framework 3.5:

Steps:

1. Create a .Net project with framework 3.5.

2. Add a web service reference of your organization service – (i.e. http://<server >:<port>/<Organization Name>/XRMServices/2011/Organization.svc?wsdl)

3. You will get all the methods offered by OrganizationService. Check the screenshot.

CRM 2011 Service Reference

CRM 2011 Service Reference

4. Finally Add the following method so that you can get CRM 2011 Service Object.

/// <summary>
/// Gets or sets the org service.
/// </summary>
/// <value>
/// The org service.
/// </value>
public static IOrganizationService OrgService { get; set; }

/// <summary>
/// Gets the CRM service.
/// </summary>
/// <param name="serverHost">The server host.</param>
/// <param name="organizationName">Name of the organization.</param>
/// <param name="userName">Name of the user.</param>
/// <param name="domain">The domain.</param>
/// <param name="password">The password.</param>
public static void GetCRMService(string serverHost, string organizationName, string userName, string domain, string password)
{
    Uri OrgUri = new Uri(string.Format("{0}/{1}/XRMServices/2011/Organization.svc", serverHost, organizationName));

    SymmetricSecurityBindingElement symmetricSecurityBindingElement = new SymmetricSecurityBindingElement();
    symmetricSecurityBindingElement.ProtectionTokenParameters = new SspiSecurityTokenParameters();

    HttpTransportBindingElement httpTransportBindingElement = new HttpTransportBindingElement();
    httpTransportBindingElement.MaxReceivedMessageSize = 1000000000;

    CustomBinding customBinding = new CustomBinding();
    customBinding.Elements.Add(symmetricSecurityBindingElement);

    TextMessageEncodingBindingElement textMessageEncodingBindingElement = new TextMessageEncodingBindingElement(
        MessageVersion.Soap12WSAddressing10, Encoding.UTF8);
    customBinding.Elements.Add(textMessageEncodingBindingElement);
    customBinding.Elements.Add(httpTransportBindingElement);

    EndpointAddress endpointAddress = new EndpointAddress(OrgUri);

    OrganizationServiceClient organizationServiceClient = new OrganizationServiceClient(customBinding, endpointAddress);
    organizationServiceClient.ClientCredentials.Windows.ClientCredential = new NetworkCredential(userName, password, domain);

    OrgService = (IOrganizationService)organizationServiceClient;
}

You now have IOrganizationService instance with all required methods available with CRM 2011 SDK.

Find more about this on my next blog post: https://consultrikin.wordpress.com/2013/09/20/crm-2011-c-entity-class-redefined-with-net-framwork-3-5-to-connect-crm-2011/

Advertisements

3 thoughts on “CRM 2011, C#: Connect CRM 2011 without using SDK/using .Net Framework 3.5

  1. Pingback: CRM 2011, C#: Entity Class redefined with .net framwork 3.5 to connect CRM 2011 | Consult Rikin

  2. Hi there,

    I found this very helpful. Thank you very much.

    One question though, your GetCRMService method works when accessing an organization with HTTP, but it doesn’t work with HTTPS. I tried replacing the HttpTransportBindingElement with HttpsTransportBindingElement but that didn’t do the trick.

    Hoping for your feedback.

    Best regards,
    Henry

  3. Hi Henry,

    Thank you for comments.

    I haven’t tried with HTTPS yet. What I know till now is that this method will/can not work with CRM Online. I haven’t tested that part also. (some busy days…)

    I will keep posting of my findings once I get some free time… If you find anything about this, kindly post it here.

    Thanks and regards,
    Rikin

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s