Exchange Server不支持所请求的版本

时间:2016-04-05 00:38:53

标签: c# exchange-server exchangewebservices

我收到此错误,因为FindItemsResult与我使用的2013年的交换版本不兼容。

Exchange Server doesn't support the requested version.

我的代码:

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);  
        }

我可以将其更改为Exchange 2010,但我在TextBody中出现错误,因为这仅适用于Exchange 2013及更高版本。

有没有办法转换可以在Exchange 2013中运行的代码?

1 个答案:

答案 0 :(得分:5)

您需要显示更多使用的代码,因为您的问题确实没有意义。 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;

}

这将只返回Text主体,并将适用于任何版本的EWS。

干杯 格伦

相关问题