c# – 通过Exchange Web服务(EWS)erreor SSL查询全局地址列表(GAL)

c# – 通过Exchange Web服务(EWS)erreor SSL查询全局地址列表(GAL),第1张

概述我的英语不好,但我会尽我所能. 我尝试通过EWS访问Exchange 2010,我想获取邮箱的联系人 阅读收件箱中的电子邮件非常有效 这是我的代码,并提前感谢您的回复 class Program{ static void Main(string[] args) { ServicePointManager.ServerCertificateValidation 我的英语不好,但我会尽我所能.
我尝试通过EWS访问Exchange 2010,我想获取邮箱的联系人
阅读收件箱中的电子邮件非常有效

这是我的代码,并提前感谢您的回复

class Program{       static voID Main(string[] args)    {        ServicePointManager.ServerCertificateValIDationCallback = delegate(Object obj,X509Certificate certificate,X509Chain chain,SslPolicyErrors errors)        {            // If the certificate is a valID,signed certificate,return true.            if (errors == System.Net.Security.SslPolicyErrors.None)            {                return true;            }            // If there are errors in the certificate chain,look at each error to determine the cause.            if ((errors & System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors) != 0)            {                if (chain != null && chain.ChainStatus != null)                {                    foreach (System.Security.Cryptography.X509Certificates.X509ChainStatus status in chain.ChainStatus)                    {                        if ((certificate.Subject == certificate.Issuer) &&                           (status.Status == System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.UntrustedRoot))                        {                            // Self-signed certificates with an untrusted root are valID.                            continue;                        }                        else                        {                            if (status.Status != System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.NoError)                            {                                // If there are any other errors in the certificate chain,the certificate is invalID,// so the method returns false.                                return false;                            }                        }                    }                }                // When processing reaches this line,the only errors in the certificate chain are                // untrusted root errors for self-signed certificates. These certificates are valID                // for default Exchange Server installations,so return true.                return true;            }            else            {                // In all other cases,return false.                return false;            }        };        ExchangeService _service = new ExchangeService(ExchangeVersion.Exchange2010);        _service.Credentials = new WebCredentials("user","password");        _service.Url = new Uri("https://mail.domain.be/ews/exchange.asmx");        //Mail dans mailBox        FindItemsResults<Item> findResults =  _service.FindItems(        WellKNownFoldername.InBox,new ItemVIEw(10));        foreach (Item item in findResults.Items)            Console.Writeline(item.Subject);        Console.Readline();         //CONtact mailBox        foreach (Contact contact in _service.FindItems(WellKNownFoldername.Contacts,new ItemVIEw(int.MaxValue)))        {            Console.Writeline(contact);        }}
解决方法 我的解决方案

static voID Main(string[] args){     ServicePointManager.ServerCertificateValIDationCallback = delegate(Object obj,SslPolicyErrors errors)    {        if (errors == System.Net.Security.SslPolicyErrors.None)        {            return true;        }        if ((errors & System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors) != 0)        {            if (chain != null && chain.ChainStatus != null)            {                foreach (System.Security.Cryptography.X509Certificates.X509ChainStatus status in chain.ChainStatus)                {                    if ((certificate.Subject == certificate.Issuer) &&                       (status.Status == System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.UntrustedRoot))                    {                        continue;                    }                    else                    {                        if (status.Status != System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.NoError)                        {                            return false;                        }                    }                }            }            return true;        }        else        {            return false;        }    };     ExchangeService _service = new ExchangeService(ExchangeVersion.Exchange2010);    _service.Credentials = new WebCredentials("user","password");    _service.Url = new Uri("https://mail.domain.com/ews/exchange.asmx");    //Contact mailBox    ContactsFolder contactsfolder = ContactsFolder.Bind(_service,WellKNownFoldername.Contacts);    int numItems = contactsfolder.TotalCount < int.MaxValue ? contactsfolder.TotalCount : int.MaxValue;    ItemVIEw vIEw = new ItemVIEw(numItems);    vIEw.PropertySet = new PropertySet(BasePropertySet.IDOnly,ContactSchema.displayname);    FindItemsResults<Item> contactItems = _service.FindItems(WellKNownFoldername.Contacts,vIEw);    foreach (Item item in contactItems)    {        if (item is Contact)        {            Contact contact = item as Contact;            Console.Writeline(contact.displayname);        }    }    Console.Readline();}
总结

以上是内存溢出为你收集整理的c# – 通过Exchange Web服务(EWS)erreor SSL查询全局地址列表(GAL)全部内容,希望文章能够帮你解决c# – 通过Exchange Web服务(EWS)erreor SSL查询全局地址列表(GAL)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1230236.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存