文档章节

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

剑禅觅心
 剑禅觅心
发布于 2016/08/01 21:28
字数 387
阅读 3
收藏 0

输出错误信息:

                 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;
}
}
}

本文转载自:http://blog.csdn.net/amohan/article/details/12870855

剑禅觅心
粉丝 6
博文 224
码字总数 0
作品 0
深圳
高级程序员
私信 提问
Exchange Server 2016安装部署系列一:Exchange 简述,环境需求及部署规划

Exchange Server 2016简述 MicrosoftExchange Server 2016 为 Exchange Server(提供电子邮件、日程安排和用于自定义协作与消息传送服务应用程序的工具的消息传送平台)引入了一组新技术、功...

Wish_亮
2018/06/28
0
0
RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.3版本全新发布

1、RDIFramework.NET框架介绍 RDIFramework.NET,基于.NET的快速信息化系统开发、整合框架,为企业或个人快速开发系统提供了强大的支持,开发人员不需要开发系统的基础功能和公共模块,框架自...

NET快速开发框架
2018/12/21
0
0
springboot+rabbitmq整合

1.安装好rabbitmq 2.新建一个springBoot项目:rabbitmq_demo 3.添加pom依赖: 4.application.properties: 5.启动类声明一个Queue,用于测试: 多场景实现: 1.单生产者和单消费者 生产者1: ...

狼王黄师傅
2018/10/19
0
0
认识一下WebService应用的简单开发

在开发中,不免遇到两个不同系统交互的问题,比如数据信息同步、数据信息获取等,解决问题的途径有多种,今天带大家认识一下 WebService,看看它在实际应用中的处理。 一、什么是WebService ...

海岸线的曙光
2018/07/09
0
0
Exchange 2010配置Autodiscover服务for Outlook2016

  Outlook 2016 can only add Exchange accounts using autodiscover. This is a change from Outlook 2013. If you want to use Outlook 2016 with an Exchange account, you need to use......

lorysun
2018/06/26
0
0

没有更多内容

加载失败,请刷新页面

加载更多

八、RabbitMQ的集群原理

集群架构 写在前面 RabbitMQ集群是按照低延迟环境设计的,千万不要跨越WAN或者互联网来搭建RabbitMQ集群。如果一定要在高延迟环境下使用RabbitMQ集群,可以参考使用Shovel和Federation工具。...

XuePeng77
今天
1
0
mac系统下,brew 安装mysql,用终端可以连接,navicat却连接不上?

问题: 1.报错? 2059 - Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(../Frameworks/caching_sha2_password.so, 2): image not found 2.自己通过设置,已经把密......

写bug的攻城狮
昨天
2
0
老生常谈,HashMap的死循环

问题 最近的几次面试中,我都问了是否了解HashMap在并发使用时可能发生死循环,导致cpu100%,结果让我很意外,都表示不知道有这样的问题,让我意外的是面试者的工作年限都不短。 由于HashMap...

群星纪元
昨天
5
0
拉普拉斯算子

拉普拉斯算子是二阶微分算子。 我们知道,一维离散信号一阶微分公式如下: 相应的,一维离散信号二阶微分公式如下: 由于图像有x和y两个方向,因此图像信号属于二维离散信号。其在x,y两个...

yepanl
昨天
3
0
记录"正则表达式"

详细请查看我的博客:https://blog.enjoytoshare.club/article/RegularExpression.html 1 写在前面 正则表达式(Regular Expression)在代码中常常简写为regex。正则表达式通常被用来检索、替...

wugenqiang
昨天
3
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部