我目前正在开发Windows Azure服务,我必须实现从Exchange服务器导入一些项目。 当我在本地模拟器上测试它时,一切正常,我可以导入项目,但是在云上部署它会停止工作。
这是我得到的例外:
异常类型:ServiceResponseException 异常消息:发生内部服务器错误。操作失败。
我使用的代码:
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: 这不是防火墙问题,因为如果我输入的用户名或密码不正确,则会引发未经授权的异常,因此它会连接到服务器。
答案 0 :(得分:1)
经过3天的疼痛,我解决了这个问题。问题是我没有在ExchangeService
类的构造函数中指定时区。我的构造函数现在看起来像这样:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));
答案 1 :(得分:0)
您应该在Windows Azure上检查VM的防火墙策略