XMLHttpRequest失败,错误代码为415:无法处理消息

时间:2016-03-07 14:29:45

标签: javascript soap dynamics-crm-2015

我正在CRM 2015 Online enivronment工作。我试图从HTML Webressource触发CRM工作流程。 HTML Webressource由JavaScript Webressource打开。

我的问题:运行以下代码后,我收到此错误消息: 无法加载资源:服务器响应状态为415(无法处理邮件,因为内容类型' text / xml; charset = UTF-8'不是预期的类型' application / soap + xml; charset = utf-8'。)

这是我的代码:

function runWorkflow()
{
    var entityId = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"; //Guid of record that workflow is to run on.
    var workflowId = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"; //Workflow Guid.
    var url = window.parent.Xrm.Page.context.getClientUrl();

    var OrgServicePath = "/XRMServices/2011/Organization.svc";
    url = url + OrgServicePath;
    var request;
    request = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
    "<s:Body>" +
    "<Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">" +
      "<request i:type=\"b:ExecuteWorkflowRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">" +
        "<a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">" +
          "<a:KeyValuePairOfstringanyType>" +
            "<c:key>EntityId</c:key>" +
            "<c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">" + entityId + "</c:value>" +
          "</a:KeyValuePairOfstringanyType>" +
          "<a:KeyValuePairOfstringanyType>" +
            "<c:key>WorkflowId</c:key>" +
            "<c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">" + workflowId + "</c:value>" +
          "</a:KeyValuePairOfstringanyType>" +
        "</a:Parameters>" +
        "<a:RequestId i:nil=\"true\" />" +
        "<a:RequestName>ExecuteWorkflow</a:RequestName>" +
      "</request>" +
    "</Execute>" +
    "</s:Body>" +
    "</s:Envelope>";

    var req = new XMLHttpRequest();
    req.open("POST", url, true)
    // Responses will return XML. It isn't possible to return JSON.
    req.setRequestHeader("Accept", "application/xml, text/xml, */*");
    req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
    req.onreadystatechange = function () { assignResponse(req); };
    req.send(request);
}

在我做了一些研究之后,我找到了以下文字:

  

这通常是客户端/服务器绑定不匹配的地方   服务中的消息版本使用SOAP 1.2(期望   application / soap + xml),客户端中的版本使用SOAP 1.1   (发送text / xml)。 WSHttpBinding使用SOAP 1.2,BasicHttpBinding   使用SOAP 1.1。

所以我不太确定如何解决我的问题。有人有解决方案吗?

1 个答案:

答案 0 :(得分:0)

虽然您似乎是copy/pasted来自互联网的代码,但您还对其进行了一些细微的更改:您从Organization.svc网址的末尾删除了/ web。重要的是要理解两者之间存在差异。

MSDN解释了Use the Modern app SOAP endpoint for modern applications with web resources

的区别
  

与Web资源的REST端点不同,SOAP端点使用   组织服务。这与写入时使用的服务相同   存在于Microsoft Dynamics CRM 2015之外的应用程序   应用。不同之处是:

     
      
  • 将请求发送给其他人   网址:/XRMServices/2011/Organization.svc/web。
  •