zoukankan      html  css  js  c++  java
  • Exhange2007 专题(二)通过Web service对Exhange进行二次开发

    Exchange2007提供了EWS Managed API和Web Service 两种形式的开发方式。这里主要讲述Web Service形式的开发方式。

    Web Service目前还不支持的包括:

    1.文件夹关联信息消息;

    2.通过代理访问;

    3.支持公共文件夹;

    4.管理员级别的函数支持(Exchange管理功能)

    5.文件夹访问控制;

    6.委托管理;

    客户端与EWS通信图

     

    在VS2010中添加Exchange 2007 Web Service

    1.在项目中右击Service References -->点击Add Service References-->点击Advanced-->点击Add Web Reference

    2.在URL中输入引用地址:https://domain/EWS/exchange.asmx

    3.Add Reference

    4.在代码中using Namespace.WebServiceName

    下面的例子通过编程获取收件箱中文件夹的ID:

    static void Main(string[] args)
    {
    
      // 创建Web Service服务 绑定
      //
      ExchangeServiceBinding binding = new ExchangeServiceBinding();
      binding.Url = @"https://yourserver/ews/exchange.asmx";
      binding.Credentials = new NetworkCredential("username", "password", "domain");
    
      Dictionary<DistinguishedFolderIdNameType, FolderIdType> mapping;
    
      // 通过绑定的用户名映射对应的收件箱中文件夹的ID
      //
      mapping = GetAllDistinguishedFolderIds(binding);
      Console.WriteLine("The Id of the inbox is: \r\n" +
                   mapping[DistinguishedFolderIdNameType.inbox].Id);
      Console.WriteLine();
      Console.WriteLine("The Id of sentitems is: \r\n" +
                   mapping[DistinguishedFolderIdNameType.sentitems].Id);
    }
    

    创建 distinguished的文件夹名映射到文件夹的ID

    GetAllDistinguishedFolderIds方法

    public static Dictionary<DistinguishedFolderIdNameType, FolderIdType>
                     GetAllDistinguishedFolderIds(ExchangeServiceBinding binding)
    {
      // 创建请求  //
      GetFolderType getFolderRequest = new GetFolderType();
      getFolderRequest.FolderIds = GetAllDistinguishedFolderIdsForRequest();
      getFolderRequest.FolderShape = new FolderResponseShapeType();
    
    
      getFolderRequest.FolderShape.BaseShape = DefaultShapeNamesType.IdOnly;
    
      // 响应  //
      GetFolderResponseType response = binding.GetFolder(getFolderRequest);
      ResponseMessageType[] responseMessages =
                            response.ResponseMessages.Items;
    
      Dictionary<DistinguishedFolderIdNameType, FolderIdType> result =
                   new Dictionary<DistinguishedFolderIdNameType, FolderIdType>();
    
      Array enumValues =
                   Enum.GetValues(typeof(DistinguishedFolderIdNameType));
    
      // 遍历每一个消息
      for (int folderIndex = 0;
           folderIndex < responseMessages.Length;
           folderIndex++)
      {
        FolderInfoResponseMessageType folderInfoMessage =
            responseMessages[folderIndex] as FolderInfoResponseMessageType;
        FolderIdType folderId = null;
        if (folderInfoMessage.ResponseClass == ResponseClassType.Success)
        {
          // 获取ID
          folderId = folderInfoMessage.Folders[0].FolderId;
        }
    
        result.Add(
             (DistinguishedFolderIdNameType)enumValues.GetValue(folderIndex),
             folderId);
      }
      return result;
    }
    
    

    检索所有的文件夹

    代码
    public static BaseFolderIdType[] GetAllDistinguishedFolderIdsForRequest()
    {
    Array enumValues
    =
    Enum.GetValues(
    typeof(DistinguishedFolderIdNameType));

    BaseFolderIdType[] result
    = new BaseFolderIdType[enumValues.Length];
    for (int folderIndex = 0; folderIndex<enumValues.Length; folderIndex++)
    {
    DistinguishedFolderIdType id
    = new DistinguishedFolderIdType();
    id.Id
    = (DistinguishedFolderIdNameType)
    enumValues.GetValue(folderIndex);
    result[folderIndex]
    = id;
    }

    return result;
    }

    输出结果:

    上述事例讲述了如何通过引用Exchange Web Serivce,获取Exchange中的一些信息,下节我们将围绕Exchange编程开发这一主题进行讲述。

  • 相关阅读:
    c调用python记录
    linux 进程内存基础
    doubango类面向对象研究
    HBuilderX 连接 逍遥模拟器 之 解决没法找到模拟器设备 问题
    Application,Session,Cookie,ViewState和Cache区别
    每个.Net开发人员应该下载的十种必备工具
    ASP.NET面试资料
    .net 主题与样式
    浅谈C#当中的out关键字
    5ResponseModel响应模型
  • 原文地址:https://www.cnblogs.com/tmywu/p/1783116.html
Copyright © 2011-2022 走看看