Friday, February 18, 2011

CRM 2011 - Debugging Silverlight Webresources without deploying

It finaly works!

Good week for CRM2011 developers!

1. Release of new SDK


2. New informations about WCF-Soap Endpoint

3. Finding a solution for debugging silverlight webresources without deploying the webresources (My personal breakthrough! :))


Ok, first of all i would like to thank "erik-lp" from the MSDN forum for his tipps.

Following things are required for debugging your silverlight webresource.
  • Developing Machine (Same or other domain doesn't mater)
  • CRM-Server (I have tested with RC)
  • clientaccesspolicy.xml
The clientaccesspolicy.xml
<?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>
  1. Navigate to the Web-Folder of your CRM-System. (\..\Microsoft Dynamics CRM\CRMWeb\)
  2. Copy the created clientaccesspolicy.xml into this folder
  3. Open your silverlight project in Visual Studio (For this example, we assume you are using the SOAP example from SDK version 5.0.1)
  4. Navigate to the SilverlightUtility.cs class
  5. Replace following code in the GetSoapService() Method
Before:


Uri serviceUrl = CombineUrl(GetServerBaseUrl(), "/XRMServices/2011/Organization.svc/web");
After:
Uri serviceUrl = new Uri("http:///<ORGNAME>/XRMServices/2011/Organization.svc/web");

Now you can push F5 and start debuging.

This solutions only works in OnPremise Systems. You can not deploy clientaccesspolicy.xml in online systems.
Eric also talks about a ClientGlobalContext.aspx.js file. This is not required, if you replace the code in the SilverlightUtil.cs.

Happy coding!

cheers!

17 comments:

  1. Hi Markus,

    It sounds like we are working on very similar paths. I too am using Silverlight 4 in CRM 2011 and trying to do dynamic things using the SOAP Endpoint.

    I have managed to get as far as successfully sending a reuest using the SDK sample code, however, the fault string I get back from the service is "Required field 'Query' is missing". Did you come across this in your explorations?

    Also, to get the same to even compile I had to commend out various bits of the code like this

    return this.Results.GetItem(key);

    in SilverlightExtensionMethods is returning the compile time error of Type arguments cannot be inferred from usage.

    You have inspired me to set up a blog on blogspot to keep you and others up to date with my progress through these new technologies.

    Best Regards,
    Martin

    ReplyDelete
  2. And here's my blog, some useful posts to follow... :)

    http://silverlite.blogspot.com/

    Cheers,
    Martin

    ReplyDelete
  3. Hi Martin,

    you have to add a query in your request. The problem is, you have no typed request-classes in silverlight. So you have to build your "OrganizationRequest" by yourself.

    The easiest way is to search the sdk for the exact requestname and for the required properties. An alternative way is to create a console application with the xrm assemblies, creating the required request and look in the properties of the typed object.

    The first step you should try is to build the example for silverlight webresource with soap from sdk.

    http://msdn.microsoft.com/en-us/library/gg594452.aspx#Y1126

    Cheers,
    Markus

    ReplyDelete
  4. Cracked it!

    Thanks Markus!! I am now successfully debugging without having to deploy to CRM.

    Cheers,
    Martin

    ReplyDelete
  5. This has been very helpful! However, when I run my solution it is asking for credentials now. When I supply them I am getting an 'Unauthroized' message in Fiddler. I know that the credentials I have supplied are correct since I can browse to the service in IE (which also asks for credentials.) Any ideas on how I can get this to work?

    ReplyDelete
  6. Hi Steve, when I got this changing the domain to an IP address worked for me... Let me know if that gives you any joy.

    ReplyDelete
  7. I'm using an IP address as well. Any other ideas?

    ReplyDelete
  8. On which OS runs your Visual Studio?

    If you are using Windows XP, i think you will run into the problems regarding Windows Identity Foudation.

    http://mkonrad.blogspot.com/2010/11/crm-2011-filenotfoundexception-when.html

    In my example i only developed on Windows 7.

    ReplyDelete
  9. I am a newbie working with CRM2011 and Silverlight 4.
    Can we conclude that Silverlight can only work with CRM in "On Premise"?

    ReplyDelete
  10. Hi Daniel,

    you can use Silverlight for CRM2011 Online and OnPremise (also IFD) Systems.

    cheers

    ReplyDelete
  11. Exception: [HttpWebRequest_WebException_RemoteServer]
    Arguments: NotFound

    I've got this error instead of the cross domain error. Any Idea?

    Thanks

    ReplyDelete
  12. May be your request ist not correct. Try to debug with fiddler2.

    http://www.fiddler2.com/fiddler2/

    cheers

    ReplyDelete
  13. Thank you, you just saved the day!

    ReplyDelete
  14. Hola, alguien me podria ayudar, tengo un problema con el crm 2011, intento modificar crm pero, me dice que los metadatos tiene una referencia que no se puede resolver

    ReplyDelete
  15. Hi,

    when i add /web in the below code, it gives me BAD request 400 (the remote server returned an error not found).

    Uri serviceUrl = new Uri("http:////XRMServices/2011/Organization.svc/web");

    Any idea what could be wrong?

    Regards,
    Ravi

    ReplyDelete