【问题标题】:CRM Authentication issueCRM 身份验证问题
【发布时间】:2012-08-29 11:42:00
【问题描述】:

如何在 JavaScript 中包含 GenerateAuthenticationHeader()。我需要包含哪些必要的 DLL?我正在使用此函数使用 JavaScript 检索 MS CRM 实体。我收到此错误:

Microsoft JScript 运行时错误:“GenerateAuthenticationHeader”未定义

function AccessCRMWebServices() {
        debugger;
        var auth = GenerateAuthenticationHeader();
                    var productCode = "ABCDE";
                    var stock;
                    var x = Xrm.Page.getAuthenticationHeader();
                    var fetchXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical">';
                    // Target Entity Name
                    fetchXml += '<entity name="new_aditya_products">';
                    // Required Attribute
                    fetchXml += '<attribute name="new_productname"/>';
                    fetchXml += '<attribute name="new_name"/>';
                    // Condition
                    fetchXml += '<filter type="and">';
                    fetchXml += '<condition attribute="new_productcode" operator="eq" value="' + productCode + '" />';
                    fetchXml += '</filter>';

                    fetchXml += '</entity>';
                    fetchXml += '</fetch>';

                    var Xml = "<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\">"
                    Xml += GenerateAuthenticationHeader()
                    Xml += "<soap:Body>";
                    Xml += "<Fetch xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">";
                    Xml += "<fetchXml>";
                    //Xml += _HtmlEncode(fetchXml);
                    Xml += "</fetchXml>";
                    Xml += "</Fetch>";
                    Xml += "</soap:Body>";
                    Xml += "</soap:Envelope>";

                    var XmlHttp = CreateXmlHttp();

                    XmlHttp.open("POST", 'http://rxdotnet:5555/MSCRMServices/2007/MetadataService.asmx', false);
                    XmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
                    XmlHttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Fetch");
                    XmlHttp.send(Xml);
                    var resultDoc = loadXmlDocument(XmlHttp.responseXML.text);
                    var resultRecords = resultDoc.selectNodes("//stockvolume");
                    var resultnames = resultDoc.selectNodes("//new_name");
                    if (resultRecords.length == 1) {
                        stock = resultRecords[0].text;
                        alert('Product ' + resultnames[0].text + ' Contains stock is -' + stock);
                    }

【问题讨论】:

    标签: javascript dynamics-crm


    【解决方案1】:

    我假设您使用的是 MS CRM 4.0 版

    GenerateAuthenticationHeader 函数只能在表单代码中本地使用(它是 SDK 中记录的全局函数)。我相信不支持在任何其他情况下使用它。这就是您收到错误的原因。

    根据SDK,它所做的只是创建一个如下所示的 SOAP 标头(因此也许您可以在代码中重新创建它):

    <soap:Header>
    <CrmAuthenticationToken xmlns="http://schemas.microsoft.com/crm/2007/WebServices">
      <AuthenticationType xmlns="http://schemas.microsoft.com/crm/2007/CoreTypes">
        0
      </AuthenticationType>
      <OrganizationName xmlns="http://schemas.microsoft.com/crm/2007/CoreTypes">
        AdventureWorksCycle
      </OrganizationName>
      <CallerId xmlns="http://schemas.microsoft.com/crm/2007/CoreTypes">
        00000000-0000-0000-0000-000000000000
      </CallerId>
    </CrmAuthenticationToken>
    </soap:Header>
    

    除此之外,可能还有其他解决方案。你想做什么,你的代码在哪里运行?

    【讨论】:

    • 如果不知道“您要做什么以及您的代码在哪里运行?”,我无法回答这个问题。 ;-)
    • 我的代码在 aspx 页面中。其实我想通过javascript访问所有MS CRM实体,然后从javascript对实体执行CRUD操作。
    • 查看 SDK 章节 Accessing Web Services in JScript,它描述了从代码访问 CRM Web 服务,此外还有 the start of this index 章节中的 CRUD 操作。请记住,上述函数不可访问,因此您需要创建自己的函数来返回我粘贴的 XML(用正确的值填充!)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-23
    • 2015-08-25
    • 2010-11-17
    • 2019-06-19
    相关资源
    最近更新 更多