[英]How to connect to CRM 2015 on-premise from a Siverlight App without depending on the Context?
该代码适用于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.