最近需要研究下
Exchange获取联系人列表,EWS确实强大,奈何内容太多,死活弄不出来。(度娘不给力还得考谷哥)被俺搜到老外的这个帖子:http://stackoverflow.com/questions/2071668/how-to-get-contact-list-from-exchange-server(不能带连接自己贴吧!)
得知这个还是要靠API啊(http://www.microsoft.com/en-us/download/details.aspx?id=35371 )。放送代码如下:
不会代码排版啊!
,感谢Exchange Lab我没有测试环境,用的实验室的EWS。原帖地址http://bbs.exchangecn.com/read.php?tid-6579.html 我买了账号密码大家自己去买吧!(发帖能挣回来不?)
//指定
证书验证回调方法,Lamda表达式,直接返回true,表示忽略所有错误 《解决SSL证书错误,导致的无法连接》
ServicePointManager.ServerCertificateValidationCallback = (source, cert, chain, errors) => true;
ExchangeService esb = new ExchangeService();
esb.Credentials = new NetworkCredential("ex****", "ex****", "exchangecn");//没环境的用户名密码自己去取吧!
esb.Url = new Uri("https://lab.exchangecn.com/EWS/exchange.asmx");
//指定证书《解决401未授权错误》
esb.UseDefaultCredentials = true;
//前面是连接,主要的,因为证书
问题所以需要注释后面的两条代码。
//下面是获取内容代码,稍改了下
//联系人列表展示《本人使用ASP.NET测试,页面放了个Lable显示内容,所以拼了个字符串,各位自己改吧》
string message = string.Empty;
foreach (var v in svc.FindItems(WellKnownFolderName.Contacts, new ItemView(999999)))
{
Contact contact = v as Contact;
ContactGroup contactGroup = v as ContactGroup;
//v.Load(); // Turns out you don't need to load for basic props.
if (contact != null)
{
message += string.Format("联系人: {0} [{1}] <br />",
contact.DisplayName,
contact.EmailAddresses[EmailAddressKey.EmailAddress1]);
}
else if (contactGroup != null)
{
message += string.Format("联系人分组: {0} <br />", contactGroup.DisplayName);
switch (svc.RequestedServerVersion)
{
case ExchangeVersion.Exchange2007_SP1:
ExpandGroupResults groupResults
= svc.ExpandGroup((contactGroup.Id));
foreach (var member in groupResults)
{
message += string.Format("+ {0} [{1}] <br />",
member.Name, member.Address);
}
break;
case ExchangeVersion.Exchange2010:
foreach (GroupMember member in contactGroup.Members)
{
message += string.Format("+ {0} [{1}] <br />",
member.AddressInformation.Name,
member.AddressInformation.Address);
}
break;
default:
message += string.Format(
"** 未知服务版本: {0} <br />",
svc.RequestedServerVersion);
break;
}
}
else
{
message += string.Format("未知联系人类型: {0} - {1} <br />",
contact.GetType(), v.Subject);
}
}
Label1.Text += "<br />" + message;
本人第一技术贴啊!欢迎.NET爱好者指教,还有各位EWS高手!