How to enable MS Dynamics CRM 2011 to integrate with Windows Azure

Hi,

I’m writing this article to explain a good architecture design for integrating your Microsoft Dynamics CRM 2011 with windows azure.

Let’s  say you have on-premise CRM 2011 instance, and you want to use Windows Azure Blob storage to store Customer’s documents on the cloud. How would you do that ?

The example i’m giving is applicable to any other windows azure service such as: SQL Azure, Mobile Notification Service, AppFabric Features..etc.

Since Windows azure is a scalable Cloud platform, you can easily integration your CRM 2011 with the windows azure on the cloud in 4 main steps.

Before going through the details, I’d like to explain the architecture of the proposed solution.

MS CRM 2011 has a backend windows service called “CRM Asynchronous Service” this is the component that will be in charge to communicate with the windows azure through a service bus.

MS CRM 2011 has 2 types of plugins, out-of-the box (OOB) and custom plugins. The OOB plugins runs  with full trust but the custom plugins runs with partial trust, and we will develop a custom plugin to connect to a listener through azure service bus.

The solution has the following components:

1) Configure CRM to be Windows Azure Aware.

2) We need to configure a service bus on Azure with an endpoint to communicate with the CRM server.

3) A listener hosted in Windows Azure to communicate with the asyncrhounous service, specificially listening to CRM assembly “Microsoft.Xrm.Sdk” with RemoteExecuteContext defined. so we need to develop a listener and deploy it on windows azure.

4) A custom CRM Plugin to communicate with the Windows Azure Listener.


How To accomplish, configure and develop this solution:

1) To accomplish step 1 , “Configure CRM for Integration with Windows Azure” :
http://technet.microsoft.com/en-us/library/gg328249.aspx

2) To accomplish step 2, “Configure Windows Azure ACS on Azure” :
http://technet.microsoft.com/en-us/library/jj863635.aspx

3) How to write a windows azure listener:
http://technet.microsoft.com/en-us/library/gg309615.aspx

C# Sample code – Listener:
http://technet.microsoft.com/en-us/library/gg309657.aspx

4) To accomplish step 4, “How to write Azure Aware CRM Plugin”:
http://technet.microsoft.com/en-us/library/gg328194.aspx

Note, if you want to develop a custom workflow activity:
http://technet.microsoft.com/en-us/library/gg327854.aspx

Registration step – FINAL:
http://technet.microsoft.com/en-us/library/gg328524.aspx


**Here is some sample code for all what i mentioned above “listeners & plugins”:
http://technet.microsoft.com/en-us/library/gg334712.aspx

Note: you should be having CRM SDK and Windows Azure SDK 1.7 or higher to be able to exercise and develop the solution.

Hope this helps.


Reference:
-Azure Extensions for Microsoft Dynamics CRM 2011:
http://technet.microsoft.com/en-us/library/gg309276.aspx



 

Fix It: Application deployment Failed, Please try again in VS 2012

Hi,

A well-known error message is being thrown from VS 2012 when you try to run the emulator for Windows Phone 8. After you installed all the tools and trying to see your application on the emulator you get the above error and it is a show stopper! It’s so frustrating and annoying not to be able to view your running code.

After i was stuck for 3 days, and posting my question in MSDN and contributing on StackOverflow and other forums, all of these suggestions didn’t work with me.

My case is fairly simple: I have a brand new laptop, Lenovo AMD E1500 (Supports SLAT) with 4GB RAM on Windows 8 Pro 64bit with VS 2012.

Every time i try to run my windows phone 8 application after selecting “WVGA 512MB” Emulator, it takes forever and i got this error:

Application Deployment Failed, Please try again.

When i check the output window in VS2012, I see the error happens when the VS 2012 tries to connect to the created VM in Hyper-V.

Here is the steps you have to make sure befor uninstalling the SDK or the other tools:

1) Turn off windows firewall.
2) Make sure that you are running VS 2012 as an administrator.
3) Make sure that you are a member of Hyper-V Administrator on your machine.
4) Open Hyper-V and check the you have a VM called “Emulator WVGA 512MB” since this is the VM that VS 2012 is trying to deploy the xap file into.
NOTE: IF YOU DON’T HAVE THE VM, THIS POST IS NOT INTENTED TO FIX IT.

