[CRM 2011] Can Silverlight use SOAP or REST out of browser` RRS feed

  • Question

  • Simple question. Is there a way to connect a Silverlight Out of Browser application to either the SOAP or REST service of CRM 2011? I need this application to be run on a tablet in the field outside of the CRM context.
    Monday, August 29, 2011 4:56 PM


All replies

  • It can use SOAP out of browser, but not rest.  You just have to add the service reference and then form up your web service calls.  I recommend looking through my sdk example index for the posts tagged as silverlight to see how the syntax and setup works.

    Link to example index:



    Jamie Miley
    Check out my about.me profile!
    Linked-In Profile
    Follow Me on Twitter!
    Monday, August 29, 2011 5:28 PM
  • Mistafreeze and I are working together on this project, thought I'd drop in and provide a little more detail;


    I have already added the SOAP service reference to my project per this walk through (and it does work, as far as using the sample code which pulls in a list of accounts/entities) 



    Now what we are trying to do is get this to work outside of a CRM form (In an out of browser silveright application) so we need to be able to provide the same context to our application that it receives when it's running as a CRM web service embedded in a CRM form.


    Is there a specific example you can point us to, to do this?



    Monday, August 29, 2011 7:07 PM
  • There are specific functions that exist in there that are problematic because they are looking for the embedded page elements (like Xrm.page) to get information like the server URL and things like that, anything that uses these constructs won't work outside of CRM.  You will have to fill in the information manually that these functions retrieve because you cannot get it directly from the application anymore.  The functions I am aware of that use this are these (but there could be more):




    Jamie Miley
    Check out my about.me profile!
    Linked-In Profile
    Follow Me on Twitter!
    Monday, August 29, 2011 7:16 PM
  • Okay so what you're saying is that instead of having these functions able to retrieve certain information we need to remove them (the functions/methods) and hard code the information in their place? And if that's true, are you aware of any sample/example/blog that might have gone down this road already? We're fairly novice programmers, so anything you can provide is extremely appreciated. Thanks for all your help so far, and the documentation you've included on your blog!
    Monday, August 29, 2011 7:45 PM
  • Since you're not hosting the silverlight in the CRM application, you will probably run into cross-domain issues.  So you will need to put the correct ClientAccessPolicy.xml file on the CRM server. This post describes the clientAccessPolicy file you'll need.

    As for updating the SDK example to work outside of CRM, I think you just need to update the GetSoapService() method to use an absolute URL (instead of getting the URL from the CRM context):

           public static IOrganizationService GetSoapService()
                Uri serviceUrl = new Uri(http://myCrmServerUrl/XRMServices/2011/Organization.svc/web, UriKind.Absolute);

                BasicHttpBinding binding = new BasicHttpBinding(Uri.UriSchemeHttps == serviceUrl.Scheme
                    ? BasicHttpSecurityMode.Transport : BasicHttpSecurityMode.TransportCredentialOnly);
                binding.MaxReceivedMessageSize = int.MaxValue;
                binding.MaxBufferSize = int.MaxValue;
                binding.SendTimeout = TimeSpan.FromMinutes(2);

                return new CrmSdk.OrganizationServiceClient(binding, new EndpointAddress(serviceUrl));

    Erik Pool | Avanade XRM | http://erikpool.blogspot.com
    Monday, August 29, 2011 8:37 PM
  • Thanks for the quick response Erik! (and also thanks for your blog as it's been very helpful in our learning) I have the URL set properly in the application, and we've used your link to create our policy file (and it's now hosted on the CRM server) However, we are still getting an error referencing cross-domain policy issues. here is the error message;



    Exception: An error occurred while trying to make a request to URI 'https://OUR_ORG_URL/XRMServices/2011/Organization.svc/web'. 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. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details.

       at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult 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 DockingTut.CrmSdk.OrganizationServiceClient.OrganizationServiceClientChannel.EndExecute(IAsyncResult result)

       at DockingTut.CrmSdk.OrganizationServiceClient.DockingTut.CrmSdk.IOrganizationService.EndExecute(IAsyncResult result)

       at DockingTut.MainPage.AccountList_ClickCallback(IAsyncResult result)

    Innner Exception: 

       at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)

       at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)

       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)

    Innner Exception: Security error.

       at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)

       at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)

       at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__0(Object sendState)




    I did want to mention that we are set up with claims based authentication for access from outside our network (deployment is on premise). Thoughts?

    Monday, August 29, 2011 8:52 PM
  • Hmm, its probably the claims based authentication that is preventing the connection. 

    Basically, if the silverlight app is hosted inside CRM then it can talk to the CRM web-service regardless of what kind of authentication is used.  Because its on the CRM site then its already been authenticated and all of the necesary authentication headers are automatically added to each request by the browser. 

    If you're not hosting Silverlight insude CRM then you dont get any automatic authentication.  It still works for Active Directory authentication because the browser will just automatically pass the credentials of the logged-in user along with the request.

    For claims-based authentication, I think you would need to handle the authentication programmatically when connecting to CRM, but I am not that familar with how claims-based auth works in CRM. 

    Erik Pool | Avanade XRM | http://erikpool.blogspot.com
    • Proposed as answer by Jim Glass Jr Tuesday, August 30, 2011 4:20 PM
    Monday, August 29, 2011 9:16 PM
  • Thats pretty much the conclusion we've come too. Assuming we can get that issue resolved, it's good to know that SOAP will in fact work outside of the browser. Thanks for the assistance.
    Tuesday, August 30, 2011 3:31 PM
  • Mistafreeze,

    I'd be interested in your conclusions if you work this out. In my case I was trying to create a shared set of data access/business logic code which I could call from Silverlight & .Net/WPF. I managed to achieve that some hacks around namespaces etc.

    However like yourself I would also like to be able to run Silverlight outside of the CRM site for a couple of good reasons: testing & testing !

    Firstly it would be useful for automated unit tests, and secondly it would make development a lot easier  as you wouldn't have to go through the whole build/upload/publish/refresh cycle every time you wanted to see if a change worked.

    I did start looking at what the OrganizationServiceProxy was doing, but it was quite hard to decipher from a decompilation. I suspect there will be lots of nasty SOAP XML involved in getting it running outside of the CRM site. I'm using 2011 Online which means DeviceIds come into somewhere as well (still haven't figured out what use they are given lots of examples seem to suggest creating a temporary one).

    Good luck and let us know if you have any joy.



    Wednesday, August 31, 2011 8:45 AM
  • LJ,

      We also looked into OrganizationServiceProxy, and basically in order to use it you have to be using the XRM binaries which aren't compatible with silverlight 4 (Why not, is what I would like to know!). All of the silverlight examples provided in the SDK are ran within the context of a form or HTML webpage, so are no help either. At this point there doesn't seem to be a solution for getting an out of browser silverlight application able to connect to CRM directly. (at least for a claims based authentication deployment using SOAP for services)

      Our goal is, to create a simple silverlight application that can run without depending on an internet connection that uses CRM as it's back end. We currently have a console application that does this, it's able to save data to a text file when the connection is missing and then loads that information into CRM when the connection returns (It's a tracking application which accesses and saves GPS data to the server/device), however it's using the REST endpoint and connecting through XRM. (If you haven't noticed, CRM offline mode in outlook is very clunky and seems hacked together and we have had nothing but problems trying to use it)

    At this point we are wondering if we're going to have to implement a console application just to move the data around. It would upload to CRM during online periods, and simply use local storage/database to store the data during offline periods, however we are still looking for advice/assistance. Feel free to share your thoughts on the above.

    Wednesday, August 31, 2011 8:15 PM
  • Hi LJ,

    If you just need to run silverlight outside of CRM for testing and to get around the build/upload/publish cycle, you can create a simple SOAP XML proxy that can forward your OrganizationService requests to CRM Online.  I have created a working proof of concept of a proxy here.

    Erik Pool | Avanade XRM | http://erikpool.blogspot.com
    Wednesday, August 31, 2011 8:32 PM
  • Thanks Eric. That's very interesting. Not sure it helps MistaFreeze or with unit testing, but will save me a lot of time nonetheless.
    Thursday, September 1, 2011 8:52 AM
  • @bhsbdemartino

    Unfortunately I'm in the same position so can't offer any real help.

    It's definitely possible to connect to the web service from Silverlight without running in CRM, it's just more complicated than it should be IMHO and I just haven't had time/inclination to look into it in depth. Personally I think the whole authentication process for CRM (online) is a bit overcomplicated.

    I do have an MS Connect open asking them to port at least some of the SDK to Silverlight, might be worth a vote:





    Thursday, September 1, 2011 9:01 AM