【问题标题】:MoveItem Invalid RequestMoveItem 无效请求
【发布时间】:2021-09-30 23:31:42
【问题描述】:

我正在尝试使用 EWS MoveItem XML 请求删除项目。我正在将此请求发送到 makeEwsRequestAsync 函数:

function getMoveItemRequest(id, changeKey) {

    var result =
        '<?xml version="1.0" encoding="utf-8"?>' +
        '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">' +
        '<soap:Header>' +
        '<RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' +
        '</soap:Header>' +
        '<soap:Body>' +
        '<MoveItem xmlns="https://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">' +
            '<ToFolderId>' +
                '<t:DistinguishedFolderId Id="deleteditems" />' +
            '</ToFolderId>' +
            '<ItemIds>' +
                '<t:ItemId Id="' + id + '" ChangeKey="' + changeKey + '" />' +
            '</ItemIds>' +
        '</MoveItem>' +
        '</soap:Body>' +
        '</soap:Envelope>';

    return result;
}

我从这样的消息中获取项目 ID:

Office.context.mailbox.item.itemId

我得到了这样的changekey:

var mailbox = Office.context.mailbox;
var soapToGetItemData = getItemDataRequest(mailbox.item.itemId);

    Office.context.mailbox.makeEwsRequestAsync(soapToGetItemData, function(result) {
        var response = $.parseXML(result.value);
        var responseString = result.value;

        // TODO: May want to reconsider the logic for getting the ChangeKey
        var indexOfChangeKey = responseString.indexOf("ChangeKey=\"");
        var substringAfterChangeKey = responseString.substring(indexOfChangeKey + 11);
        var indexOfQuotes = substringAfterChangeKey.indexOf("\"");
        var changeKey = substringAfterChangeKey.substring(0, indexOfQuotes);

这里是getItemDataRequest函数:

function getItemDataRequest(itemId) {
    var soapToGetItemData = '<?xml version="1.0" encoding="utf-8"?>' +
        '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
        '               xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"' +
        '               xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
        '               xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +
        '               xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
        '  <soap:Header>' +
        '    <RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' +
        '  </soap:Header>' +
        '  <soap:Body>' +
        '    <GetItem' +
        '                xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"' +
        '                xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
        '      <ItemShape>' +
        '        <t:BaseShape>IdOnly</t:BaseShape>' +
        '        <t:AdditionalProperties>' +
        '            <t:FieldURI FieldURI="item:Attachments" /> ' +
        '        </t:AdditionalProperties> ' +
        '      </ItemShape>' +
        '      <ItemIds>' +
        '        <t:ItemId Id="' + itemId + '"/>' +
        '      </ItemIds>' +
        '    </GetItem>' +
        '  </soap:Body>' +
        '</soap:Envelope>';
    return soapToGetItemData;
}

然而,我收到了无效的响应(返回的 XML 包含“请求无效。”)

有什么想法吗?

谢谢!

【问题讨论】:

    标签: javascript exchangewebservices office-addins


    【解决方案1】:

    请求中需要使用http而不是https。

    function getMoveItemRequest(id, changeKey) {
        var result =
            '<?xml version="1.0" encoding="utf-8"?> ' +
            '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
                'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
                'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ' +
                'xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> ' +
            '<soap:Header> ' +
                '<t:RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" /> ' +
            '</soap:Header> ' +
            '<soap:Body> ' +
                '<MoveItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" ' +
                    'xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> ' +
                    '<ToFolderId> ' +
                        '<t:DistinguishedFolderId Id="deleteditems"/> ' +
                    '</ToFolderId> ' +
                    '<ItemIds> ' +
                        '<t:ItemId Id="' + id + '" ChangeKey="' + changeKey + '"/> ' +
                    '</ItemIds> ' +
                '</MoveItem> ' +
            '</soap:Body> ' +
            '</soap:Envelope> ';
    
        return result;
    }
    

    【讨论】:

      猜你喜欢
      • 2014-03-01
      • 2018-08-03
      • 1970-01-01
      • 2014-12-11
      • 2021-11-18
      • 1970-01-01
      • 1970-01-01
      • 2016-02-14
      • 2023-03-14
      相关资源
      最近更新 更多