5) Check the connection type for “Windows Phone Emulator Internal Switch” in Hyper-V manager by clicking on Virtual Switch Manager link on the right pane is Internal.

6) In the control panel, Check Network and Sharing Center and then click on change adapter settings –> you should be able to find 3 adapters starts with vEthernet, those are being used with Hyper-V.
Don’t change any configuration by your self without any direction from a network guy! missing around these configuration might need you to re-install all the tools and rebuild all virtual switches!

7) Check below Article for MSDN and verify you have the following configuration for “vEthernet (Internal Ethernet Port Windows Phone Emulator Internal Switch)

http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj681694(v=vs.105).aspx

8) IMPORTANT: Turn off  any antivirus real time scanning, This turns into scanning all communications which slow down the VS/Emulator and times out the emulator running process so you won’t be able to deploy your application. THIS WAS MY FINDING AFTER SPENT 3 DAYS!

After following all above instructions you shouldn’t have any issues with running your WP8 Emulator.

Have Fun.





VS 2012 Update 1 is available

Hi,

Yesterday, Microsoft released a new update for VS 2012. In this first update for VS 2012, They included a lot of enhancements in terms of TFS services, SharePoint Development ALM, .NET Framework enhancements, Mobile development Enhancements and IDE fixes.

The complete list of all the updates in details are listed here:

http://support.microsoft.com/kb/2797915

So, if you are developing using VS 2012, it is strongly recommended to install this update, this is the download link:

http://www.microsoft.com/en-us/download/details.aspx?id=35774

Hope this helps.

Generic Failure in WP8 Emulator and Error when opening Hyper-V Switch Manager!

Hi,

I was developing a windows phone 8 application using VS 2012, and after i did some changes in the network adapter by disabling the hyper-v virtualization protocol “vEthernet” and all its components, the emulator stops working!.

The reason i did this because i wasn’t able to give a static IP to my machine so i can access it from my second machine, installing TCP/IP 4 to set the static IP and unchecked Hyper-V protocol screw my virtual Ethernet adapter and emulator components that are using it.


I was looking and searching what caused this problem, the only thing i was sure about it it is something related to the network adapter settings! since the network adapter doesn’t have the required settings for the Hyper-V neither The emulator nor the Hyper-V switch manager is working and throwing errors.

The emulator was throwing an error: Generic Failure in VS 2012.

The Hyper-V Switch manager is throwing this error message: An error occurred while trying to retrieve a list of virtual switches.


To cleanup your machine and get back developing on the emulator, do the following:

1) Open Hyper-V Manager, you will find a VM created for your emulator, Delete this VM.

2) From Control Panel, Open Add or Remove windows Features -> Un check Hyper-V. This will un install all Hyper-V configuration. Reboot your machine.

3) From Control Panel, Add back Hyper-V to your windows, this will install Hyper-V manager and install all required vEthernet and other components that are required to run the emulator.

4) Open Hyper-V Manager, Click on “Add Virtual Switch Manager” and then add a virtual switch of type Internal.
Notice: you won’t get the error message we had earlier!

5) Open your visual studio, and run your WP8 application, this will configure the emulator VM and all its components.
Notice: The first will take a longer time to run, since the windows will install all required drivers and create the VM used by the emulator and setup the network adapters between the PC and the VM.

6) If you check the Hyper-V manager after the first run for your application, VS 2012 has created a new VM and used the new Virtual Switch we created earlier.

Hope this helps!

Drop me a line if you have this problem and have other solutions or workarounds to it.

Thanks.




Calling Stored procedure from EF takes long time and times out!


Hi Folks,
 
I was going through an interesting performance issue when calling a stored procedure from my web application more than one time and the WCF was timing out because of the stored procedure execution takes long time to execute.
 
At the first, I have a parameterized stored procedure that takes different parameters. First time it executes as expected.
 
The second time, the EF calls the stored procedure and i don’t get any results back to my application. i thought there is an issue in the Stored procedure but no because the stored procedure works as expected from the SQL management studio.
 
 
This means, there is something is going on between the EF bindings and getting results to mapped views/entities we have in the DBML file.
 
I was searching and trying to find any clue why this could happen ? I tried different things but it didn’t work, until i read the following articles about performance issues in EF:
 
http://msdn.microsoft.com/en-us/library/cc853327.aspx
 
