Tuesday 7 February 2012

Debugging Silverlight Web Resources for MS Dynamics CRM 2011

I read this post about debugging Silverlight and it felt like too much of hack. So I thought I would present my far superior (I'm kidding here, I do think it's neater, though) solution.

Assuming that you have followed the tutorial on the SDK or on this page, you should have a file called SilverlightUtilty.cs and in this file you will have a method called GetSoapService. All you need to do is make use of the #if directive.

#if !DEBUG
            Uri serviceUrl = CombineUrl(GetServerBaseUrl(), "/XRMServices/2011/Organization.svc/web");
#else
            Uri serviceUrl = new Uri("http://localhost/testorg/XRMServices/2011/Organization.svc/web");
#endif

You also need to ensure that you only use the Debug build for your development environment and Release for production, but you are doing that already, right?. At any rate, here is a step by step guide:
  1. Set up Silverlight project following this tutorial.
  2. Change code in SilverlightUtility.cs as described above.
  3. Create clientaccesspolicy.xml file:

    <?xml version="1.0" encoding="utf-8"?>
    <access-policy>
     <cross-domain-access>
      <policy>
       <allow-from http-request-headers="*">
        <domain uri="*"/>
       </allow-from>
       <grant-to>
        <resource path="/" include-subpaths="true"/>
       </grant-to>
      </policy>
     </cross-domain-access>
    </access-policy>
    

  4. Copy clientaccesspolicy.xml to the website directory (normally c:\Program Files\Microsoft Dynamics CRM\CRMWeb\).
  5. Debug from Visual Studio.
  6. Ensure that you compile it as Release before you deploy it to other environments.
Note that if you use the same org name in Dev, Test and Prod, you could change the code to simply:
Uri serviceUrl = new Uri("http://localhost/org/XRMServices/2011/Organization.svc/web");

No comments:

Post a Comment