Sample: Silverlight 2 and CRM
Ok, so here it is (download); I finally had the chance to finish this sample and put it in a form that others can learn from. Various folks both from the Silverlight team and the CRM team were involved in the process of finding ways to make it work (not listing their names here to keep their privacy) so thank you for that. The sample is extremely simple and is just meant to illustrate how to call the CRM service from within Silverlight 2 using the proxy that Silverlight generates. The two key pieces of the sample are:
· A method to wire up the CRM service: It has special logic that injects the CRM authentication token so that CRM can effectively process the calls (see my previous post for a bit more background).
· Usage of DynamicEntity when retrieving data from CRM.
Remember, the sample is provided “AS IS”; I bet there are many others out there that have come up with other patterns/helper-methods to achieve similar results.
Happy coding
Update:
I realized that I didn’t include explicit instruction on how to run this sample (I always assume that my audience is geek enough to understand everything I ramble he he) so here they are:
Requirements:
· Visual Studio 2008 + Silverlight SDK + Silverlight Tools for Visual Studio 2008
· Remember that in order for Silverlight to be able to call a web service the root of the server hosting the service must contain a clientaccesspolicy.xml (or equivalent) file stating that the server allows clients to issue calls to it. The project includes a sample clientaccesspolicy.xml that you can drop in the <crmwebroot> of your server. For more information about these security measures refer to the Silverlight documentation.
·
Instructions:
1. Make sure to drop the policy file (clientaccesspolicy.xml) under the Web root of your CRM server.
2. On page.xaml.cs change the values of the global variables to point to your server:
a. _serverUrl
b. _organizationName
3. Open the project, compile it and run it J
a. If you have troubles compiling/running the project make sure you don’t have namespace conflicts (check this post )
4. If you want to host the sample outside of VS well, you will need to setup your own IIS website and/or put your files under the \ISV\[yoursubfolder] folder (check documentation on the CRM SDK)
Comments
Anonymous
November 05, 2008
PingBack from http://blogs.msdn.com/lezamax/archive/2008/09/24/silverlight-2-and-crm.aspxAnonymous
November 05, 2008
The comment has been removedAnonymous
November 05, 2008
hmm it seems like i ve found the(?) problem the service reference (CrmSdk) is not reachable could that be the problem?Anonymous
November 06, 2008
Silverstarter: Make sure you are setting the url of your server properly; also look at the comments at the top of Page.cs ... you need to have a crossdomain.xml file in the root of your CRM server (I included such file as part of the sample you can can drop it in the root of your crm server). For more information about cross domanin policies and silverlight please refer to the silverlight documentation.Anonymous
November 22, 2008
The comment has been removedAnonymous
November 24, 2008
Aswanee: You probably have an older version of the silverlight RUNTIME. Make sure you uninstall any previous beta versions of the Silverlight runtime and install the RTM version. If that doesn't solve your problem I would suggest you consult the silverlight forums/support.Anonymous
November 26, 2008
Hi, i just downloaded and tested the project. I think the problem was that if you go into the properties of the project, you'll find that the namespace is "CRMSilverlightDirect" instead of "CrmSilverlightDirect". when I changed that to make it consistent to the rest of the project, it worked great for me! thanks for posting this sample!Anonymous
November 26, 2008
I was doing some research on Silverlight 2 & Dynamics CRM integration and found this post by HumbertoAnonymous
December 01, 2008
  There are multiple ways that you can call the CRM Services from Silverlight 2.  I’veAnonymous
December 01, 2008
  There are multiple ways that you can call the CRM Services from Silverlight 2.  I’veAnonymous
December 01, 2008
  There are multiple ways that you can call the CRM Services from Silverlight 2.  I’veAnonymous