I realized that i don’t have issues in terms of the SQL performance, but EF does have some overhead on executing any stored procedure and getting the results back to mapped view objects. Since this search stored procedure return list of objects to one of my entities, i want to know why does it take long time to execute and i don’t get my results back ?!
 
I found the solution for my problem by doing 2 steps:
 
1) Since i don’t want to track any loaded objects for my entities, i added the following merge option with No Tracking when i call my stored procedure.

C# Code:

this.ObjectContext.Search(EmpId,EmpName, DeptId,DeptName, System.Data.Objects.MergeOption.NoTracking).ToList();


2) Since SQL Server has a known performance issue called Paramter sniffing, which means the SQL Server engine allows to compile the plan for the stored procedure and reuse this plan for subsequent calls of the same stored procedure with different paramters! and this was my case, i pass long list of parameters but with different values. the first time executes as expected because the server chose to compile the plan with the results but the second time it re-uses the compiled plan which might not work well with the results that i want and this takes long time to get the expected results!
 
This is a known issue when your stored procedure inlcudes Like keyword in your queries and you use the input paramters directly to filter your results without using other temp paramters assigned from the input parameters.
 
What you need to do is to force SQL to compile the query each call and not to use a precompiled plan and this can be accomplished by using : RECOMPILE query hints along with your query. This is supported in SQL 2005 and above. I’m using SQL 08 R2 server.

Select * FROM myView
WHERE DeptName like ‘%’ + @DeptName+ ‘%’ 
OPTION (RECOMPILE); – This enhance the performance query and fix the parameter sniffing issue for multiple calls stored procedure.

 After these 2 changes, I ran my web application, the application works as expected and no times out for the stored procedure that is being called twice!

Hope this helps.


Reference:
1) Table Hints in SQL Server:
http://msdn.microsoft.com/en-us/library/ms181714.aspx

2)  Paramter Sniffing in SQL Enginer:
http://blogs.technet.com/b/mdegre/archive/2012/03/19/what-is-parameter-sniffing.aspx


 
 

What do you expect from Entity Framework 6 Alpha ?

Hi,
 
I was reading the MSDN magazine March 2013 and i found an article by Julie Lerman about EF 6 Alpha features.
 
If you haven’t had the chance to read the article, here is a summary of this article for .NET developers and architects:
 
1)      EF 6 will be supporting multiple schemas. So in your dbml file you will be able to reference and import multiple schemas in your database.
 
Julie has written a detailed article about this feature, here is the link for this:
 
2)      EF6 will be supporting the asynchronous processing (Async).
Since we have Asynchronous pattern supported in .NET 4.5. The EF 6 will be bringing some of these features by having: SaveChangesAsync(), ExecuteSqlCommandAsync and FindAsync() functions that don’t block the UI while executing and you will be able to write asynchronous code in your application in EF 6.
 
For Linq to Entities, they have added bunch of other Async methods for enumerations such as: ToListAsync(), FirstOrDefaultAsync(), MaxAsync().
 
This is a very important feature especially for Silverlight, WPF and Windows Phone developers in addition to web developers.
 
3)      Enum and Spatial support
EF 6 will be supporting enums and Spatial data types. Unlike earlier version where dependent on the .NET framework you are using/targeting. The new EF 6 will be supporting this no matter which .NET framework you are targeting. So you can use enums and spatial support even you are targeting .NET 4.0 framework that doesn’t support certain EF 6 features.
 
Hope this helps.

Conditional using statement in C# debug versus Release

Hi Folks,

I’m writing this blog post to share how to write conditional using statements in C#. The meaning of this is how to use using statements in Debug mode versus Release mode in reference to different dlls. This is needed when you are using any testing/sandbox DLLs that use any non production environment and you want your code to use other reference when you build a Release for your application in reference to production dlls.

The below code is using In-App Purchase library for Windows Phone 8.

C# Code:

#if DEBUG
using MockIAPLib;
using Store = MockIAPLib;
#else
using Windows.ApplicationModel.Store;
#endif
Notice: you give the same alias name for the testing Libaray namespace as the one that will be used in production so you don’t need to re-write your code.

Then, you can use any class for the referenced namespace:

ProductListing p = new ProductListing();


Tip: You should select Release before your deploy your application to products so the application will refer to the production assemblies and not the ones are used in the debug mode.


Hope this tip helps!