如何在不依赖上下文的情况下从 Siverlight 应用程序连接到本地 CRM 2015?
How to connect to CRM 2015 on-premise from a Siverlight App without depending on the Context?
我正在创建一个应该从 CRM 检索数据的 Silverlight 应用程序。我尝试了教程 here,但由于调用 GetServerBaseUrl 时上下文无效
,我无法在 Visual Studio 中调试我的应用程序
Uri serviceUrl = CombineUrl(GetServerBaseUrl(), "/XRMServices/2011/Organization.svc/web");
我知道我可以使用连接字符串连接到 CRM,并使用来自 this 问题的 SDK 中的 dll,但是提供的第一个 link 已损坏,我看不到示例.
代码适用于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;
}
}
}
我正在创建一个应该从 CRM 检索数据的 Silverlight 应用程序。我尝试了教程 here,但由于调用 GetServerBaseUrl 时上下文无效
,我无法在 Visual Studio 中调试我的应用程序Uri serviceUrl = CombineUrl(GetServerBaseUrl(), "/XRMServices/2011/Organization.svc/web");
我知道我可以使用连接字符串连接到 CRM,并使用来自 this 问题的 SDK 中的 dll,但是提供的第一个 link 已损坏,我看不到示例.
代码适用于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;
}
}
}