2010-11-12 31 views
1

我試圖編寫一個簡單的示例程序來檢查Exchange 2010服務器上的任何新郵件。據我所知,我得到的代碼應該可以正常工作。Exchange EWS託管API - XML中的意外標記

我設置服務如下:

ExchangeService service = new ExchangeService(); 

service.Credentials = new WebCredentials("[email protected]", "password"); 

service.Url = new Uri("https://address/owa"); 

在執行以下代碼:

 int unreadMail = 0; 

     // Add a search filter that searches on the body or subject. 
     List<SearchFilter> searchFilterCollection = new List<SearchFilter>(); 
     searchFilterCollection.Add(new SearchFilter.ContainsSubstring(ItemSchema.Subject, "Defense")); 

     // Create the search filter. 
     SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilterCollection.ToArray()); 

     // Create a view with a page size of 50. 
     ItemView view = new ItemView(50); 

     // Identify the Subject and DateTimeReceived properties to return. 
     // Indicate that the base property will be the item identifier 
     view.PropertySet = new PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject, ItemSchema.DateTimeReceived); 

     // Order the search results by the DateTimeReceived in descending order. 
     view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending); 

     // Set the traversal to shallow. (Shallow is the default option; other options are Associated and SoftDeleted.) 
     view.Traversal = ItemTraversal.Shallow; 

     // Send the request to search the Inbox and get the results. 
     FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, searchFilter, view); 

     // Process each item. 
     foreach (Item myItem in findResults.Items) 
     { 
      if (myItem is EmailMessage) 
      { 
       if (myItem.IsNew) unreadMail++; 

      } 
     } 

我得到這個錯誤(在FindItemResults行):

'>' is an unexpected token. The expected token is '"' or '''. Line 1, position 63. 

這似乎是API實際生成的XML中的一個錯誤,我嘗試了一些不同的代碼(所有的代碼都一樣)相同的行),並沒有發現任何工作。

任何想法?在直接來自API的時候有點遺憾!

乾杯,丹尼爾。

回答

相關問題