exchange|exchange webservice访问类(日程新增和删除)
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.Valuehttps://www.it610.com/article/= "";
//正文内容
//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;
【exchange|exchange webservice访问类(日程新增和删除)】 // 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;
}
}
}
推荐阅读
- Android7.0|Android7.0 第三方应用无法访问私有库
- 打开Anaconda|打开Anaconda Navigator 时报错 error 5 拒绝访问
- Nginx进阶(1)——nginx本地代理配置访问node服务
- OkHttp的Internal让外部对象可以访问私有方法
- 后台|NATAPP内网穿透通过nginx实现一个端口访问多个不同端口服务
- JavaCV的摄像头实战之五(推流)
- 为什么内部类中访问局部变量,局部变量需要final修饰
- 小说域名怎么才能在微信中正常访问而不被微信拦截(366tool免费提供小说防封方案)
- 垃圾回收机制与内存管理
- JavaCV的摄像头实战之四(抓图)