GenerateAuthenticationHeader() 在 CRM 2013 中不起作用?

GenerateAuthenticationHeader() does not work in CRM 2013?

我们正在将 CRM 2011 升级到 CRM 2013。自定义代码验证工具标记了方法:GenerateAuthenticationHeader()

问题是我将如何替换此方法以使其在 CRM 2013 中工作。因为当我 运行 它时它给了我 "undefined"。

我查了很多资料。一个网站说使用 SDK REST,但它没有提供适当的信息。

如果您能告诉我如何替换方法GenerateAuthenticationHeader(),我们将不胜感激。

代码如下:

function GetAttributeValueFromID(sEntityName, sGUID, sAttributeName, isTextField)
{

var xml = "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + GenerateAuthenticationHeader() +
"  <soap:Body>" +
"    <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
"      <Request xsi:type=\"RetrieveRequest\" ReturnDynamicEntities=\"false\">" +
"        <Target xsi:type=\"TargetRetrieveDynamic\">" +
"          <EntityName>" + sEntityName + "</EntityName>" +
"          <EntityId>" + sGUID + "</EntityId>" +
"        </Target>" +
"        <ColumnSet xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:ColumnSet\">" +
"          <q1:Attributes>" +
"            <q1:Attribute>" + sAttributeName + "</q1:Attribute>" +
"          </q1:Attributes>" +
"        </ColumnSet>" +
"      </Request>" +
"    </Execute>" +
"  </soap:Body>" +
"</soap:Envelope>" + "";

var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);

xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Execute");

xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

xmlHttpRequest.setRequestHeader("Content-Length", xml.length);

xmlHttpRequest.send(xml);

var result = null;

if (isTextField)
{
    result = xmlHttpRequest.responseXML.selectSingleNode("//q1:" + sAttributeName).text;

}
else
{

    result = xmlHttpRequest.responseXML.selectSingleNode("//q1:" + sAttributeName).getAttribute('name');

}
if (result == null)
{
    return '';
}
else
    return result;

}

GenerateAuthenticationHeader() 从 2013 年开始弃用。您必须使用 OData 端点重写代码(仅供参考 - 此端点在 REST Web API 之后的 Dynamics 365 v9 中也已弃用 API)

There is no need to have this function anymore because 2007 endpoint is not available anymore. To get information you will have to use Organization.svc or OrganizationData.svc endpoints. Check following article - http://msdn.microsoft.com/en-us/library/gg490659.aspx

Reference

Each of these web services can use the authentication provided by the Microsoft Dynamics 365 application within web resources without the need to include any code to implement authentication.

更新:

Download & import CRM REST Builder - 这是一个托管解决方案,可以在 CRM 中导入并用于 build/test 查询。

示例请求 URI 如下,您可以对其进行参数化。

var oDataURI = Xrm.Page.context.getClientUrl()
       + "/XRMServices/2011/OrganizationData.svc/"
       + "AccountSet(guid'" + accountId + "')"
       + "?$select="
       + "Address1_PostalCode";

Learn more