Dynamics crm 2011 CRM 2013:从javascript调用操作
我试图使用以下函数从javascript调用操作:Dynamics crm 2011 CRM 2013:从javascript调用操作,dynamics-crm-2011,dynamics-crm,crm,Dynamics Crm 2011,Dynamics Crm,Crm,我试图使用以下函数从javascript调用操作: function ExecuteActionCreateProject(reason, entityId, entityName, requestName) { // Creating the request XML for calling the Action var requestXML = "" requestXML += "<s:Envelope xmlns:s=\"http://schemas.xmlso
function ExecuteActionCreateProject(reason, entityId, entityName, requestName)
{
// Creating the request XML for calling the Action
var requestXML = ""
requestXML += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
requestXML += " <s:Body>";
requestXML += " <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
requestXML += " <request xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
requestXML += " <a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
requestXML += " <a:KeyValuePairOfstringanyType>";
requestXML += " <b:key>Reason</b:key>";
requestXML += " <b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">"+reason+"</b:value>";
requestXML += " </a:KeyValuePairOfstringanyType>";
requestXML += " <a:KeyValuePairOfstringanyType>";
requestXML += " <b:key>Target</b:key>";
requestXML += " <b:value i:type=\"a:EntityReference\">";
requestXML += " <a:Id>"+entityId+"</a:Id>";
requestXML += " <a:LogicalName>"+entityName+"</a:LogicalName>";
requestXML += " <a:Name i:nil=\"true\" />";
requestXML += " </b:value>";
requestXML += " </a:KeyValuePairOfstringanyType>";
requestXML += " </a:Parameters>";
requestXML += " <a:RequestId i:nil=\"true\" />";
requestXML += " <a:RequestName>"+requestName+"</a:RequestName>";
requestXML += " </request>";
requestXML += " </Execute>";
requestXML += " </s:Body>";
requestXML += "</s:Envelope>";
var req = new XMLHttpRequest();
req.open("POST", GetClientUrl(), false)
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/IOrganizationServic/Execute");
req.send(requestXML);
//Get the Resonse from the CRM Execute method
var response = req.responseXML.xml;
}
函数ExecuteActionCreateProject(原因、entityId、entityName、requestName)
{
//创建用于调用操作的请求XML
var requestXML=“”
requestXML+=“”;
requestXML+=“”;
requestXML+=“”;
requestXML+=“”;
requestXML+=“”;
requestXML+=“”;
requestXML+=“原因”;
requestXML+=“”+原因+“”;
requestXML+=“”;
requestXML+=“”;
requestXML+=“目标”;
requestXML+=“”;
requestXML+=“”+entityId+“”;
requestXML+=“”+entityName+“”;
requestXML+=“”;
requestXML+=“”;
requestXML+=“”;
requestXML+=“”;
requestXML+=“”;
requestXML+=“”+requestName+“”;
requestXML+=“”;
requestXML+=“”;
requestXML+=“”;
requestXML+=“”;
var req=新的XMLHttpRequest();
请求打开(“POST”,GetClientUrl(),false)
setRequestHeader(“接受”、“应用程序/xml、文本/xml、*/*”);
请求setRequestHeader(“内容类型”,“文本/xml;字符集=utf-8”);
请求setRequestHeader(“SOAPAction”http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationServic/Execute");
请求发送(requestXML);
//从CRM执行方法获取响应
var response=req.responseXML.xml;
}
我能够成功地传递函数参数和客户端URL,但我得到的响应如下:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:ActionNotSupported</faultcode>
<faultstring xml:lang="en-US">The message with Action 'http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationServic/Execute' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).
</faultstring>
</s:Fault>
</s:Body>
</s:Envelope>
答:行动不受支持
带行动的信息'http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationServic/Execute由于EndpointDispatcher上的ContractFilter不匹配,无法在接收器上处理。这可能是因为合同不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息、传输、无)。
请告知该功能看起来正常。我看不到实际调用,因此在发送请求之前,请确保所有值都已正确编码。 MS使用以下示例对值进行编码。 就我个人而言,我会用数组缓冲区替换XmlEncode值的串联(字符串缓冲区),以提高性能
function loadAction() {
var reason = XmlEncode("custom string");
var entityId = XmlEncode(Xrm.Page.data.entity.getId());
var entityName = "serviceappointment";
var requestName = "new_entityname";
//call function with encoded values ...
ExecuteActionCreateProject(reason, entityId, entityName, requestName);
}
XmlEncode = function (strInput) {
var c, XmlEncode = '';
if (strInput == null) { return null; }
if (strInput == '') { return ''; }
for (var cnt = 0; cnt < strInput.length; cnt++) {
c = strInput.charCodeAt(cnt);
if (((c > 96) && (c < 123)) ||
((c > 64) && (c < 91)) ||
(c == 32) ||
((c > 47) && (c < 58)) ||
(c == 46) ||
(c == 44) ||
(c == 45) ||
(c == 95)) {
XmlEncode = XmlEncode + String.fromCharCode(c);
}
else {
XmlEncode = XmlEncode + '&#' + c + ';';
}
}
return XmlEncode;
}
函数loadAction(){
var reason=XmlEncode(“自定义字符串”);
var entityId=XmlEncode(Xrm.Page.data.entity.getId());
var entityName=“serviceappointment”;
var requestName=“new\u entityname”;
//使用编码值调用函数。。。
ExecuteActionCreateProject(原因、entityId、entityName、requestName);
}
XmlEncode=函数(strInput){
变量c,XmlEncode='';
如果(strInput==null){return null;}
if(strInput=''){return';}
对于(var cnt=0;cnt96)&(c<123))||
((c>64)和(c<91))||
(c==32)||
((c>47)和(c<58))||
(c==46)||
(c==44)||
(c==45)||
(c==95)){
XmlEncode=XmlEncode+String.fromCharCode(c);
}
否则{
XmlEncode=XmlEncode+''+c+'';
}
}
返回xmlcode;
}
尝试使用我开发的助手框架-打字错误
req.setRequestHeader(“SOAPAction”,
"http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationServic/Execute");
“iOrganizationService”需要附加一个“e”
您正在使用SOAPLogger吗?很抱歉,我不知道如何使用您的代码使我的代码正确运行请解释更多。附加值是什么?这将如何使其工作?无法说明这是否是导致问题的原因,但很明显,您缺少xml编码,需要排除此选项。我认为传递给函数的请求名称参数不匹配。您试图执行什么请求?是“创造”吗?如果是这样,那么requestName应该等于“Create”,而不是实体名。我正在尝试执行一个操作,所以我将操作名传递给requestName参数。