Monday, 26 September 2011

CRM Entropy - A Microsoft CRM Blog: Silverlight and CRM 4 (continued)

[UPDATE: The conclusion of this series is up, and in it I discuss the code and break-down how I developed it and why it works the way it does.]

I promised in my last post on the subject that I would include an example of the code I presented during my CRMUG 10@10of10 segment.  Then, I went to delay that example for a couple of weeks while I was looking for a good time to produce it.  Well, today was that day.

For starters, the example code is hosted at CodePlex.  I put the project together in Visual Studio 2010, so the solution and project files will all reflect that.  Also, you will need the Silverlight 4 Tools for VS 2010 and the Silverlight 4 for Developers Runtime to open the project files.  Head on over there to download it, decompress it to your favorite demonstration code directory, and come back here for the instructions on putting it together.

Putting It Together

First, download the WSDL from a CRM deployment you would like to compile the project against.  I personally prefer a “vanilla” deployment of CRM to keep the WSDL small, and rely on DynamicEntity to perform all the dirty work for me—however that is not necessary for this sample project (in fact, I don’t use DynamicEntity at all in it, though my special “NamedProperties” extension is available to the project for your own tinkering amusement).

1 - Customization

2 - Download WSDL

3 - Download WSDL for CrmService

4 - Download WSDL for CrmService - Save As

Save the resultant XML file somewhere easy to locate, such as the root folder for our project.

5 - Save WSDL as Xml File

Open the solution in Visual Studio, and add a “Service Reference” to the Simple CRM App project.

6 - Add Service Reference

Be sure to specify the XML file location as the “Address” and then click Go.  Upon a successful load, the “Services” frame will contain an item titled “CrmService”.  Specify the “Namespace” value as CrmSDK.  Click OK when finished.

7 - Add Service Reference - Location and Namespace

Next, add a “Reference” to the Simple CRM App.Web project.

8 - Add Reference

Locate and select the assembly microsoft.crm.sdk.dll from the CRM 4 SDK.  Click OK.

9 - Add Reference - CRM SDK

Now, build the whole solution.

To deploy the project to CRM, create this new folder:

<crm web root>/ISV/SCA

In this folder place the following files from the Simple CRM App.Web project folder:

Silverlight.js
SimpleCrmApp.aspx
ClientBin/Simple CRM App.xap  (copy the folder)

Deploy this file:

Simple CRM App.Web/bin/SimpleCRMApp.Web.dll

Into the following location:

<crm web root>/bin/

Now, in order to view the project, export your SiteMap.xml from the customizations, and insert this code into some reasonable area

<SubArea Id="SimpleCrmApp" PassParams="1" Url="/../ISV/SCA/SimpleCrmApp.aspx" AvailableOffline="false">
  <Titles>
    <Title LCID="1033" Title="Simple CRM App" />
  </Titles>
  <Descriptions>
    <Description LCID="1033" Description="A simple Silverlight demonstration." />
  </Descriptions>
</SubArea>

Import the altered SiteMap.xml, and refresh your CRM window to view the changes.  Upon clicking on the new navigation item, you should be treated to a very basic Silverlight page that shows a list of all active accounts by name.

I’ll get into the details of the code a little more with another post to follow within a day or two.

No comments:

Post a Comment