2010-11-12 5 views
1

Je tente d'écrire un exemple de programme simple qui vérifie tout nouveau courrier sur un serveur Exchange 2010. Pour autant que je sache, le code que j'ai doit fonctionner correctement.API Exchange EWS gérée - jeton inattendu en XML

-je configurer le service comme suit:

ExchangeService service = new ExchangeService(); 

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

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

Lors de l'exécution du code suivant:

 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++; 

      } 
     } 

Je reçois cette erreur (sur la ligne de FindItemResults):

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

Cette semble être une erreur dans le XML que l'API génère réellement, j'ai essayé quelques lots de code différents (tout le long du mêmes lignes) et ne trouve rien qui fonctionne.

Des idées? À un peu de perte quand il vient directement de l'API!

Cheers, Daniel.

Répondre

0

Nevermind fixé il - nécessaire pour pointer mon service:

https://servername/ews/Exchange.asmx

et fournir des détails réguliers de connexion de domaine tels que « nom d'utilisateur », « mot de passe » pour se connecter!

Questions connexes