December 02, 2008
Do you have this up and running somewhere that I could see before going through the download/install.Anonymous
December 16, 2008
I was doing some research on Silverlight 2 & Dynamics CRM integration and found this post by HumbertoAnonymous
January 06, 2009
Hi, Great post! If I understand correctly, since Silverlight webservice calls are made asynchronously, theoretically the following could happen: t0: DisplayAccounts(…); >>> _lastIssuedRequest = RetrieveAccounts; t1: DisplayContacts(…); >>> _lastIssuedRequest = RetrieveContacts; t2: Service_ExecuteCompleted (for t0) >>> _lastIssuedRequest == RetrieveContacts; (oops! completed event was for RetrieveAccounts) t3: Service_ExecuteCompleted (for t1) >>> _lastIssuedRequest == RetrieveContacts Is there another way to determine which method initiated the request that resulted in the Service_ExecuteCompleted event? Thanks in advance!Anonymous
January 06, 2009
rudgr Yes you are correct, that can happen when working with asynch calls. I noticed the potential problem when developing the sample but didn't spend much time dealing with it. The only alternative that comes to mind would be to recursively "chain" your calls... that would make them sequential;... the code would be somewhat ugly tough.Anonymous
January 06, 2009
I was doing some research on Silverlight 2 & Dynamics CRM integration and found this post by HumbertoAnonymous
January 06, 2009
I was doing some research on Silverlight 2 & Dynamics CRM integration and found this post by HumbertoAnonymous
January 06, 2009
I was doing some research on Silverlight 2 & Dynamics CRM integration and found this post by HumbertoAnonymous
January 23, 2009
Hi, Any idea how to get the GUID of the CRM user doing the request? (i.e. WhoAmIRequest?) Thanks! rudgrAnonymous
January 28, 2009
The sample is not working on my end with SL2 RTM and VS 2008. After resolving the above mentioned errors, I am getting this error "The name already exists in the tree"Anonymous
March 02, 2009
The comment has been removedAnonymous
March 02, 2009
Gjukawa, I haven't seen that error before. Sorry :/Anonymous
April 30, 2009
Hi So I fixed the namespace problem as per Jocelyns post and now I get the page loaded and I can enter the seach critera. Next we get below. Any idea. Is it that crossdomain stuff? System.ServiceModel.CommunicationException was unhandled by user code Message="An error occurred while trying to make a request to URI 'http://127.0.0.1/mscrmservices/2007/crmservice.asmx'. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. Please see the inner exception for more details." StackTrace: at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result) at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result) at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result) at System.ServiceModel.ClientBase1.ChannelBase
1.EndInvoke(String methodName, Object[] args, IAsyncResult result) at CrmSilverlightDirect.CrmSdk.CrmServiceSoapClient.CrmServiceSoapClientChannel.EndExecute(IAsyncResult result) at CrmSilverlightDirect.CrmSdk.CrmServiceSoapClient.CrmSilverlightDirect.CrmSdk.CrmServiceSoap.EndExecute(IAsyncResult result) at CrmSilverlightDirect.CrmSdk.CrmServiceSoapClient.OnEndExecute(IAsyncResult result) at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result) InnerException: System.Security.SecurityException Message="" StackTrace: at System.Net.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) at System.Net.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result) InnerException: System.Security.SecurityException Message="Security error." StackTrace: at System.Net.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState) at System.Net.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState) InnerException:Anonymous
May 04, 2009
The comment has been removedAnonymous
May 05, 2009
Mahesh not sure what is it that you are facing but the error seems to indicate that you modified a Xaml piece (in page.xaml perhaps??). Make sure your xaml is valid and that all the VS tools that you have are for SL 2 (I haven't tried it with the SL beta 3 tools). RegardsAnonymous
May 05, 2009
VJ APU, Yes, the exception seems to be pretty self explanatory. Look at http://msdn.microsoft.com/en-us/library/cc197955(VS.95).aspx for more infoAnonymous
June 03, 2009
Most of the time there CRM service reference which i have added is throwing a TIMEOUT Error.Anonymous
October 05, 2009
after having attempted with this example and a few others, it appears that nothing about this is truly async. i was under the impression that the point behind silverlight not handing us the ability to do synchronous calls was so that we would not be blocking the UI thread, but running this simple example shows the UI thread blocked both instantiating a service client, (and even worse) plus all subsequent "async" calls. is there some way of making these run on a background thread so it's not locking up the UI? even this example with the "loading" and "searching" are locking the UI so those don't actually appear at all until AFTER the work is doneAnonymous
March 09, 2011
Now i want to insert record in crm using this applicatio? How can i do this using this application?