因为微软官方的那个 WebService API 不能满足我的需求,所以我现在得改变方式来用另外的方式来掉WebService(这种方式实际上就是官方提供API文件中所使用的方法,这个其实文档里面满足了,但是文件没更新,没有相对应的方法,这个我没办法,所以才这样做啊。)

首先,我们建立一个基础的架构,这个呢,先打开 vs2005 ,然后建立一个工程,名字就叫做 ExchangeEWS吧。
然后 引用WebService,比如 http://mail.xxx.com/ews/Exchange.asmx ,然后看它引用过来的 cs 代码。拷贝过来,然后在吧原来的命名空间改成 ExchangeEWS。 这个是第一步完成了。
现在来完成一个功能,这个功能就是我前面日程提到的,1.无法删除附件、2.无法通过副日程得到主日程,现在贴代码。
Code
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Text;
  5 using System.Net;
  6 
  7 
  8 namespace ExchangeEWS
  9 {
 10     class Program
 11     {
 12         static void Main(string[] args)
 13         {
 14             ExchangeServiceBinding esb = new ExchangeServiceBinding();
 15 
 16             esb.Credentials = new NetworkCredential("MailAdmin", "App1234", "xxx.com");
 17             esb.RequestServerVersionValue = new RequestServerVersion() { Version = ExchangeVersionType.Exchange2007_SP1 };
 18             esb.ExchangeImpersonation = new ExchangeImpersonationType();
 19 
 20             esb.ExchangeImpersonation.ConnectingSID = new ConnectingSIDType()
 21             {
 22                 PrimarySmtpAddress = "liujunxun@lab.com"
 23 
 24             }; ;
 25 
 26             esb.Url = @"http://mail.lab.com/EWS/Exchange.asmx";
 27 
 28             string id = GetRecurringMasterFromOccurrenceId(esb, new ItemIdType()
 29                {
 30                    ChangeKey = "DwAAABYAAACmByZGocQSToqby5KUV81FAqM8fV5y",
 31                    Id = "AAMkADdlNTVhMTlmLWYxNWQtNDNlZi1hMTIyLTNkZTRkN2VkN2ZlNgFRAAiIy+JqlstAAEYAAAAAixAkoQ62ZEGeBtVLJhjjZwcApgcmRqHEEk6Km8uSlFfNRQFpAZtwWgAApgcmRqHEEk6Km8uSlFfNRQKjPH0b6AAAEA=="
 32                }).Id;
 33 
 34 
 35 
 36         }
 37 
 38         /// <summary>
 39         /// Deletes an attachment and returned the Id and updated change key of the
 40         /// parent item
 41         /// </summary>
 42         /// <param name="binding">Exchange binding to use</param>
 43         /// <param name="attachmentId">Attachment id to delete</param>
 44         /// <returns>Id and updated change key of the parent item</returns>
 45         ///
 46         public static ItemIdType DeleteAttachmentAndGetItem(
 47                          ExchangeServiceBinding binding,
 48                          RequestAttachmentIdType attachmentId)
 49         {
 50             DeleteAttachmentType request = new DeleteAttachmentType();
 51             request.AttachmentIds = new RequestAttachmentIdType[] { attachmentId };
 52             DeleteAttachmentResponseType response =
 53                         binding.DeleteAttachment(request);
 54             DeleteAttachmentResponseMessageType responseMessage =
 55                         response.ResponseMessages.Items[0] as
 56                               DeleteAttachmentResponseMessageType;
 57             if (responseMessage.ResponseCode != ResponseCodeType.NoError)
 58             {
 59                 throw new Exception("Delete attachment failed.  Response code: " +
 60                            responseMessage.ResponseCode.ToString());
 61             }
 62             else
 63             {
 64                 // Normally, we could just return the root item id from our Delete
 65                 // Attachment response.  But I want to prove a point here, so we will
 66                 // call GetItem and see what happens.
 67 
 68                 // There is a bug here.
 69                 //
 70                 GetItemType getRequest = new GetItemType();
 71                 getRequest.ItemIds = new BaseItemIdType[] {
 72                           responseMessage.RootItemId };
 73                 getRequest.ItemShape = new ItemResponseShapeType(
 74                                     ) { BaseShape = DefaultShapeNamesType.IdOnly };
 75                 GetItemResponseType getResponse = binding.GetItem(getRequest);
 76                 ItemInfoResponseMessageType getResponseMessage =
 77                          getResponse.ResponseMessages.Items[0] as
 78                                        ItemInfoResponseMessageType;
 79 
 80                 if (getResponseMessage.ResponseCode != ResponseCodeType.NoError)
 81                 {
 82                     throw new Exception("GetItem failed.  Response code: " +
 83                              getResponseMessage.ResponseCode.ToString());
 84                 }
 85                 else
 86                 {
 87                     return getResponseMessage.Items.Items[0].ItemId;
 88                 }
 89             }
 90         }
 91 
 92 
 93 
 94         public static ItemIdType GetRecurringMasterFromOccurrenceId(
 95     ExchangeServiceBinding binding,
 96     ItemIdType idOfOccurrence)
 97         {
 98             // Create the RecurringMasterItemIdType instance that we will pass to GetItem.
 99             //
100             RecurringMasterItemIdType recurringMasterId =
101                 new RecurringMasterItemIdType();
102             recurringMasterId.OccurrenceId = idOfOccurrence.Id;
103             recurringMasterId.ChangeKey = idOfOccurrence.ChangeKey;
104 
105             GetItemType getItemRequest = new GetItemType();
106             getItemRequest.ItemShape = new ItemResponseShapeType();
107             getItemRequest.ItemShape.BaseShape = DefaultShapeNamesType.IdOnly;
108 
109             getItemRequest.ItemIds = new RecurringMasterItemIdType[] {
110         recurringMasterId };
111 
112             // Make the call to the GetItem web method, check for success
113             // and return the item id accordingly
114             //
115             GetItemResponseType response = binding.GetItem(getItemRequest);
116             ItemInfoResponseMessageType responseMessage =
117                 response.ResponseMessages.Items[0] as ItemInfoResponseMessageType;
118 
119             if (responseMessage.ResponseCode != ResponseCodeType.NoError)
120             {
121                 throw new Exception("GetItem failed with response code " +
122                          responseMessage.ResponseCode.ToString());
123             }
124 
125             return responseMessage.Items.Items[0].ItemId;
126         }
127 
128 
129     }
130 }
131 

