Đây là kịch bản của tôi: Tôi phải đọc email từ tài khoản trao đổi 2010 sp2. Tôi phải sử dụng Exchange Web Services, POP3 và IMAP bị chặn. Tôi phải kiểm tra ứng dụng của mình trong môi trường mà mọi người có thể truy cập tài khoản của họ thông qua trình duyệt web chỉ trong mạng nội bộ. Tôi không thể gỡ lỗi ứng dụng của mình trực tiếp vào mạng nội bộ này. Tôi có đoạn này để truy cập vào tài khoản:đọc email bằng cách sử dụng dịch vụ trao đổi web
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");
}
Nếu tôi sử dụng dòng này:
service.AutodiscoverUrl(url);
tôi nhận được lỗi này:
"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."
Vì vậy, các phương pháp RedirectionUrlValidationCallback
được thực hiện, tôi m không chắc liệu url có đúng không. Thực tế là tôi nhận được lỗi này:
"The Autodiscover service couldn't be located".
Có thể Tự động phát hiện không được định cấu hình đúng không ?? Tôi không phải là quản trị viên trao đổi, làm thế nào tôi có thể biết được nếu các công trình tự động phát hiện? Tôi cần các đối số để nói cho quản trị viên trao đổi biết tính năng này phải được định cấu hình. Cảm ơn vì bất kì sự giúp đỡ.
Tôi chắc chắn bạn đã tìm thấy một cách ngay bây giờ khi câu hỏi này được một tuổi, chỉ muốn thêm rằng bằng cách sử dụng gọi 'AutoDiscoverUrl' không phải là cách duy nhất để kết nối với EWS. Thay vào đó, hãy đặt trực tiếp url của bạn có thể là một giải pháp thay thế khả thi. Ví dụ: 'service.Url = new URI (" https: //your_exchange_server/EWS/Exchange.asmx ");' – Halvard