none
exchang web service 删除约会 RRS feed

  • 常规讨论

  • 为什么会删除约会失败,请大家帮忙
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using testmeeting.ExchangeWebService;
    using System.Net.Security;
    using System.Xml.Serialization;
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    //using System.Net.Security;
    namespace testmeeting
    {
      public class Program
      {
        public static string id;
        public static string changeid;
        static void Main(string[] args)
        {
          string url = "https://localhost/EWS/Exchange.asmx";
          DateTime start = Convert.ToDateTime("2011-03-20 4:00");
          DateTime end = Convert.ToDateTime("2011-03-20 4:30");
          string emailaddress = "epro3@ex2007.com"; ;
          SendAppointment(url, start, end, emailaddress); 
        }
        public static void del(ExchangeServiceBinding esb,string id)
        {
          Util.SetCertificatePolicy();
          DeleteItemType dit = new DeleteItemType();
          dit.ItemIds = new BaseItemIdType[1];
          ItemIdType iit = new ItemIdType();
          iit.Id = id;
          //iit.ChangeKey = changeid;
          dit.ItemIds[0] = iit;
          DeleteItemResponseType de = esb.DeleteItem(dit);
          if (de.ResponseMessages.Items.Length > 0 && de.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)
          {
            Console.Write("ɾ��ɹ�");
            Console.Read();
          }
          else
          {
            Console.Write("ɾ��ʧ��");
            Console.Read();
          }
        }
        public static void SendAppointment(string url, DateTime start, DateTime end, string emailaddress)
        {
          ExchangeServiceBinding esb = new ExchangeServiceBinding();
          esb.Url = url;
          esb.Credentials = new NetworkCredential("Administrator", "epro-001", "ex2007.com");
          CalendarItemType appointment = new CalendarItemType();
          appointment.Body = new BodyType();
          appointment.Body.BodyType1 = BodyTypeType.Text;
          appointment.Body.Value = "ͬ���û�æ��";
          appointment.Importance = ImportanceChoicesType.High;
          appointment.ImportanceSpecified = true;
          appointment.ItemClass = "IPM.Appointment";
          appointment.Subject = "ͬ���û�æ��";
          appointment.Start = start;
          appointment.StartSpecified = true;
          appointment.End = end;
          appointment.EndSpecified = true;
          appointment.LegacyFreeBusyStatus = LegacyFreeBusyType.Busy;
          DistinguishedFolderIdType folder = new DistinguishedFolderIdType();
          folder.Id = DistinguishedFolderIdNameType.calendar;
          folder.Mailbox = new EmailAddressType();
          folder.Mailbox.EmailAddress = emailaddress;
          NonEmptyArrayOfAllItemsType arrayOfItems = new NonEmptyArrayOfAllItemsType();
          arrayOfItems.Items = new ItemType[1];
          arrayOfItems.Items[0] = appointment;
          CreateItemType createItemRequest = new CreateItemType();
          createItemRequest.SendMeetingInvitations = CalendarItemCreateOrDeleteOperationType.SendToAllAndSaveCopy;
          createItemRequest.SendMeetingInvitationsSpecified = true;
          createItemRequest.SavedItemFolderId = new TargetFolderIdType();
          createItemRequest.SavedItemFolderId.Item = folder;
          createItemRequest.Items = arrayOfItems;
          try
          {
            Util.SetCertificatePolicy();
            CreateItemResponseType createItemResponse = esb.CreateItem(createItemRequest);
            ResponseMessageType[] rmta = createItemResponse.ResponseMessages.Items;
            foreach (ResponseMessageType rmt in rmta)
            {
              ArrayOfRealItemsType itemArray = ((ItemInfoResponseMessageType)rmt).Items;
              ItemType[] items = itemArray.Items;
              foreach (ItemType item in items)
              {
                Console.WriteLine("Item identifier: " + item.ItemId.Id);
                Console.WriteLine("Item change key: " + item.ItemId.ChangeKey);
                id = item.ItemId.Id;
                changeid = item.ItemId.ChangeKey;
              }
            }
            ItemInfoResponseMessageType responseMessage = createItemResponse.ResponseMessages.Items[0] as ItemInfoResponseMessageType;
            ItemIdType items2 = responseMessage.Items.Items[0].ItemId;
            del( esb, items2.Id);
            del(esb, id);
          }
          catch (Exception e)
          {
            Console.WriteLine("Error Message: " + e.Message);
            Console.ReadLine();
          }
        }
      }
    }
    2011年3月24日 2:47

全部回复