转载于:https://www.cnblogs.com/clock2008/archive/2009/08/04/1538595.html

exchange EWS 开发随笔二相关推荐

  1. 如何提高码农产量,基于ASP.NET MVC的敏捷开发框架之移动端开发随笔二

    前言 在前一篇文章中我已经做过开篇,接下来的随笔会详细讲一下我们的开发框架是如何实现的,专业的事由专业的人来讲,以后就由我们的高级码农小李英文名查尔斯和他的师父厂长(因为姓陈,酷爱摄影,我们的文艺片都 ...

  2. 3D数学基础:图形与游戏开发---随笔二

    笛卡尔坐标系统 笛卡尔不仅创立了解析集合,将当时完全分离的代数学和几何学联系到一起,还在回答"怎样判断某件事物是真的?"这个哲学问题上迈出了一大步,使后来的一代代哲学家能够轻松起来 ...

  3. 软件开发随笔系列二——关于架构和模型

    软件开发随笔系列二--关于架构和模型 文章目录 软件开发随笔系列二--关于架构和模型 软件模型 功能模型 概念层 边界 参与方 分组分类 逻辑层 功能组织图 层次.模块化 接口 流程模型 概念层 业务 ...

  4. 软件开发随笔系列一——分布式架构实现

    软件开发随笔系列一--分布式架构实现 文章目录 软件开发随笔系列一--分布式架构实现 理论基础 分布式架构的实现 内核框架 应用开发 基础设施 服务接入 监控 日志监控 调用链监控 度量指标监控 健康 ...

  5. IOS 逆向开发(二)密码学 HASH

    IOS 逆向开发(二)密码学 HASH 1. HASH算法简介 1.1 HASH是什么? 1.2 Hash的特点 1.3 Hash的作用 1.4 Hash有哪些流行的算法 1.5 Hash算法的碰撞 ...

  6. php后台开发(二)Laravel框架

    php后台开发(二)Laravel框架 为了提高后台的开发效率,往往需要选择一套适合自己的开发框架,因此,选择了功能比较完善的Laravel框架,仔细学来,感觉和Python语言的框架Django非常 ...

  7. 【Visual C++】游戏开发笔记二十七 Direct3D 11入门级知识介绍

    游戏开发笔记二十七 Direct3D 11入门级知识介绍 作者:毛星云    邮箱: happylifemxy@163.com    期待着与志同道合的朋友们相互交流 上一节里我们介绍了在迈入Dire ...

  8. PCL-1.8.1从源码搭建开发环境二(FLANN库的编译)

    原文首发于微信公众号「3D视觉工坊」,PCL-1.8.1从源码搭建开发环境二(FLANN库的编译) 首先,快速近似最近邻搜索库FLANN-Fast Library for Approximate Ne ...

  9. 蓝鸥Unity开发基础二——课时20 接口

    蓝鸥Unity开发基础二--课时20 接口 一.接口 使用interface关键字定义接口 接口定义一组成员单不直接实现它们 二.实现接口 实现接口的任何类都必须实现其所有的成员方法 接口不能直接实例 ...

最新文章

  1. 正则表达式——全部符号解释(详解)
  2. 如何在Hadoop上编写MapReduce程序
  3. 安川西格玛7驱动器手册_什么是伺服驱动器?选型的原则有哪些?
  4. cmd imp导入dmp文件_cmd 导入oracle数据的dmp文件
  5. 2017.4.26 组合数问题 思考记录
  6. iis7 64位 操作excel的一系列问题(未完待续)
  7. loadrunner提示:Cannot save the license information because acceses to the registry is denied
  8. mysql中的模糊查询(非原创)
  9. springboot国际化04
  10. 固定尺寸内存块的缓冲队列类及C++实现源代码
  11. 三轴合并_用两套乐高60107合并成铰接式云梯消防车,看看和60112有什么区别
  12. 对Python的初认识以及期待
  13. 对于处理上传图片添加水印的简单操作
  14. PowerPoint的巧妙使用就可造就一场经济而又专业的知识竞赛场面
  15. php 获取access token,百度应用获取Access Token
  16. chrome插件商店(Chrome插件商店)
  17. Nachos Lab3 同步机制
  18. win10一键激活,解除SymantecEndpointProtection的自动拦截
  19. java程序员转正述职报告PPT
  20. 使用Vim/Neovim编辑二进制文件

热门文章

  1. 回溯法 —— 算法框架及应用
  2. UnityShader9.1:光照基础实例
  3. bzoj 1706: [usaco2007 Nov]relays 奶牛接力跑(倍增floyd)
  4. 51nod-1065:最小正子段和
  5. Rabbitmq基本原理和架构
  6. matlab2c使用c++实现matlab函数系列教程-disp函数
  7. -函数-MATLAB提供的函数/主子函数/匿名-嵌套函数
  8. 配置Sublime Text3和MASM32编译汇编的问题汇总
  9. intel 酷睿core系列cpu的类型:U M H HQ MQ
  10. ZooKeeper CentOS7上安装