Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过Exchange Web服务(EWS)错误或SSL查询全局地址列表(GAL)_C#_Contacts_Exchangewebservices - Fatal编程技术网

C# 通过Exchange Web服务(EWS)错误或SSL查询全局地址列表(GAL)

C# 通过Exchange Web服务(EWS)错误或SSL查询全局地址列表(GAL),c#,contacts,exchangewebservices,C#,Contacts,Exchangewebservices,我的英语不好,但我会尽力的。 我试图通过EWS访问Exchange 2010,我想获取邮箱的联系人 在收件箱中阅读电子邮件非常有效 这是我的代码,提前感谢您的回复 class Program { static void Main(string[] args) { ServicePointManager.ServerCertificateValidationCallback = delegate(Object obj, X509Certificate cert

我的英语不好,但我会尽力的。 我试图通过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);
        }
}
类程序
{   
静态void Main(字符串[]参数)
{
ServicePointManager.ServerCertificateValidationCallback=委托(对象obj、X509证书证书、X509链、SslPolicyErrors)
{
//如果证书是有效的签名证书,则返回true。
if(errors==System.Net.Security.SslPolicyErrors.None)
{
返回true;
}
//如果证书链中存在错误,请查看每个错误以确定原因。
if((errors&System.Net.Security.SslPolicyErrors.remoteCertificateChaineErrors)!=0)
{
if(chain!=null&&chain.ChainStatus!=null)
{
foreach(System.Security.Cryptography.X509Certificates.X509ChainStatus在chain.ChainStatus中的状态)
{
if((certificate.Subject==certificate.Issuer)&&
(status.status==System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.untrustroot))
{
//具有不受信任根的自签名证书有效。
继续;
}
其他的
{
if(status.status!=System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.NoError)
{
//如果证书链中存在任何其他错误,则证书无效,
//因此,该方法返回false。
返回false;
}
}
}
}
//当处理到达此行时,证书链中唯一的错误是
//自签名证书的不受信任根错误。这些证书有效
//对于默认的Exchange Server安装,请返回true。
返回true;
}
其他的
{
//在所有其他情况下,返回false。
返回false;
}
};
ExchangeService\u服务=新的ExchangeService(ExchangeVersion.Exchange2010);
_service.Credentials=新的WebCredentials(“用户”、“密码”);
_service.Url=新的Uri(“https://mail.domain.be/ews/exchange.asmx");
//邮筒
FindItemsResults findResults=\u service.FindItems(
WellKnownFolderName.Inbox,新项目视图(10));
foreach(findResults.Items中的项目)
Console.WriteLine(项目主题);
Console.ReadLine();
//联系邮箱
foreach(在_service.FindItems(WellKnownFolderName.Contacts,new ItemView(int.MaxValue))中的联系人)
{
控制台。写线(联系人);
}
}
我的解决方案:

static void Main(string[] args)
{ 
    ServicePointManager.ServerCertificateValidationCallback = delegate(Object obj, X509Certificate certificate, X509Chain chain, 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();
}
static void Main(字符串[]args)
{ 
ServicePointManager.ServerCertificateValidationCallback=委托(对象obj、X509证书证书、X509链、SslPolicyErrors)
{
if(errors==System.Net.Security.SslPolicyErrors.None)
{
返回true;
}
if((errors&System.Net.Security.SslPolicyErrors.remoteCertificateChaineErrors)!=0)
{
if(chain!=null&&chain.ChainStatus!=null)
{
foreach(System.Security.Cryptography.X509Certificates.X509ChainStatus在chain.ChainStatus中的状态)
{
if((certificate.Subject==certificate.Issuer)&&
(status.status==System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.untrustroot))
{
继续;
}
其他的
{
if(status.status!=System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.NoError)
{
返回false;
}
}
}
}
返回true;
}
其他的
{
返回false;
}
}; 
ExchangeService\u服务=新的ExchangeService(ExchangeVersion.Exchange2010);
_service.Credentials=新的WebCredentials(“用户”、“密码”);
_service.Url=新的Uri(“https://mail.domain.com/ews/exchange.asmx");
//联系邮箱
ContactsFolder ContactsFolder=ContactsFolder.Bind(_服务,Wellknown文件夹名称.Contacts);
int numItems=contactsfolder.TotalCount
不清楚您在问什么。您遇到了哪些错误?