Exchange Server does not support the requested version

I get this error because FindItemsResult is incompatible with the exchange version that I am using, which is 2013.

Exchange Server doesn't support the requested version.

My codes are:

SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
        FindItemsResults<Item> items = service.FindItems(WellKnownFolderName.Inbox, sf, new ItemView(10));

        foreach (Item item in items.Items)
        {
            PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, ItemSchema.TextBody);
            EmailMessage email = EmailMessage.Bind(service, item.Id, propSet);
            Program.SearchItems(email);  
        }

I could just change it in Exchange 2010, but I get an error in TextBody, as it is only for Exchange 2013 and later.

Is there a way to convert code that can work in Exchange 2013?

+4
source share
1 answer

, , . ItemSchema.TextBody Exchange 2013, Exchange 2013, ( , 2013 , , ). -, Exchange 2007,2010 2013, .

String MailboxToAccess = "user@domain.com";
ExchangeService service = new Microsoft.Exchange.WebServices.Data.ExchangeService(ExchangeVersion.Exchange2010_SP1);
SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead,false);        

service.Credentials = new NetworkCredential("user@domain.com", "password");
service.AutodiscoverUrl(MailboxToAccess, adAutoDiscoCallBack);
FolderId FolderToAccess = new FolderId(WellKnownFolderName.Inbox, MailboxToAccess);
ItemView ivItemView = new ItemView(10);
FindItemsResults<Item> FindItemResults = service.FindItems(FolderToAccess, sfSearchFilter, ivItemView);
PropertySet ItemPropertySet = new PropertySet(BasePropertySet.IdOnly);
ItemPropertySet.Add(ItemSchema.Body);
ItemPropertySet.RequestedBodyType = BodyType.Text;
if (FindItemResults.Items.Count > 0)
{
    service.LoadPropertiesForItems(FindItemResults.Items, ItemPropertySet);
}
foreach (Item item in FindItemResults.Items)
{
    Console.WriteLine(item.Body.Text);
}

internal static bool adAutoDiscoCallBack(string redirectionUrl)
{
    // The default for the validation callback is to reject the URL.
    bool result = false;

    Uri redirectionUri = new Uri(redirectionUrl);

    // Validate the contents of the redirection URL. In this simple validation
    // callback, the redirection URL is considered valid if it is using HTTPS
    // to encrypt the authentication credentials. 
    if (redirectionUri.Scheme == "https")
    {
        result = true;
    }

    return result;

}

EWS.

Glen

+5

All Articles