简体   繁体   中英

C# EWS API - Accessing items on different Exchange server than the server where account accessing is configured

I have an account created on Exchange Server A and I'm trying to access items on shared mailbox X configured on Exchange server B . I have required permissions to access mailbox X and I'm able to do it using MS Outlook, but not able to do it using EWS Managed API. I have used following code:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new WebCredentials("user.name@organization.com", "password");
service.Url = new Uri("https://organization.com/EWS/Exchange.asmx");
Mailbox somemailbox = new Mailbox("some.mailbox@organization.com");
FolderId folderInbox = new FolderId(WellKnownFolderName.Inbox, somemailbox);
FindFoldersResults findResults = service.FindFolders(folderInbox, new FolderView(int.MaxValue));

This returns an error: "The account accessing the resource must be on the same Mailbox Server version as the delegate account being accessed." pointing last line of the code (service.FindFolders).

At the beginning I thought that version of the servers are not compatible, but when I changed ExchangeVersion in line 1 of the code to any other than "Exchange2007_SP1" I got error message Exchange Server doesn't support the requested version. , So I guess that this is not version related problem. I guess that in such case I would not be able to connect using MS Outlook which works fine.

I think that I'm missing something very easy, but I don't know what...

the problem is that you connect to the primary server. If you want to access the delegate-account you will have to change the ews-url to the ews-address of the server where the mailbox is stored. I have nearly the same scenario in my company and with diffrent urls it works fine for me. If your exchange-server is co configured properly you can use the autodiscover function 'service.Autodiscover()' of the managed api to get the right ews-address.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM