我在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。
所以我不太清楚我該如何解決我的問題。任何人都有解決方案?