2014-10-02 31 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

相關問題