【问题标题】:How do you set the state and status of an email object using a SOAP call?如何使用 SOAP 调用设置电子邮件对象的状态和状态?
【发布时间】:2015-01-08 17:37:16
【问题描述】:

我真的很难解决这个问题。我在网上搜索并找到了一些关于如何设置对象的状态和状态的示例,但它们似乎都不适合我。

谁有一些示例说明肥皂信封的外观以及 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);

}

executeSoapRequest 函数如下所示:

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;

}

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

setStateCodeForEntity("email", newGuid, 1, 2);

setStateCodeForEntity("email", newGuid, "Completed", 2);

我得到的是服务器 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>"

然而……

我刚刚注意到,当我使用成功的 executeSoapRequest 方法时,我得到了一个非常相似的 responseText。当我如上所述拨打电话时,电子邮件实体的状态没有改变。

我几乎可以肯定在做一些愚蠢的事情,但我不知道是什么。此时,任何建设性的帮助都可以挽救生命。

灰色

【问题讨论】:

    标签: soap dynamics-crm-4


    【解决方案1】:

    好的...为了完整起见,这是答案:

    主函数如下所示:

    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);
     }
    

    请注意,请求类型是“SetStateDynamicEntityRequest”,这似乎是我最初尝试的主要问题,但这个版本比我最初使用的要简单得多。

    方法被调用

    setStateCodeForEntity("email", newGuid, 'Completed', 2);
    

    一位推荐 Crm Service Toolkit (http://crmtoolkit.codeplex.com/) 的同事给了我答案,并且代码几乎是从那里提取的。更多信息http://danielcai.blogspot.co.uk/2010/07/crm-web-service-toolkit-for-javascript.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-27
      • 2019-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-19
      相关资源
      最近更新 更多