這是我的場景:我必須從exchange 2010 sp2帳戶讀取電子郵件。我必須使用Exchange Web服務,POP3和IMAP被阻止。我必須在人們只能通過Intranet上的Web瀏覽器訪問其帳戶的環境中測試我的應用程序。我無法直接調試我的應用程序到此Intranet。我有這樣的片段訪問一筆賬:如果我用這條線使用交換網絡服務閱讀電子郵件
private void Dowork()
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
string dominio = "domain";
string usuario = "user";
string password = "password";
service.Credentials = new NetworkCredential(usuario, password, dominio);
string url = usuario + "@" + dominio + ".com";
service.AutodiscoverUrl(url, RedirectionUrlValidationCallback);
//service.AutodiscoverUrl(url);
FindItemsResults<Item> findResults = service.FindItems(
WellKnownFolderName.Inbox,
new ItemView(10));
string content = string.Empty;
foreach (Item item in findResults.Items)
{
EmailMessage email = EmailMessage.Bind(service, item.Id);
email.Load();
content += item.Subject + "\n";
content += email.From.Address + "\n";
content += email.Body + "\n\n";
//Console.WriteLine(item.Subject);
//Console.WriteLine(email.From.Address);
//Console.WriteLine(email.Body);
}
string result = content;
}
// Create the callback to validate the redirection URL.
static bool RedirectionUrlValidationCallback(String redirectionUrl)
{
// Perform validation.
return (redirectionUrl == "https://autodiscover-s.outlook.com/autodiscover/autodiscover.xml");
}
:
service.AutodiscoverUrl(url);
我得到這個錯誤:
"Autodiscover blocked a potentially insecure redirection to https://autodiscover.colpatria.com/autodiscover/autodiscover.xml . To allow Autodiscover to follow the redirection, use the AutodiscoverUrl(string, AutodiscoverRedirectionUrlValidationCallback) overload."
因此該方法RedirectionUrlValidationCallback
實施以來,我m不知道該網址是否正確。事實是,我得到這個錯誤:
"The Autodiscover service couldn't be located".
是否有可能是自動發現配置不當?我不是交換管理員,我怎麼知道autodiscover是否工作?我需要參數來告訴交換管理員這個功能必須配置。謝謝你的幫助。
我敢肯定,你現在因爲這個問題是一歲發現了一種方法,只是想補充一點,使用調用'AutoDiscoverUrl'不能與EWS連接的唯一途徑。直接自己設置url可能是一個可行的選擇。例如:'service.Url =新URI( 「HTTPS://your_exchange_server/EWS/Exchange.asmx」);現在' – Halvard 2013-08-14 08:39:30