2014-12-30 48 views
0

我試圖使用EWS-Api-2.1 nuget包開始與EWS合作。下面是簡單的代碼,我使用的是:與'autodiscover.domain.com'的連接失敗使用EWS

 ExchangeService _service = new ExchangeService(); 
     _service.Credentials = new WebCredentials("mail", "password"); 
     _service.AutodiscoverUrl("mail", url => false);//_service.AutodiscoverUrl("mail") Both variants fails 

     var appointment = new Appointment(_service); 
     appointment.Subject = "Status Meeting"; 
     appointment.Body = "The purpose of this meeting is to discuss status."; 
     appointment.Start = DateTime.Now.AddHours(1); 
     appointment.End = appointment.Start.AddHours(2); 
     appointment.Location = "Conf Room"; 
     appointment.RequiredAttendees.Add("mail1"); 
     appointment.Save(SendInvitationsMode.SendToNone); 

至於結果,我有:

HTTP/1.1 502 Fiddler - Connection Failed 
    [Fiddler] The connection to 'autodiscover.domain.com' failed. 
    Error: ConnectionRefused (0x274d). System.Net.Sockets.SocketException 
    No connection could be made because the target machine actively refused it 157.56.248.169:443 

在DNS管理,我有以下:

Initial domain: This domain is included with your account. It’s set up automatically for you, and you can’t delete it. 
+0

您是否知道交換服務器的IP或其DNS名稱?然後,您可以嘗試設置沒有自動發現的連接。這可能會給你一個縮小原因的可能性。 – khlr

+0

感謝您的意見,它幫助我解決問題。我添加了下一個代碼:_service.Url = new Uri(「https://outlook.office365.com/EWS/Exchange.asmx」); –

+0

你現在能夠使用AutoDiscover? – khlr

回答

1

如果你想找出爲什麼自動發現失敗,我會推薦enabling tracing與所有自動發現相關的跟蹤標記。當然,我假設你傳遞的值「郵件」實際上是用戶的電子郵件地址。