Exchange 2013 EWS PHP - FindItem限制错误

时间:2014-01-21 14:16:20

标签: php soap exchange-server exchangewebservices

我正在开发一个连接到Microsoft Exchange 2013的Web应用程序。 问题是,如果我在'FindItem'上使用'限制',我会收到一个错误。

此代码有效,但没有限制:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/messages">
    <SOAP-ENV:Body>
        <ns2:FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" Traversal="Shallow">
            <ns2:ItemShape>
                <ns1:BaseShape>AllProperties</ns1:BaseShape>
            </ns2:ItemShape>
            <ns2:IndexedPageItemView MaxEntriesReturned="50" Offset="0" BasePoint="Beginning"/>
            <ns2:ParentFolderIds>
                <ns1:FolderId Id="(myFolderID)"/>
            </ns2:ParentFolderIds>
        </ns2:FindItem>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

此代码不起作用,但有限制:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/messages">
    <SOAP-ENV:Body>
        <ns2:FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" Traversal="Shallow">
            <ns2:ItemShape>
                <ns1:BaseShape>AllProperties</ns1:BaseShape>
            </ns2:ItemShape>
            <ns2:IndexedPageItemView MaxEntriesReturned="50" Offset="0" BasePoint="Beginning"/>
            <ns2:ParentFolderIds>
                <ns1:FolderId Id="(myFolderID)"/>
            </ns2:ParentFolderIds>
            <ns2:Restriction>
                <Or>
                    <IsEqualTo>
                        <FieldURI FieldURI="message:From" />
                        <FieldURIOrConstant>
                            <Constant Value="(searchEmailAddress)" />
                        </FieldURIOrConstant>
                    </IsEqualTo>
                    <IsEqualTo>
                        <FieldURI FieldURI="message:Sender" />
                        <FieldURIOrConstant>
                            <Constant Value="(searchEmailAddress)" />
                        </FieldURIOrConstant>
                    </IsEqualTo>
                </Or>
            </ns2:Restriction>
        </ns2:FindItem>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

这是我得到的错误:

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
        <s:Fault>
            <faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">a:ErrorSchemaValidation</faultcode>
            <faultstring xml:lang="en-US">The request failed schema validation: The element 'FindItem' in namespace 'http://schemas.microsoft.com/exchange/services/2006/messages' has invalid child element 'Restriction' in namespace 'http://schemas.microsoft.com/exchange/services/2006/messages'.</faultstring>
            <detail>
                <e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorSchemaValidation</e:ResponseCode>
                <e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">The request failed schema validation.</e:Message>
                <t:MessageXml xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
                    <t:LineNumber>9</t:LineNumber>
                    <t:LinePosition>5</t:LinePosition>
                    <t:Violation>The element 'FindItem' in namespace 'http://schemas.microsoft.com/exchange/services/2006/messages' has invalid child element 'Restriction' in namespace 'http://schemas.microsoft.com/exchange/services/2006/messages'.</t:Violation>
                </t:MessageXml>
            </detail>
        </s:Fault>
    </s:Body>
</s:Envelope>

现在是否有人解决此问题?

1 个答案:

答案 0 :(得分:2)

尝试在限制后放置ParentFolderIds。以下代码适用于我,但如果我在限制之前放置ParentFolderIds,则会失败。

<?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:t="http://schemas.microsoft.com/exchange/services/2006/types" 
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2013" />
  </soap:Header>
  <soap:Body>
    <m:FindItem Traversal="Shallow">
      <m:ItemShape>
        <t:BaseShape>AllProperties</t:BaseShape>
      </m:ItemShape>
      <m:IndexedPageItemView MaxEntriesReturned="50" Offset="0" BasePoint="Beginning" />
            <m:ParentFolderIds>
        <t:FolderId Id="..." />
      </m:ParentFolderIds>
<m:Restriction>
        <t:Or>
          <t:IsEqualTo >
            <t:FieldURI FieldURI="message:From" />
            <t:FieldURIOrConstant>
              <t:Constant Value="sadie@contoso.com" />
            </t:FieldURIOrConstant>
          </t:IsEqualTo>
          <t:IsEqualTo>
            <t:FieldURI FieldURI="message:Sender" />
            <t:FieldURIOrConstant>
              <t:Constant Value="sadie@contoso.com" />
            </t:FieldURIOrConstant>
          </t:IsEqualTo>
        </t:Or>
      </m:Restriction>
    </m:FindItem>
  </soap:Body>
</soap:Envelope>