Pam
Pam

Reputation: 73

Exchange Server doesn't support the requested version

I get this error because the FindItemsResult isn't compatible with exchange version I'm using which is 2013.

Exchange Server doesn't support the requested version.

My codes:

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 into Exchange 2010 but I get an error in TextBody since this is only for Exchange 2013 and later versions.

Is there any way to convert the code which can work in Exchange 2013?

Upvotes: 4

Views: 9035

Answers (1)

Glen Scales
Glen Scales

Reputation: 22032

You need to show more of the code your using as your question doesn't really make sense. The ItemSchema.TextBody was added in Exchange 2013 so as long you are running Exchange 2013 and you have set the Initial server version correctly it will work (So you are either not running 2013 or you have other issue in the code you haven't show). If your looking for something that will work on both Exchange 2007,2010 and 2013 the I would suggest you use.

String MailboxToAccess = "[email protected]";
ExchangeService service = new Microsoft.Exchange.WebServices.Data.ExchangeService(ExchangeVersion.Exchange2010_SP1);
SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead,false);        

service.Credentials = new NetworkCredential("[email protected]", "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;

}

That will return just the Text body and will work on any version of EWS.

Cheers Glen

Upvotes: 6

Related Questions