2012-07-13 115 views
7

這是我的場景:我必須從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是否工作?我需要參數來告訴交換管理員這個功能必須配置。謝謝你的幫助。

+2

我敢肯定,你現在因爲這個問題是一歲發現了一種方法,只是想補充一點,使用調用'AutoDiscoverUrl'不能與EWS連接的唯一途徑。直接自己設置url可能是一個可行的選擇。例如:'service.Url =新URI( 「HTTPS://your_exchange_server/EWS/Exchange.asmx」);現在' – Halvard 2013-08-14 08:39:30

回答

2

不知怎的,你需要記錄redirectionUrl的結果。當您的redirectionUrl與您指定的URI不匹配時(即您的自動發現驗證回調返回FALSE),您將收到此錯誤。當然,redirectionUrl URI並不是你想象的那樣。如果您使用SSL - 您需要處理重定向驗證回調。

因爲你不能調試應用程序,也許你可以發送電子郵件給自己,登錄到一個共享的數據庫或文件,或者使用應用程序事件日誌(拋出一個應用程序異常)。

注意:第一個錯誤告訴你自動發現URI是https://autodiscover.colpatria.com/autodiscover/autodiscover.xml。這應該替換現有的字符串https://autodiscover-s.outlook.com/autodiscover/autodiscover.xml

另請參閱related SO post regarding Exchange AutodiscoveryValidating a Potentially Unsafe Redirection URL on MSDN

3

已經遇到類似的問題,最近並努力解決他們,我發現了一個工具,它是/是非常有幫助的故障排除:EWS Editor它可能不是解決你的問題,但可以用於非常快速迭代通過不同的配置組合,希望這將闡明瞭你的問題。

我使用此應用程序時,與客戶端建立自動發現和服務URL連接測試和prod Exchange服務器。它不僅適用於我,還適用於客戶的IT人員。他們下載並使用該實用程序來測試和驗證其設置。

http://ewseditor.codeplex.com

項目介紹

EWSEditor有三個目標:

  1. 展示通過其源代碼中的Exchange Web服務託管API的功能和簡單的開發。

  2. 展示用於執行通過資源管理器用戶界面啓動的操作Exchange Web服務SOAP傳輸。

  3. 通過探索深入

+1

EWSEditor是在GitHub:https://github.com/dseph/EwsEditor – RenniePet 2017-11-07 13:06:34

1

項目,文件夾和它們的屬性幫助調試非開發人員和了解Exchange存儲這是一個老帖子,我想我會放在一個完整的示例解決方案報告的錯誤。只需更換service.AutodiscoverUrl( 「[email protected]」);的System.Uri( 「https://mail.somedomain.org/ews/Exchange.asmx」);

這裏的代碼完全塊

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2); 
       service.Credentials = new WebCredentials("someuser", "somepassword"); 
       //service.AutodiscoverUrl("[email protected]"); 
       service.Url = new System.Uri("https://mail.somedomain.org/ews/Exchange.asmx"); 
0

嘗試service.TraceEnabled = true;

WFM。在我的情況下,我需要通過從客戶機上安裝Exchange Server的證書來設置SSL/TLS。我從跟蹤輸出被引導到這個解決方案。

0

這就像一個魅力對我說:

var exchange = new ExchangeService(ExchangeVersion.Exchange2013_SP1); 
    var username = Settings.EmailUserName; 
    var password = Settings.EmailPassword; 
    var domain = Settings.EmailDomain; 
    var email = Settings.Email; 
    exchange.Credentials = new WebCredentials(email, password); 
    exchange.AutodiscoverUrl(email, RedirectionCallback); 

和RedirectionCallback是:

static bool RedirectionCallback(string url) 
     { 
      // Return true if the URL is an HTTPS URL. 
      return url.ToLower().StartsWith("https://"); 
     } 

繼承人是鏈接: https://msdn.microsoft.com/en-us/library/office/dd635285(v=exchg.80).aspx

商祺!