c# - EWS 无法在 Windows Azure 上运行

标签 c# asp.net azure exchange-server exchangewebservices

我目前正在开发 Windows Azure 服务,并且必须实现从 Exchange 服务器导入某些项目。 当我在本地模拟器上测试时,一切正常,我可以导入项目,但部署在云上时它停止工作。

这是我得到的异常:

Exception type: ServiceResponseException Exception message: An internal server error occurred. The operation failed.

我使用的代码:

service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.UseDefaultCredentials = false;
service.Credentials = new NetworkCredential(userName, password, domain);
service.Url = new Uri(serverUrl);

itemPropertySet = new PropertySet(BasePropertySet.FirstClassProperties);
itemPropertySet.RequestedBodyType = BodyType.Text;

CalendarView calendarView = new CalendarView(fromDate, toDate);
List<ExchangeTask> tasks = new List<ExchangeTask>();
try
{
    FindItemsResults<Appointment> appointments = service.FindAppointments(WellKnownFolderName.Calendar, calendarView);

    if (appointments.TotalCount > 0)
    {
        service.LoadPropertiesForItems(appointments, itemPropertySet);
    }
    foreach (Appointment app in appointments)
    {
        tasks.Add(new ExchangeTask() { Name = app.Subject, Description = app.Body, DeadLine = app.End.ToString() });
    }
    return tasks;
}
catch (Exception ex)
{
    throw ex;
}

编辑 1: 这不是防火墙问题,因为如果我输入的用户名或密码不正确,它会抛出未经授权的异常,因此它会连接到服务器。

最佳答案

经过三天的痛苦,我解决了这个问题。问题是我没有在 ExchangeService 类的构造函数中指定时区。我的构造函数现在看起来像这样:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1, TimeZoneInfo.FindSystemTimeZoneById("东部标准时间"));

关于c# - EWS 无法在 Windows Azure 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15784227/

相关文章:

c# - c#的消息系统

azure - 使用什么工具来获取/设置 Azure Blob 缓存控制属性

azure - 如何使用 oidc 和 azure 应用程序配置 kubernetes,以仅允许使用指定安全组进行身份验证

c# - 允许用户从谷歌驱动器中选择文件上传到我的服务器

asp.net - 如何使用 LinkBut​​ton 提交表单?

c# - 如何测试 ActionFilterAttribute - OnActionExecuted

c# - ASP.Net MVC 存储在资源中或作为内容

php - 在 Azure 中运行 Fuel Php

c# - 使用 C# 的 SQL 中的空格

c# - 下一帧 WPF mediaElement