2014-10-02 33 views
0

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

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

+0

我认为这是搜索联系人右一个非常简单的和经常使用的方法是什么?有人能指出我的错误吗? – RazorAlliance192 2014-10-02 09:11:53

回答

1

你不能创建EmailAddresses属性的限制,因为这是一个集合o富力地产,所以你需要跨底层3联系人的电子邮件地址属性使用或限制,例如

 <m:Restriction> 
     <t:Or> 
     <t:IsEqualTo> 
      <t:IndexedFieldURI FieldURI="contacts:EmailAddress" FieldIndex="EmailAddress1" /> 
      <t:FieldURIOrConstant> 
      <t:Constant Value="[email protected]" /> 
      </t:FieldURIOrConstant> 
     </t:IsEqualTo> 
     <t:IsEqualTo> 
      <t:IndexedFieldURI FieldURI="contacts:EmailAddress" FieldIndex="EmailAddress2" /> 
      <t:FieldURIOrConstant> 
      <t:Constant Value="[email protected]" /> 
      </t:FieldURIOrConstant> 
     </t:IsEqualTo> 
     <t:IsEqualTo> 
      <t:IndexedFieldURI FieldURI="contacts:EmailAddress" FieldIndex="EmailAddress3" /> 
      <t:FieldURIOrConstant> 
      <t:Constant Value="[email protected]" /> 
      </t:FieldURIOrConstant> 
     </t:IsEqualTo> 
     </t:Or> 
    </m:Restriction> 

干杯 格伦

+0

不错!那就是诀窍:D非常感谢! – RazorAlliance192 2014-10-05 11:31:44

相关问题