1

我的任务很简单。我有一个公共文件夹(实际上是一个日历),我需要从两个日期之间拉出所有会议。如何从Exchange Server 2007中提取公共日历数据?

我使用Visual Studio 2010中,ASP.Net 4.0,Microsoft Exchange服务器的Web服务(EWS)和Exchange Server 2007

我已经全成在使用创造我个人的日历项以下代码:

public static string[] CreateAppointment() 
{ 
    // Set up the binding with credentials and URL. 
    com.webmail.ExchangeServiceBinding binding = new com.webmail.ExchangeServiceBinding(); 
    binding.Credentials = new System.Net.NetworkCredential("steve.kershaw", "mypasswordhere", "domain.com"); 
    binding.Url = @"https://webmail.com/ews/exchange.asmx"; 

    // Creating new appointment item type 
    com.webmail.CalendarItemType appointment = new com.webmail.CalendarItemType(); 

    // Add properties to the newly created appointment. 
    appointment.Importance = com.webmail.ImportanceChoicesType.Normal; 
    appointment.ImportanceSpecified = true; 
    appointment.ItemClass = "IPM.Appointment"; 
    appointment.Subject = "mySubject"; 
    appointment.Body = new com.webmail.BodyType(); 
    appointment.Body.BodyType1 = com.webmail.BodyTypeType.HTML; 
    appointment.Body.Value = "<b>Body</b>"; 
    appointment.Categories = new string[] { "Category Red", "Category Blue" }; 
    appointment.Start = new DateTime(2013,4,30,12, 30,0); 
    appointment.StartSpecified = true; 
    appointment.End = new DateTime(2013, 4, 30, 13, 0, 0); 
    appointment.EndSpecified = true; 
    appointment.IsAllDayEvent = false; 
    appointment.IsAllDayEventSpecified = true; 
    appointment.Location = "myOffice"; 
    appointment.LegacyFreeBusyStatus = com.webmail.LegacyFreeBusyType.Busy; 
    appointment.LegacyFreeBusyStatusSpecified = true; 
    appointment.ReminderIsSet = true; 
    appointment.ReminderIsSetSpecified = true; 
    appointment.ReminderMinutesBeforeStart = "60"; 

    // Specify the destination folder 
    com.webmail.DistinguishedFolderIdType folder = new com.webmail.DistinguishedFolderIdType(); 
    folder.Id = com.webmail.DistinguishedFolderIdNameType.calendar; 

    // Create the NonEmptyArrayOfAllItemsType array that will contain the appointment. 
    com.webmail.NonEmptyArrayOfAllItemsType arrayOfItems = new com.webmail.NonEmptyArrayOfAllItemsType(); 
    arrayOfItems.Items = new com.webmail.ItemType[1]; 

    // Add our appointment to the array. 
    arrayOfItems.Items[0] = appointment; 

    // Create the request. 
    com.webmail.CreateItemType createItemRequest = new com.webmail.CreateItemType(); 

    // Set the required SendMeetingInvitations attribute 
    createItemRequest.SendMeetingInvitations = com.webmail.CalendarItemCreateOrDeleteOperationType.SendToNone; 
    createItemRequest.SendMeetingInvitationsSpecified = true; 

    // Add the destination folder to the request. 
    createItemRequest.SavedItemFolderId = new com.webmail.TargetFolderIdType(); 
    createItemRequest.SavedItemFolderId.Item = folder; 

    // Add the items to the CreateItem request. 
    createItemRequest.Items = arrayOfItems; 

    // Return value containg changeKey and hash Id to identify our appointment(needed for deleteing etc.) 
    string[] changeKeyHashId = new string[2]; 
    try 
    { 


     // Send the request - esb is a ExchangeServiceBinding object instance created in the Part 1 of this tutorial 
     com.webmail.CreateItemResponseType createItemResponse = binding.CreateItem(createItemRequest); 
     if (createItemResponse.ResponseMessages.Items == null || createItemResponse.ResponseMessages.Items.Length == 0) 
     { 
      return new string[] { "ERROR" }; 
     } 
     else 
     { 
      // Get the response message. 
      com.webmail.ResponseMessageType[] rmt = createItemResponse.ResponseMessages.Items; 
      if (rmt[0].ResponseClass != com.webmail.ResponseClassType.Success) 
       return new string[] 
       { "ERROR: " + rmt[0].MessageText 
       }; 
      else 
      { 
       foreach (com.webmail.ResponseMessageType rmtItem in rmt) 
       { 
        com.webmail.ArrayOfRealItemsType itemArray = (rmtItem as com.webmail.ItemInfoResponseMessageType).Items; 
        com.webmail.ItemType[] items = itemArray.Items; 
        // Get the return values 
        changeKeyHashId[0] = items[0].ItemId.ChangeKey; 
        changeKeyHashId[1] = items[0].ItemId.Id; 
       } 
      } 
     } 
    } 
    catch (Exception ex) 
    { 
     return new string[] 
     { "ERROR: " + ex.Message }; 
    } return changeKeyHashId; 
} 

