2016-03-07 114 views
0

我在CRM 2015 Online enivronment中工作。我試圖從HTML Webressource觸發CRM工作流程。 HTML Webressource由JavaScript Webressource打開。XMLHttpRequest失敗,錯誤代碼415:無法處理消息

我的問題:運行下面的代碼後,我收到此錯誤信息: 無法加載資源:服務器與415(狀態響應無法處理消息,因爲內容類型「文本/ XML的,字符集= UTF-8' 是不是預期的類型 '應用程序/肥皂+ xml的;字符集= 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(其預計 應用/肥皂+ XML)和在客戶端的版本不匹配使用SOAP 1.1 (它發送文/ XML)。 WSHttpBinding使用SOAP 1.2,BasicHttpBinding 使用SOAP 1.1。

所以我不太清楚我該如何解決我的問題。任何人都有解決方案?

回答

0

雖然看起來您的網絡代碼是copy/pasted,但您也對其進行了一些細微更改:您從Organization.svc URL的末尾刪除了/ web。理解這兩者之間是有區別的,這很重要。

MSDN解釋Use the Modern app SOAP endpoint for modern applications with web resources的區別:

不像REST端點的網絡資源,SOAP端點使用 組織服務。這是在編寫 應用程序時使用的相同服務,該應用程序存在於Microsoft Dynamics CRM 2015 應用程序之外。區別是:

  • 請求被髮送到不同的 網址:/XRMServices/2011/Organization.svc/web。
相關問題