Exchange2010 创建没有邮件联系人的问题

公司exchange环境升级到了2010 ,于是用以前的单元测试过了一遍,发现在创建没有邮件地址的时候居然报错,但是把环境改到了2007 却通过,通过工具Fiddler,发现差别如下:

Exchange2007<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2007_SP1" />
    <t:TimeZoneContext>
      <t:TimeZoneDefinition Id="China Standard Time" />
    </t:TimeZoneContext>
  </soap:Header>
  <soap:Body>
    <m:CreateItem MessageDisposition="SaveOnly">
      <m:Items>
        <t:Contact />
      </m:Items>
    </m:CreateItem>
  </soap:Body>
</soap:Envelope>

Exchange2010<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2007_SP1" />
    <t:TimeZoneContext>
      <t:TimeZoneDefinition Id="China Standard Time" />
    </t:TimeZoneContext>
  </soap:Header>
  <soap:Body>
    <m:CreateItem MessageDisposition="SaveOnly">
      <m:Items>
        <t:Contact>
          <t:EmailAddresses />
        </t:Contact>
      </m:Items>
    </m:CreateItem>
  </soap:Body>
</soap:Envelope>

明显多了一个 EmailAddresses 这个字段,经过反编译代码发现

原来现在这个字段已经是个对象了,所以在处理的时候会自动加上Emailaddressses。

怎么办呢?于是我想到一种办法,既然能在Exchange2010的服务器上采用2007的方式访问,而且是正常的,反而用2010 的方式访问不正常。那为了不干扰别的地方,我采用在局部地方采用原来2007 的访问方式,在程序实例化的时候,采用加载两种不同的服务,分别是当前版本和2007版本

代码如下:

初始化 service = new ExchangeService(RequestedServerVersion)
                          {
                              Url = new Uri(config.EWSServiceUrl),
                              Credentials = new NetworkCredential(config.ExchangeAdministrator,
                                                                  config.ExchangeAdministratorPassword,
                                                                  config.Domain),
                             // ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SID, "MailAdmin")
                          };

            service2007 = new ExchangeService( ExchangeVersion.Exchange2007_SP1)
            {
                Url = new Uri(config.EWSServiceUrl),
                Credentials = new NetworkCredential(config.ExchangeAdministrator,
                                                    config.ExchangeAdministratorPassword,
                                                    config.Domain),
                // ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SID, "MailAdmin")
            };

 

在创建实体的时候均采用2007的方式(因为2010 可以兼容这个创建的方法)

创建联系人        /// <summary>
        /// 创建一个联系人实例,Contact实例不能通过new Contact的方式实例化
        /// </summary>
        /// <returns></returns>
        public Contact CreateContactEntity()
        {
            Contact contact = new Contact(service2007);
            return contact;
        }


 

保存的代码被我改成如下

保存联系人        public string SaveContact2007(Contact data, string account)
        {
            var service1 = data.Service;
            string mailAddress = string.Format("{0}@{1}", account, ConfigService.CreateInstance().MailDomain);
            if (service1.ImpersonatedUserId == null || service1.ImpersonatedUserId.Id != mailAddress)
            {
                service1.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, mailAddress);
            }

            data.Save();
            return data.Id.UniqueId;
        }

 

这样,修改的方法亦是如此。

转载于:https://www.cnblogs.com/clock2008/archive/2010/06/25/1765100.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值