Thursday, January 12, 2012

Developing CRM Silverlight Web Resources outside of CRM


When you are developing a Siverlight web resource for use in Microsoft CRM it can be a pain having to deploy the XAP web resource each time you want to do some testing.

The microsoft recommendation is to ‘Write and test as much of the application as you can without requiring contextual data from Microsoft Dynamics CRM.’

Then when you want to start writing the bits of the app that require context information you have to redeploy you resource each time.

A way round this problem is to mock the Xrm.Page.context property that is available when your app is hosted in CRM – this lets you take your application further before you have to deploy.

In the aspx page you are using to test the silverlight app add a snippet similar to the following the following code snippet to hard code some context values:

    <asp:ScriptManager ID="ScriptManager1" runat="server">


    <script type="text/javascript">


        Xrm.Page = function () { };


        Xrm.Page.context =


            getUserId: function () { return "e2511a4a-f914-e111-91ba-00155d828444" },

            getServerUrl: function () { return "http://crmserverurl" }

            //See for a list of

            //available functions




Note ScriptManager is part of the Microsoft AJAX Extensions library