但是,我一直无法找到任何代码来成功从任何日历中取出任何约会,包括我自己的。我的代码的(当前)迭代在com.webmail.GetItemResponseType resp = binding.GetItem(getItemType);中返回“Id is malformed”错误。返回ResponseMessages.Items.MessageText值。这会导致返回的项目为空值。 我的代码如下:

public static void GetCalendarItem() 
{ 
    // Set up the binding with credentials and URL. 
    com.webmail.ExchangeServiceBinding binding = new com.webmail.ExchangeServiceBinding(); 
    binding.Credentials = new System.Net.NetworkCredential("steve.kershaw", "mypasswordhere", "domain.com"); 
    binding.Url = @"https://webmail.com/ews/exchange.asmx"; 

    // Get the Itemtype... 
    com.webmail.GetItemType getItemType = new com.webmail.GetItemType(); 

    ////getItemType. 
    //com.webmail.GetItemResponseType getItemResponseType = binding.GetItem(getItemType); 
    // Create the response shape. 
    com.webmail.ItemResponseShapeType responseShape = new com.webmail.ItemResponseShapeType(); 
    responseShape.BodyType = com.webmail.BodyTypeResponseType.Text; 
    responseShape.BodyTypeSpecified = true; 
    responseShape.BaseShape = com.webmail.DefaultShapeNamesType.Default; 
    // Add more properties to the request. 
    com.webmail.PathToUnindexedFieldType[] sensitivity = new com.webmail.PathToUnindexedFieldType[1]; 
    sensitivity[0] = new com.webmail.PathToUnindexedFieldType(); 
    sensitivity[0].FieldURI = com.webmail.UnindexedFieldURIType.itemSensitivity; 
    responseShape.AdditionalProperties = sensitivity; 
    // Add the response shape to the request. 
    getItemType.ItemShape = responseShape; 

    // Identify the items to get. 
    com.webmail.ItemIdType[] items = new com.webmail.ItemIdType[2]; 
    items[0] = new com.webmail.ItemIdType(); 
    items[0].Id = "AAAlAE1BQG1"; 
    items[0].ChangeKey = "DwAAABYAAAA"; 
    items[1] = new com.webmail.ItemIdType(); 
    items[1].Id = "AAAlAE1BQG1"; 
    items[1].ChangeKey = "DwAAABYAAAA"; 

    // Add items to the request. 
    getItemType.ItemIds = items; 

    try 
    { 
     // Send the request and get the response. 
     com.webmail.GetItemResponseType resp = binding.GetItem(getItemType); 
     com.webmail.ArrayOfResponseMessagesType aormt = resp.ResponseMessages; 
     com.webmail.ResponseMessageType[] rmta = aormt.Items; 

     foreach (com.webmail.ResponseMessageType rmt in rmta) 
     { 
      com.webmail.ItemInfoResponseMessageType iirmt = (rmt as com.webmail.ItemInfoResponseMessageType); 
      com.webmail.ArrayOfRealItemsType aorit = iirmt.Items; 
      com.webmail.ItemType[] myItems = aorit.Items; 

      // Determine the type for each item and cast to the approriate type. 
      foreach (com.webmail.ItemType it in myItems) 
      { 
       // Check whether it is an e-mail. 
       if (it is com.webmail.MessageType) 
       { 
        com.webmail.MessageType message = (it as com.webmail.MessageType); 
       } 
       // Determine whether it is a calendar item. 
       else if (it is com.webmail.CalendarItemType) 
       { 
        com.webmail.CalendarItemType calendar = (it as com.webmail.CalendarItemType); 
       } 
       else 
       { 
        // Check for other item types. 
       } 
      } 
     } 
    } 
    catch (Exception e) 
    { 
     throw new Exception("GetItem failed"); 
    } 
} 

有没有一种简单的方法,只是拉一个特定日期范围内的日历所有的约会?

+0

我猜没有人有答案! :-( – stevekershaw 2013-05-02 14:32:52

+0

你的项目Id和ChangeKey看起来可怕的错误,他们应该是这样的形式。<典型值:项目Id标识= “AQMkADkyZTQxNjUzLTcwZTQtNGRlNS04M2VmLWMxYmIBNWJiADUwZTYARgAAA4Kt4mOTlXZJrZx0v5cQm8IHAISmF1hx/2pAhQBTVUBmYgoAAAMhAAAAhKYXWHH/akCFAFNVQGZiCgACMstDjAAAAA ==” ChangeKey = “DwAAABYAAACEphdYcf9qQIUAU1VAZmIKAAIyy5CE”/> CreateItem应该已经回到你这些ID。 – 2014-08-20 07:34:22

回答

1

Steve,你从哪里得到了你放进GetItem的ID的地方? 通常的路线是致电FindItem与邮箱smtp和从/到日期。您可以使用FindItem获取大多数字段,但例如而不是正文文本,因此您可以使用从FindItem返回的ID之一调用GetItem。

请注意,FindItem也会返回所有出现的重复事件,您可能希望首先从这些事件中获取主事件。 看到我的答案在Delete recurring calendar item with PHP EWS?

我不能给你任何C代码,我在Delphi中通过我自己的SOAP调用来完成所有这些。

相关问题