簡體   English   中英

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;

}

這將只返回Text主體,並將適用於任何版本的EWS。

干杯格倫

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM