Search code examples
c#silverlightdynamics-crm-2015

How to connect to CRM 2015 on-premise from a Siverlight App without depending on the Context?


I'm creating a Silverlight application that should retrieve data from the CRM. I tried the tutorial here but I failed to debug my application in Visual Studio due to the invalidity of the Context when GetServerBaseUrl is called

Uri serviceUrl = CombineUrl(GetServerBaseUrl(), "/XRMServices/2011/Organization.svc/web");

I understand that I can connect to the CRM using a connection string and using dlls from the SDK from this question, however the first link provided is broken and i can't see examples.


Solution

  • The code applies to Dynamics CRM 2011 and uses function getServerUrl. The function was declared obsolete for CRM 2011 already and has been removed from Dynamics CRM 2015.

    Luckily you only have to make a small modification to the sample code:

    public static Uri GetServerBaseUrl()
    {
        string serverUrl = (string)GetContext().Invoke("getClientUrl");
        //Remove the trailing forwards slash returned by CRM Online
        //So that it is always consistent with CRM On Premises
        if (serverUrl.EndsWith("/"))
            serverUrl = serverUrl.Substring(0, serverUrl.Length - 1);
    
        return new Uri(serverUrl);
    }
    

    Here the literal "getServerUrl" was replaced by "getClientUrl".