繁体   English   中英

如何在不依赖上下文的情况下从Siverlight应用连接到CRM 2015。

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

我正在创建应该从CRM检索数据的Silverlight应用程序。 我在这里尝试了本教程但是由于在调用GetServerBaseUrl时上下文无效,因此无法在Visual Studio中调试应用程序

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

我知道我可以使用连接字符串并使用来自问题的SDK中的dll连接到CRM,但是提供的第一个链接已断开,我看不到示例。

该代码适用于Dynamics CRM 2011,并使用getServerUrl函数。 该功能已被宣布对于CRM 2011已作废,并且已从Dynamics CRM 2015中删除。

幸运的是,您只需要对示例代码进行少量修改:

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);
}

在这里,文字“ getServerUrl”被“ getClientUrl”代替。

除了Henk的答案外,这里还提供了我们使用的函数的修改版本,该函数可与新旧方法一起使用,最终退回到使用硬编码值。 这使我们可以在Visual Studio中进行调试,而不必部署到CRM

public static string GetServerBaseUrl(string FallbackValue = null)
    {


        try
        {
            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 serverUrl;
        }
        catch
        {
            //Try the old getServerUrl
            try
            {
                string serverUrl = (string)GetContext().Invoke("getServerUrl");
                //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 serverUrl;
            }
            catch
            {
                   return FallbackValue;   
            }
        }

    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM