title: Exchange EWS Managed API - unexpected token in XML
body: <p>Im trying to write a simple sample program which checks for any new mail on an Exchange 2010 server. As far as I can tell, the code I've got should work fine.</p>
  
  <p>I setup the service as follows:</p>
  
  <pre><code>ExchangeService service = new ExchangeService();
  
  service.Credentials = new WebCredentials("user@domain.co.uk", "password");
  
  service.Url = new Uri("https://address/owa");
  </code></pre>
  
  <p>Upon executing the following code:</p>
  
  <pre><code>        int unreadMail = 0;
  
          // Add a search filter that searches on the body or subject.
          List&lt;SearchFilter&gt; searchFilterCollection = new List&lt;SearchFilter&gt;();
          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&lt;Item&gt; findResults = service.FindItems(WellKnownFolderName.Inbox, searchFilter, view);
  
          // Process each item.
          foreach (Item myItem in findResults.Items)
          {
              if (myItem is EmailMessage)
              {
                  if (myItem.IsNew) unreadMail++;
  
              }
          }
  </code></pre>
  
  <p>I get this error (on the FindItemResults line):</p>
  
  <pre><code>'&gt;' is an unexpected token. The expected token is '"' or '''. Line 1, position 63.
  </code></pre>
  
  <p>This appears to be an error in the XML the API is actually generating, I've tried a few different lots of code (all along the same lines) and not found anything that works.</p>
  
  <p>Any ideas? At a bit of a loss when it comes directly from the API!</p>
  
  <p>Cheers, Daniel.</p>