Freigeben über


Building Dynamics CRM Applications for Windows 8 – Practical Approaches

Introduction

We are living in the age of “apps”. A quick search on internet will show that there are close to 15,000 apps registered in Windows 8 marketplace while Android is sprinting ahead with approximately 600,000 aps and Apple will reach record 1 million anytime now. We have huge opportunity in this space.

The Microsoft Dynamics CRM is also evangelizing apps for Windows 8. As per official communication, the Windows 8 app for Dynamics CRM 2011 will be available by mid of 2013. In addition, you can also build your custom app which sources data from Dynamics CRM. I am sure you will come across business scenario (different looks and feel app, app leveraging old versions 3.0/4.0 CRM etc.) where you need to build custom Windows 8 apps for Dynamics CRM.

This article is focused to discuss approaches to integrate Dynamics CRM in Windows 8 apps and pros-cons associated with them.

Challenges

If you try to use CRM SDK with Windows 8 app, you encounter loads of build errors because CRM SDK and Windows 8 app use two different platforms which are not compatible with each other. The CRM SDK classes are built with .Net Framework 4.0 as target while Windows 8 apps use “.NET for Windows Store Apps”. You find the same type of errors whether using early binding or late binding methods.

Solutions

So, how do we build Windows 8 apps which can talk to Dynamics CRM? There are roughly three approaches which we can take – each with their set of pros and cons.

  • Use WinRt compatible CRM Libraries

The Microsoft Dynamics Team has developed WinRt compatible CRM libraries (WinRt.Microsoft.Crm.Sdk.Proxy and WinRt.Microsoft.Xrm.Sdk) which you can use in Windows 8 app. Right now, the libraries are in pre-released state so you can download the code of the libraries along with a sample using them. I presume that the WinRt SDK will be officially released with the release Windows 8 client for Dynamics CRM. You can download WinRt compatible Libraries and sample from the following link –

download.microsoft.com/download/1/A/A/1AA59217-D571-4E65-B037-FE59DD945A13/CRMSLSample.zip

Pros

Cons

The SDK is the way to go as it will be integral  part of CRM release when it happens.

 

Works with CRM Online (Live and Office 365) ,  Claim Based and IFD deployment

 

Does not work with CRM on-premises deployments using  Active Directory authentication. [at present]

 

It is currently in sample stage only.

 

Will not work with old versions of Dynamics CRM (4.0  and 3.0).

 

  • Use Bridge WCF service

This is a simple approach which works with the current release of CRM SDK. It uses a WCF service as an intermediate service to normalize platform compatibility between CRM SDK and Windows 8 app. The following are the high level steps to use intermediate service –

  • Create a WCF Services project. Set target framework as .NET 4.0. It is important because the WCF service will use CRM SDK which is .NET 4.0 based.
  • As per business need, create operations (methods) in WCF Service. Use data contracts and parameters which are compatible with “.NET for Windows Store Apps”. In my personal experience, I used native types (STRING, INT etc.), collections and also data classes without any hassles. Please use the following link to see what data types are compatible - msdn.microsoft.com/en-GB/library/windows/apps/br230232.aspx
  • In WCF operations or methods, use CRM SDK APIs to implement the method. You can use both early and late binding way of coding as per your comfort.

 

  • Finally, reference this WCF service in Windows 8 app and make calls to operations. If you are new to this, please refer the following links -

           msdn.microsoft.com/en-us/library/hh556233.aspx

           <www.tapanila.net/consuming-wcf-service-with-windows-8/>

 

Pros

Cons

Simple to use. Works with current release of CRM  SDK.

 

Works with CRM Online (Live and Office 365), IFD  deployment and On-Premise using Windows Authentication

 

Possible to make calls to old versions (3.0 and  4.0) of Dynamics CRM.

 

More development effort due to development of  intermediate WCF method.

 

You have to plan for deployment of intermediate WCF  service on some box. Overhead deployment task.

 

After the release of CRM SDK for Windows 8 App, this  approach should not be used unless talking to old versions (3.0, 4.0) of  Dynamics CRM.

 

  • Tweak Proxy Class in Early Binding

This approach also uses current release of CRM SDK but works only with early binding method. In brief, you create proxy for CRM web service and then change proxy class code to make it compatible with Windows 8 apps. Here are the steps –

 

  • Use CrmSvUtil utility to create proxy class for CRM Web Service

 

  • Include proxy class in your Windows 8 app project. When you build the project it will throw close to 500 errors in proxy class due to platform in-compatibility between Windows 8 app and proxy class framework APIs.

 

  • In proxy class, most of the errors are related to “System.ComponentModel” class which does not support members like INotifyPropertyChanging, PropertyChangingEventHandler etc. in “.NET for Windows Store Apps”.

 

  • You need to perform marathon task of manually removing and commenting/disabling these member usage and related code in proxy class.

                Note: Deleting these reference will have no negative impact on the functionality.

 

  • Once all the references are deleted, compile the code. After successful compilation, you are good to use this proxy class like you do in normal .NET client.

 

  • It is advisable to include proxy class in Portable Class Library (PCL - targeting .NET Framework 4.0 and above) project in place of Windows 8 client project directly.  The PCL project then can be referenced in Windows 8 client project. Please refer the following link to learn more about PCL - msdn.microsoft.com/en-us/library/gg597391.aspx

 

  • There is a way to generate smaller proxy class by generating only those entities which are required. It simplifies things because then clean-up is performed on a smaller code. Please check the following link for the same - <erikpool.blogspot.co.uk/2011/03/filtering-generated-entities-with.html>

 

Pros

Cons

Simple to use. Use early binding and strong data types.

 

Can leverage Event-based Asynchronous Pattern (EAP) – async /await in Windows 8.

 

Works with CRM Online (Live and Office 365), IFD  deployment and On-Premise using Windows Authentication

 

Lengthy clean-up task. If proxy is regenerated due to  change in entity metadata then clean-up has to be performed each time.

 

Would recommend as intermediate approach till the CRM  SDK for WinRt gets released.

 

Will not work with old versions of Dynamics CRM.

 

Summary

You have choices to use the approach you want. I would recommend using CRM SDK for WinRt when it is released. Till that happens, you can choose between approach 2 and 3. The approach 2 (Bridge Service) has advantage to work with old CRM versions as well. Hope you find this article useful.

 

Brajendra,

Comments

  • Anonymous
    April 15, 2013
    Trying out the first WinRT library you attached, but all I  get is "Access is Denied" when trying to log in (Dynamics CRM Online 2011).