从Outlook获取日历项->;有一个例外

从Outlook获取日历项->;有一个例外,outlook,exchangewebservices,Outlook,Exchangewebservices,我有个例外 Microsoft.Exchange.WebServices.dll中发生类型为“Microsoft.Exchange.WebServices.Data.ServiceLocalException”的未处理异常。其他信息:必须设置ExchangeService对象的Url属性。 关于: 在 public void GetEWS() { //初始化开始和结束时间以及要检索的约会数的值。 //$service=新对象Microsoft.Exchange.WebServices.Data.

我有个例外

Microsoft.Exchange.WebServices.dll中发生类型为“Microsoft.Exchange.WebServices.Data.ServiceLocalException”的未处理异常。其他信息:必须设置ExchangeService对象的Url属性。 关于:

public void GetEWS()
{
//初始化开始和结束时间以及要检索的约会数的值。
//$service=新对象Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013)
ExchangeService服务=新的ExchangeService(ExchangeVersion.Exchange2013);
DateTime startDate=DateTime.Now;
DateTime endDate=开始日期。添加日期(30);
常量int NUM_APPTS=5;
//仅使用文件夹ID初始化日历文件夹对象。
CalendarFolder calendar=CalendarFolder.Bind(服务,WellKnownFolderName.calendar,新属性集());
//设置要检索的开始和结束时间以及约会数。
CalendarView cView=新的CalendarView(开始日期、结束日期、数值应用);
//限制返回到约会主题、开始时间和结束时间的属性。
cView.PropertySet=newpropertyset(appointschema.Subject,appointschema.Start,appointschema.End);
//使用日历视图检索约会集合。
FindItemsResults约会=calendar.FindAppoints(cView);
Console.WriteLine(“\n日历上的第一个”+NUM_APPTS+”约会从“+startDate.Date.ToShortDateString()开始)+
“到”+endDate.Date.ToShortDateString()+“是:\n”);
foreach(预约中的预约)
{
Console.Write(“Subject:+a.Subject.ToString()+”);
编写(“Start:+a.Start.ToString()+”);
Console.Write(“End:+a.End.ToString());
Console.WriteLine();
}
}

在您的代码中,您没有设置EWS要使用的URL(这是错误告诉您的),也没有设置要使用的凭据。看到和

干杯 峡谷

..., new PropertySet());. 
public void GetEWS()
        {
            // Initialize values for the start and end times, and the number of appointments to retrieve.

            //$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013)
            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
            DateTime startDate = DateTime.Now;
            DateTime endDate = startDate.AddDays(30);
            const int NUM_APPTS = 5;


            // Initialize the calendar folder object with only the folder ID. 
            CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());

            // Set the start and end time and number of appointments to retrieve.
            CalendarView cView = new CalendarView(startDate, endDate, NUM_APPTS);

            // Limit the properties returned to the appointment's subject, start time, and end time.
            cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);

            // Retrieve a collection of appointments by using the calendar view.
            FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);

            Console.WriteLine("\nThe first " + NUM_APPTS + " appointments on your calendar from " + startDate.Date.ToShortDateString() +
                              " to " + endDate.Date.ToShortDateString() + " are: \n");

            foreach (Appointment a in appointments)
            {
                Console.Write("Subject: " + a.Subject.ToString() + " ");
                Console.Write("Start: " + a.Start.ToString() + " ");
                Console.Write("End: " + a.End.ToString());
                Console.WriteLine();
            }

        }