Welcome to MSDN Blogs Sign in | Join | Help

Tech Tips, Comments and Curious Stuff

Information surrounding technologies that I work with at Microsoft (Dynamics CRM)
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)

 

Posted: Wednesday, November 05, 2008 5:57 PM by humlezg

Comments

Silverstarter said:

im trying out your new example atm

theres one problem

it aborts with a

runtime error at line 453

Sys.InvalidOperationExeption:InitializeError error #2103 in control 'Xaml1' invalid or not well-formed application. check manifest

(translated by myself, if the errormessage isnt too good ;) )

it that a known problem? could it be a problem with blocked access? (sitting behind a corp. firewall which prevents access here and there)

anything i could try out myself? didnt found a way to debug, cause it aborts even before any silverlight code is reached

greetings

Sivlerstarter

# November 6, 2008 3:54 AM

Silverstarter said:

hmm it seems like i ve found the(?) problem

the service reference (CrmSdk) is not reachable

could that be the problem?

# November 6, 2008 6:33 AM

humlezg said:

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.

# November 6, 2008 12:38 PM

Aswanee said:

Dear humlezg

I have same problem when try to open any page have SilverLight component this page not on my pc it in any other site

and i tried to open the same pages form other machin and it successed !!! the error appain as Javascript error as "Error: Sys.InvalidOperationException:InitializeError Error#2103 in control'Xaml1':2103An error has occurred"

Also I already install VS2005, VS2008 on the same Machine

# November 23, 2008 1:01 AM

humlezg said:

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.

# November 24, 2008 10:17 AM

jocelyn said:

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!

# November 27, 2008 1:26 AM

Technoeuphoria! said:

I was doing some research on Silverlight 2 &amp; Dynamics CRM integration and found this post by Humberto

# November 27, 2008 1:51 AM

Microsoft Dynamics CRM Team Blog said:

&#160; There are multiple ways that you can call the CRM Services from Silverlight 2.&#160; I&#8217;ve

# December 1, 2008 1:34 PM

Microsoft Dynamics CRM Team Blog said:

&#160; There are multiple ways that you can call the CRM Services from Silverlight 2.&#160; I&#8217;ve

# December 1, 2008 3:51 PM

Microsoft Dynamics CRM Team Blog said:

&#160; There are multiple ways that you can call the CRM Services from Silverlight 2.&#160; I&#8217;ve

# December 1, 2008 4:25 PM

Silvertryer said:

Do you have this up and running somewhere that I could see before going through the download/install.

# December 2, 2008 9:00 AM

Jocelyn said:

I was doing some research on Silverlight 2 &amp; Dynamics CRM integration and found this post by Humberto

# December 17, 2008 6:10 AM

rudgr said:

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!

# January 6, 2009 8:51 AM

humlezg said:

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.

# January 6, 2009 2:44 PM

jocelyn said:

I was doing some research on Silverlight 2 &amp; Dynamics CRM integration and found this post by Humberto

# January 6, 2009 8:53 PM

jocelyn said:

I was doing some research on Silverlight 2 &amp; Dynamics CRM integration and found this post by Humberto

# January 6, 2009 9:21 PM

jocelyn said:

I was doing some research on Silverlight 2 &amp; Dynamics CRM integration and found this post by Humberto

# January 7, 2009 1:43 AM

rudgr said:

Hi,

Any idea how to get the GUID of the CRM user doing the request? (i.e. WhoAmIRequest?)

Thanks!

rudgr

# January 23, 2009 10:10 AM

Gjukawa said:

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"

# January 29, 2009 1:58 AM

humlezg said:

rudgr

Yes, the WhoAmIRequest will give the what you are looking for.  Just cradt the request (using the proxy that SL generates) and use the .execute method

# March 2, 2009 8:58 PM

humlezg said:

Gjukawa,

I haven't seen that error before. Sorry :/

# March 2, 2009 8:59 PM

VJ APU said:

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.ClientBase`1.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:

# May 1, 2009 7:16 AM

Mahesh said:

Hi,

After installing the code and ruuing the project i m getting below error:

Sys.InvalidOperationExeption:InitializeError error #2103 in control 'Xaml1' invalid or not well-formed application. check manifest

I have change the URL and Orgarnization name also.

I have updated the service refernce also.

Please let me where i m wrong..

Thanks & Regards,

Mahesh

# May 5, 2009 5:50 AM

humlezg said:

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).

Regards

# May 5, 2009 1:56 PM

humlezg said:

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 info

# May 5, 2009 1:58 PM

Siam4u said:

Most of the time there CRM service reference which i have added is throwing a TIMEOUT Error.

# June 4, 2009 6:07 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker