EWS的CreateItem操作中出现内部服务器错误

Internal Server Error in CreateItem operation of EWS

本文关键字:内部 服务器 错误 CreateItem 操作 EWS      更新时间:2023-10-16

我使用CreateItem操作,使用带有gSOAP工具包的EWS将消息保存在Draft文件夹中,但当我运行代码时,我的响应XML如下:

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
        <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">*</Action>
    </s:Header>
    <s:Body>
        <s:Fault>
            <faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">a:ErrorInternalServerError</faultcode>
            <faultstring xml:lang="en-US">An internal server error occurred. The operation failed.</faultstring>
            <detail>
                <e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorInternalServerError</e:ResponseCode>
                <e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">An internal server error occurred. The operation failed.</e:Message>
            </detail>
        </s:Fault>
    </s:Body>
</s:Envelope>

在终端中,我遇到的故障是:

SOAP 1.1 fault: SOAP-ENV:MustUnderstand[no subcode]
"The data in element 'Action' must be understood but cannot be processed"
Detail: [no detail]

并且不存在编译时错误。如果你需要代码,请告诉我,我也会给你。请帮助我,我已经尝试了很多,但没有找到解决方案,无论我更改代码,响应XML都保持不变。

请求XML如下:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ews="http://schemas.microsoft.com/exchange/services/2006/messages">
    <SOAP-ENV:Body>
        <ews:CreateItem xsi:type="ews:CreateItemType" MessageDisposition="SaveOnly"><ews:SavedItemFolderId xsi:type="ns1:TargetFolderIdType">
            <ns1:DistinguishedFolderId Id="drafts" xsi:type="ns1:DistinguishedFolderIdType"></ns1:DistinguishedFolderId>
        </ews:SavedItemFolderId>
        <ews:Items xsi:type="ns1:NonEmptyArrayOfAllItemsType">
            <ns1:Message xsi:type="ns1:MessageType">
                <ns1:ItemClass xsi:type="ns1:ItemClassType">IPM.Note</ns1:ItemClass>
                <ns1:Subject xsi:type="xsd:string">Project Action</ns1:Subject>
                <ns1:Body BodyType="Text" xsi:type="ns1:BodyType">Priority - Update specification</ns1:Body>
                <ns1:Sender xsi:type="ns1:SingleRecipientType">
                    <ns1:Mailbox xsi:type="ns1:EmailAddressType">
                        <ns1:EmailAddress xsi:type="ns1:NonEmptyStringType">markzuck93@live.com</ns1:EmailAddress>
                    </ns1:Mailbox>
                </ns1:Sender>
                <ns1:ToRecipients xsi:type="ns1:ArrayOfRecipientsType">
                    <ns1:Mailbox xsi:type="ns1:EmailAddressType">
                        <ns1:EmailAddress xsi:type="ns1:NonEmptyStringType">openuib@openuib.onmicrosoft.com</ns1:EmailAddress>
                    </ns1:Mailbox>
                </ns1:ToRecipients>
            </ns1:Message>
        </ews:Items>
    </ews:CreateItem>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我建议您去掉所有xsi:type属性,例如如何从gSoap消息中删除xsi:type信息?

简化的请求应该看起来像

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ews="http://schemas.microsoft.com/exchange/services/2006/messages">
    <SOAP-ENV:Body>
       <ews:CreateItem MessageDisposition="SaveOnly">
       <ews:SavedItemFolderId>
           <ns1:DistinguishedFolderId Id="drafts" />
        </ews:SavedItemFolderId>
        <ews:Items>
            <ns1:Message>
                <ns1:ItemClass>IPM.Note</ns1:ItemClass>
                <ns1:Subject>Project Action</ns1:Subject>
            </ns1:Message>
        </ews:Items>
    </ews:CreateItem>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

这对我来说还可以。

欢呼Glen

我最近研究了EWS api,发现Sender标记会导致带有CreateItem请求的500响应。相反,您应该使用From标记。

            <ns1:From xsi:type="ns1:SingleRecipientType">
                <ns1:Mailbox xsi:type="ns1:EmailAddressType">
                    <ns1:EmailAddress xsi:type="ns1:NonEmptyStringType">markzuck93@live.com</ns1:EmailAddress>
                </ns1:Mailbox>
            </ns1:From>