2010-11-12 4 views
1

Я пытаюсь написать простую примерную программу, которая проверяет наличие новой почты на сервере Exchange 2010. Насколько я могу судить, код, который у меня есть, должен работать нормально.Exchange EWS Managed 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. 

Этот кажется ошибкой в ​​XML, который фактически генерирует API, я пробовал несколько разных серий кода (все время те же строки) и не нашли ничего, что сработает.

Любые идеи? В некоторой степени потеря, когда он приходит непосредственно из API!

Cheers, Daniel.

ответ

0

Nevermind, зафиксировал его - необходимо указать свою службу:

https://servername/ews/Exchange.asmx

и предоставлять регулярные детали домен входа в систему, такие как «имя пользователя», «пароль» для подключения!

Смежные вопросы