CRM:SOAP:ExecuteWorkflowRequest 错误
CRM : SOAP : Error in ExecuteWorkflowRequest
我想使用 SOAP 执行工作流。我已经用谷歌搜索了所有内容并尝试了不同的方法。但是 none 我的代码有效。例如,两个最最终的变体是:
2011 年服务
function RunWorkflow() {
var url = Xrm.Page.context.getServerUrl() + "/XRMServices/2011/Organization.svc/web";
var requestMain = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"> <s:Body>";
requestMain += " <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
requestMain += " <request i:type=\"b:ExecuteWorkflowRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">";
requestMain += " <a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>EntityId</c:key>";
requestMain += " <c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">B8373961-D084-E611-8763-005056810E95</c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>WorkflowId</c:key>";
requestMain += " <c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">191CDD5A-3EBD-40FD-A685-B79D99B32831</c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " </a:Parameters>";
requestMain += " <a:RequestId i:nil=\"true\" />";
requestMain += " <a:RequestName>ExecuteWorkflow</a:RequestName>";
requestMain += " </request>";
requestMain += " </Execute>";
requestMain += " </s:Body>";
requestMain += "</s:Envelope>";
var req = new XMLHttpRequest();
req.open("POST", url, true);
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(requestMain);
function assignResponse(req) {
if (req.readyState == 4)
if (req.status == 200)
alert('successfully executed the workflow');
}
}
2007 年服务
function RunWorkflowSeven() {
var url = Xrm.Page.context.getServerUrl() + "/MSCRMservices/2007/CrmServiceWsdl.aspx";
var soapBody = "<s:Envelope><soap:Body>" +
" <Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
" <Request xsi:type=\'ExecuteWorkflowRequest\'>" +
" <EntityId>B8373961-D084-E611-8763-005056810E95</EntityId>" +
" <WorkflowId>191CDD5A-3EBD-40FD-A685-B79D99B32831</WorkflowId>" +
" </Request>" + " </Execute>" + "</soap:Body>";
var soapXml = "<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() + soapBody + "</soap:Envelope>";
var req = new XMLHttpRequest();
req.open("POST", url, false);
req.setRequestHeader("Accept", "application/xml, text/xml, */*");
req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Execute");
req.onreadystatechange = function () { assignResponse(req); };
req.send(soapXml);
function assignResponse(req) {
if (req.readyState == 4)
if (req.status == 200)
alert('successfully executed the workflow');
}
}
第一个给我一个错误“400:错误的请求”,
2011 年的其他变体(请求 '/XRMServices/2011/Organization.svc/' 而不是 '/XRMServices/2011/Organization.svc/web' 给出 '无法处理消息,因为内容类型 'text/xml; charset=utf-8' 不是预期的类型 'application/soap+xml; charset=utf-8'),
第二个在控制台中没有显示错误,但它没有 运行 工作流程。
对不起这么大的代码,但我真的不知道问题出在哪里。
更新 1:
Fiddler 显示 3 个请求,状态如下:
- HTTP 错误 401 - 未经授权:访问被拒绝
- HTTP 错误 401。请求的资源需要用户身份验证。
- 请求错误
我相信您在第一个请求中错过了一个节点。尝试替换
var requestMain = " <s:Body>";
和
var requestMain = "<s:Envelope><s:Body>";
我想使用 SOAP 执行工作流。我已经用谷歌搜索了所有内容并尝试了不同的方法。但是 none 我的代码有效。例如,两个最最终的变体是: 2011 年服务
function RunWorkflow() {
var url = Xrm.Page.context.getServerUrl() + "/XRMServices/2011/Organization.svc/web";
var requestMain = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"> <s:Body>";
requestMain += " <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
requestMain += " <request i:type=\"b:ExecuteWorkflowRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">";
requestMain += " <a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>EntityId</c:key>";
requestMain += " <c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">B8373961-D084-E611-8763-005056810E95</c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>WorkflowId</c:key>";
requestMain += " <c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">191CDD5A-3EBD-40FD-A685-B79D99B32831</c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " </a:Parameters>";
requestMain += " <a:RequestId i:nil=\"true\" />";
requestMain += " <a:RequestName>ExecuteWorkflow</a:RequestName>";
requestMain += " </request>";
requestMain += " </Execute>";
requestMain += " </s:Body>";
requestMain += "</s:Envelope>";
var req = new XMLHttpRequest();
req.open("POST", url, true);
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(requestMain);
function assignResponse(req) {
if (req.readyState == 4)
if (req.status == 200)
alert('successfully executed the workflow');
}
}
2007 年服务
function RunWorkflowSeven() {
var url = Xrm.Page.context.getServerUrl() + "/MSCRMservices/2007/CrmServiceWsdl.aspx";
var soapBody = "<s:Envelope><soap:Body>" +
" <Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
" <Request xsi:type=\'ExecuteWorkflowRequest\'>" +
" <EntityId>B8373961-D084-E611-8763-005056810E95</EntityId>" +
" <WorkflowId>191CDD5A-3EBD-40FD-A685-B79D99B32831</WorkflowId>" +
" </Request>" + " </Execute>" + "</soap:Body>";
var soapXml = "<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() + soapBody + "</soap:Envelope>";
var req = new XMLHttpRequest();
req.open("POST", url, false);
req.setRequestHeader("Accept", "application/xml, text/xml, */*");
req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Execute");
req.onreadystatechange = function () { assignResponse(req); };
req.send(soapXml);
function assignResponse(req) {
if (req.readyState == 4)
if (req.status == 200)
alert('successfully executed the workflow');
}
}
第一个给我一个错误“400:错误的请求”,
2011 年的其他变体(请求 '/XRMServices/2011/Organization.svc/' 而不是 '/XRMServices/2011/Organization.svc/web' 给出 '无法处理消息,因为内容类型 'text/xml; charset=utf-8' 不是预期的类型 'application/soap+xml; charset=utf-8'),
第二个在控制台中没有显示错误,但它没有 运行 工作流程。
对不起这么大的代码,但我真的不知道问题出在哪里。
更新 1: Fiddler 显示 3 个请求,状态如下:
- HTTP 错误 401 - 未经授权:访问被拒绝
- HTTP 错误 401。请求的资源需要用户身份验证。
- 请求错误
我相信您在第一个请求中错过了一个节点。尝试替换
var requestMain = " <s:Body>";
和
var requestMain = "<s:Envelope><s:Body>";