无法使用“搜索表达式”中的EmailAddress检索EWS联系人

时间:2014-10-02 08:50:13

标签: java exchangewebservices

我正在尝试构建一个搜索XML表达式,以便与Java中的Exchange Web服务一起使用。我试图实现的是我可以通过他们的电子邮件地址搜索所有联系人。我已经浏览了他们的文档,但未能使其工作。这就是我到目前为止所做的:

String searchXmlStr ="<Restriction>"
                     + "<t:IsEqualTo>"
                     +    "<t:FieldURI FieldURI=\"contacts:EmailAddresses\"/>"
                     +    "<t:EmailAddresses>"
                     +      "<Entry Key=\""+ emailAddress +"\"/>"
                     +    "</t:EmailAddresses>"
                     + "</t:IsEqualTo>"
                     +"</Restriction>";

当我编译并运行这段代码时,我得到:

ERROR [jec.utils.AppLogger] status: 500
ERROR [jec.utils.AppLogger] <?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 'IsEqualTo' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types' has invalid child element 'EmailAddresses' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'. List of possible elements expected: 'FieldURIOrConstant' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'.</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>1</t:LineNumber><t:LinePosition>572</t:LinePosition><t:Violation>The element 'IsEqualTo' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types' has invalid child element 'EmailAddresses' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'. List of possible elements expected: 'FieldURIOrConstant' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'.</t:Violation></t:MessageXml></detail></s:Fault></s:Body></s:Envelope>
ERROR [jec.utils.AppLogger] <?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 'IsEqualTo' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types' has invalid child element 'EmailAddresses' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'. List of possible elements expected: 'FieldURIOrConstant' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'.</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>1</t:LineNumber><t:LinePosition>572</t:LinePosition><t:Violation>The element 'IsEqualTo' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types' has invalid child element 'EmailAddresses' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'. List of possible elements expected: 'FieldURIOrConstant' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'.</t:Violation></t:MessageXml></detail></s:Fault></s:Body></s:Envelope>
jec.ExchangeGeneralException: <?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 'IsEqualTo' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types' has invalid child element 'EmailAddresses' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'. List of possible elements expected: 'FieldURIOrConstant' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'.</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>1</t:LineNumber><t:LinePosition>572</t:LinePosition><t:Violation>The element 'IsEqualTo' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types' has invalid child element 'EmailAddresses' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'. List of possible elements expected: 'FieldURIOrConstant' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'.</t:Violation></t:MessageXml></detail></s:Fault></s:Body></s:Envelope>
    at jec.a.a.a.for(Unknown Source)
    at jec.EWSConnector.getContacts(Unknown Source)
    at betas.Main.getContactByEmail(Main.java:197)
    at betas.Main.main(Main.java:36)
jec.ExchangeGeneralException: <?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 'IsEqualTo' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types' has invalid child element 'EmailAddresses' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'. List of possible elements expected: 'FieldURIOrConstant' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'.</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>1</t:LineNumber><t:LinePosition>572</t:LinePosition><t:Violation>The element 'IsEqualTo' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types' has invalid child element 'EmailAddresses' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'. List of possible elements expected: 'FieldURIOrConstant' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'.</t:Violation></t:MessageXml></detail></s:Fault></s:Body></s:Envelope>
    at jec.a.a.a.for(Unknown Source)
    at jec.EWSConnector.getContacts(Unknown Source)
    at betas.Main.getContactByEmail(Main.java:197)
    at betas.Main.main(Main.java:36)

修改

为了完整起见,我使用this库来连接EWS

1 个答案:

答案 0 :(得分:1)

您无法在EmailAddresses属性上创建限制,因为这是一组属性,因此您需要在底层3联系电子邮件地址属性中使用或限制,例如

      <m:Restriction>
      <t:Or>
        <t:IsEqualTo>
          <t:IndexedFieldURI FieldURI="contacts:EmailAddress" FieldIndex="EmailAddress1" />
          <t:FieldURIOrConstant>
            <t:Constant Value="user@domain.com" />
          </t:FieldURIOrConstant>
        </t:IsEqualTo>
        <t:IsEqualTo>
          <t:IndexedFieldURI FieldURI="contacts:EmailAddress" FieldIndex="EmailAddress2" />
          <t:FieldURIOrConstant>
            <t:Constant Value="user@domain.com" />
          </t:FieldURIOrConstant>
        </t:IsEqualTo>
        <t:IsEqualTo>
          <t:IndexedFieldURI FieldURI="contacts:EmailAddress" FieldIndex="EmailAddress3" />
          <t:FieldURIOrConstant>
            <t:Constant Value="user@domain.com" />
          </t:FieldURIOrConstant>
        </t:IsEqualTo>
      </t:Or>
    </m:Restriction>

干杯 格伦