如何使用SOAP调用设置电子邮件对象的状态和状态?

如何使用SOAP调用设置电子邮件对象的状态和状态?,soap,dynamics-crm-4,Soap,Dynamics Crm 4,我真的在努力解决这个问题。我在网上搜索了一些关于如何设置对象的状态和状态的例子,但是没有一个对我有用 有没有人举过一些例子来说明soap信封的外观,以及Msxml2.XMLHTTP对象的属性对于web服务的同步调用应该是什么 提前感谢,, 灰色的 编辑 好的。。。所以出于一个无法解释的原因,我在这个问题上投了反对票,但没有回答,所以我想我会描述一下我现在得到了什么,我得到了什么 这是主要功能(相当于从我发现的一个示例中提取): function setStateCodeForEntity(en

我真的在努力解决这个问题。我在网上搜索了一些关于如何设置对象的状态和状态的例子,但是没有一个对我有用

有没有人举过一些例子来说明soap信封的外观,以及Msxml2.XMLHTTP对象的属性对于web服务的同步调用应该是什么

提前感谢,, 灰色的

编辑

好的。。。所以出于一个无法解释的原因,我在这个问题上投了反对票,但没有回答,所以我想我会描述一下我现在得到了什么,我得到了什么

这是主要功能(相当于从我发现的一个示例中提取):

 function setStateCodeForEntity(entityName, entityId, stateOptionsetValue, statusOptionsetValue) {


    var request = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
    request += "<s:Body>";
    request += "<Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
    request += "<request i:type=\"b:SetStateRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">";
    request += "<a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
    request += "<a:KeyValuePairOfstringanyType>";
    request += "<c:key>EntityMoniker</c:key>";
    request += "<c:value i:type=\"a:EntityReference\">";
    request += "<a:Id>" + entityId + "</a:Id>";
    request += "<a:LogicalName>" + entityName + "</a:LogicalName>";
    request += "<a:Name i:nil=\"true\" />";
    request += "</c:value>";
    request += "</a:KeyValuePairOfstringanyType>";
    request += "<a:KeyValuePairOfstringanyType>";
    request += "<c:key>State</c:key>";
    request += "<c:value i:type=\"a:OptionSetValue\">";
    request += "<a:Value>"+stateOptionsetValue+"</a:Value>";
    request += "</c:value>";
    request += "</a:KeyValuePairOfstringanyType>";
    request += "<a:KeyValuePairOfstringanyType>";
    request += "<c:key>Status</c:key>";
    request += "<c:value i:type=\"a:OptionSetValue\">";
    request += "<a:Value>"+statusOptionsetValue+"</a:Value>";
    request += "</c:value>";
    request += "</a:KeyValuePairOfstringanyType>";
    request += "</a:Parameters>";
    request += "<a:RequestId i:nil=\"true\" />";
    request += "<a:RequestName>SetState</a:RequestName>";
    request += "</request>";
    request += "</Execute>";
    request += "</s:Body>";
    request += "</s:Envelope>";

var ret = executeSoapRequest("execute", request);
}

我已经尝试通过调用调用顶部描述的方法(注意,newGuid是在其他地方分配的,并且包含我希望为其设置状态/状态的新电子邮件记录的Guid):

我得到的是服务器500错误,响应如下:

"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"/>\r\n<title>500 - Internal server error.</title>\r\n<style type=\"text/css\">\r\n<!--\r\nbody{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}\r\nfieldset{padding:0 15px 10px 15px;} \r\nh1{font-size:2.4em;margin:0;color:#FFF;}\r\nh2{font-size:1.7em;margin:0;color:#CC0000;} \r\nh3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} \r\n#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:\"trebuchet MS\", Verdana, sans-serif;color:#FFF;\r\nbackground-color:#555555;}\r\n#content{margin:0 0 0 2%;position:relative;}\r\n.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}\r\n-->\r\n</style>\r\n</head>\r\n<body>\r\n<div id=\"header\"><h1>Server Error</h1></div>\r\n<div id=\"content\">\r\n <div class=\"content-container\"><fieldset>\r\n  <h2>500 - Internal server error.</h2>\r\n  <h3>There is a problem with the resource you are looking for, and it cannot be displayed.</h3>\r\n </fieldset></div>\r\n</div>\r\n</body>\r\n</html>\r\n<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><soap:Fault><faultcode>Server</faultcode><faultstring>Object reference not set to an instance of an object.</faultstring><detail><error xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><displaytitle /><displaytext /><description>Object reference not set to an instance of an object.</description><file>Not available</file><line>Not available</line><details>Not available</details><requesturl>http://[SERVERNAME]/mscrmservices/2007/CrmService.asmx</requesturl><pathAndQuery>/mscrmservices/2007/CrmService.asmx</pathAndQuery><source>SOAP</source><stacktrace /></error></detail></soap:Fault></soap:Body></soap:Envelope>"
"\r\n\r\n\r\n\r\n500-内部服务器错误。\r\n\r\n\r\n\r\n\r\n\r\n服务器错误\r\n\r\n 500-内部服务器错误。\r\n正在查找的资源有问题,无法显示。\r\n\r\n\r\n\r\n\r\n服务器对象引用未设置为对象的实例。对象引用未设置为对象的实例。否t availableNot availableNot availablehttp://[SERVERNAME]/mscrmservices/2007/CrmService.asmx/mscrmservices/2007/CrmService.asmxSOAP“
然而

我刚刚注意到,当我使用executeSoapRequest方法成功时,我得到了一个非常相似的响应Text。当我按照上述方式进行调用时,电子邮件实体的状态没有改变

我几乎肯定在做一些愚蠢的事情,但我不知道是什么。任何有建设性的帮助在这个时候都会是救命稻草


格雷

好的……为了完整起见,以下是答案:

主要功能如下所示:

function executeSoapRequest(action, xml) {
var actionUrl = "http://schemas.microsoft.com/crm/2007/WebServices/" + action;

var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction", actionUrl);
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);

return xmlHttpRequest.responseXML;
function setStateCodeForEntity(entityName, entityId, stateOptionsetValue, statusOptionsetValue) {

    var request = [
        "<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(),
        "<soap:Body>",
        "<Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>", 
        "<Request xsi:type='SetStateDynamicEntityRequest'>",
        "<Entity>",
        "<Name xmlns='http://schemas.microsoft.com/crm/2006/CoreTypes'>", entityName, "</Name>",
        "<Id xmlns='http://schemas.microsoft.com/crm/2006/CoreTypes'>", entityId, "</Id>",
        "</Entity>",
        "<State>", stateOptionsetValue, "</State>",
        "<Status>", statusOptionsetValue, "</Status>",
        "</Request>",
        "</Execute>",
        "</soap:Body>",
        "</soap:Envelope>"
        ].join("");

        var ret = executeSoapRequest("Execute", request);
 }
我的一位同事给了我答案,他推荐了Crm服务工具包(),代码基本上就是从那里提出来的

"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"/>\r\n<title>500 - Internal server error.</title>\r\n<style type=\"text/css\">\r\n<!--\r\nbody{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}\r\nfieldset{padding:0 15px 10px 15px;} \r\nh1{font-size:2.4em;margin:0;color:#FFF;}\r\nh2{font-size:1.7em;margin:0;color:#CC0000;} \r\nh3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} \r\n#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:\"trebuchet MS\", Verdana, sans-serif;color:#FFF;\r\nbackground-color:#555555;}\r\n#content{margin:0 0 0 2%;position:relative;}\r\n.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}\r\n-->\r\n</style>\r\n</head>\r\n<body>\r\n<div id=\"header\"><h1>Server Error</h1></div>\r\n<div id=\"content\">\r\n <div class=\"content-container\"><fieldset>\r\n  <h2>500 - Internal server error.</h2>\r\n  <h3>There is a problem with the resource you are looking for, and it cannot be displayed.</h3>\r\n </fieldset></div>\r\n</div>\r\n</body>\r\n</html>\r\n<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><soap:Fault><faultcode>Server</faultcode><faultstring>Object reference not set to an instance of an object.</faultstring><detail><error xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><displaytitle /><displaytext /><description>Object reference not set to an instance of an object.</description><file>Not available</file><line>Not available</line><details>Not available</details><requesturl>http://[SERVERNAME]/mscrmservices/2007/CrmService.asmx</requesturl><pathAndQuery>/mscrmservices/2007/CrmService.asmx</pathAndQuery><source>SOAP</source><stacktrace /></error></detail></soap:Fault></soap:Body></soap:Envelope>"
function setStateCodeForEntity(entityName, entityId, stateOptionsetValue, statusOptionsetValue) {

    var request = [
        "<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(),
        "<soap:Body>",
        "<Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>", 
        "<Request xsi:type='SetStateDynamicEntityRequest'>",
        "<Entity>",
        "<Name xmlns='http://schemas.microsoft.com/crm/2006/CoreTypes'>", entityName, "</Name>",
        "<Id xmlns='http://schemas.microsoft.com/crm/2006/CoreTypes'>", entityId, "</Id>",
        "</Entity>",
        "<State>", stateOptionsetValue, "</State>",
        "<Status>", statusOptionsetValue, "</Status>",
        "</Request>",
        "</Execute>",
        "</soap:Body>",
        "</soap:Envelope>"
        ].join("");

        var ret = executeSoapRequest("Execute", request);
 }
setStateCodeForEntity("email", newGuid, 'Completed', 2);