Exchange Server 不支持请求的版本
Exchange Server doesn't support the requested version
我收到此错误是因为 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 中工作的代码吗?
您需要展示更多您使用的代码,因为您的问题没有任何意义。 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;
}
这将 return 只是文本正文并且适用于任何版本的 EWS。
干杯
格伦
我收到此错误是因为 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 中工作的代码吗?
您需要展示更多您使用的代码,因为您的问题没有任何意义。 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;
}
这将 return 只是文本正文并且适用于任何版本的 EWS。
干杯 格伦