发布于 2015-05-07 12:15:46
该代码适用于Dynamics 2011,并使用函数getServerUrl。该功能已被宣布为2011年CRM的过时功能,并已从Dynamics 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”取代。
发布于 2015-05-08 08:18:49
除了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;
}
}
}https://stackoverflow.com/questions/30099865
复制相似问题