微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

exchange webservice访问类日程新增和删除

@H_502_2@

输出错误信息:

                 assistant.WriteFile("C:\\DEBUG.txt","Length:" + diResponse.ResponseMessages.Items.Length.ToString());
                 assistant.WriteFile("C:\\DEBUG.txt","Length:" + diResponse.ResponseMessages.Items[0].MessageText);
                 assistant.WriteFile("C:\\DEBUG.txt","Length:" + diResponse.ResponseMessages.Items[0].MessageXml.ToString());
                 assistant.WriteFile("C:\\DEBUG.txt","Length:" + diResponse.ResponseMessages.Items[0].ResponseClass.ToString());
                 assistant.WriteFile("C:\\DEBUG.txt","Length:" + diResponse.ResponseMessages.Items[0].ResponseCodeSpecified.ToString());
                 assistant.WriteFile("C:\\DEBUG.txt","Length:" + diResponse.ResponseMessages.Items[0].ResponseCode.ToString());

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Text;
using HPCalendarSyncToPT1.Common;
using HPCalendarSyncToPT1.Exchange;

namespace HPCalendarSyncToPT1
{
public class ExchangeWebService
{
ExchangeServiceBinding esb = null;
public ExchangeWebService(string account,string password,string domain)
{
esb = new ExchangeServiceBinding();
esb.Credentials = new NetworkCredential(account,password,domain);
esb.Url = ConfigurationManager.AppSettings["pt1exchange_ws_url"];
}

public bool DeleteItem(string itemId,string changeKey)
{
bool result = false;
DeleteItemType d = new DeleteItemType();
ItemIdType id = new ItemIdType();
id.Id = itemId;
id.ChangeKey = changeKey;
d.ItemIds = new ItemIdType[] {id};
d.SendMeetingCancellations = CalendarItemCreateOrDeleteOperationType.SendToNone;
d.SendMeetingCancellationsspecified = true;
DeleteItemResponseType deleteItemResponse = esb.DeleteItem(d);

if (deleteItemResponse != null)
{
if (deleteItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClasstype.Error)
{
Console.WriteLine(deleteItemResponse.ResponseMessages.Items[0].MessageText);
}
else
{
Console.WriteLine("删除日程成功!");
result = true;
}
}
return result;
}

public ExchangeCalendarItemResult CreateAppointmentEWS(Calendar item)
{
// Create the appointment.
CalendarItemType appointment = new CalendarItemType();

// Add item properties to the appointment.
appointment.Body = new BodyType();
appointment.Body.BodyType1 = BodyTypeType.Text;
appointment.Body.Value = "";//正文内容
//appointment.Categories = new string[] { "aaa","bbb" };//类别
appointment.Importance = ImportanceChoicesType.High;
appointment.ImportanceSpecified = true;
appointment.ItemClass = "IPM.Appointment";
appointment.Subject = item.Subject;//标题

// Add calendar properties to the appointment.
appointment.Start = item.StartTime;
appointment.StartSpecified = true;
appointment.End = item.EndTime;
appointment.EndSpecified = true;
//appointment.HasAttachments = item.HasAttachment;

 

// Identify the destination folder that will contain the appointment.
distinguishedFolderIdType folder = new distinguishedFolderIdType();
folder.Id = distinguishedFolderIdNameType.calendar;

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

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

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

// The SendMeetingInvitations attribute is required for calendar items.
createItemRequest.SendMeetingInvitations = CalendarItemCreateOrDeleteOperationType.SendToNone;
createItemRequest.SendMeetingInvitationsspecified = true;

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

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

ExchangeCalendarItemResult r = null;
try
{
// Send the request and get the response.
CreateItemResponseType createItemResponse = esb.CreateItem(createItemRequest);

// Get the response messages.
ResponseMessageType[] rmta = createItemResponse.ResponseMessages.Items;

foreach (ResponseMessageType rmt in rmta)
{
ArrayOfRealItemsType itemArray = ((ItemInfoResponseMessageType)rmt).Items;
ItemType[] items = itemArray.Items;

// Get the item identifier and change key for each item. r = new ExchangeCalendarItemResult(); if (items != null) foreach (ItemType itm in items) { Console.WriteLine("Item identifier: " + itm.ItemId.Id); Console.WriteLine("Item change key: " + itm.ItemId.ChangeKey); r.ItemId = itm.ItemId.Id; r.ItemKey = itm.ItemId.ChangeKey; } } } catch (Exception e) { Console.WriteLine("Error Message: " + e.Message); } return r; } } }

@H_502_2@ @H_502_2@
@H_502_2@
@H_502_2@

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