EWS C#,自动发现URL无法在Office365帐户上设置

时间:2018-02-27 13:48:57

标签: c# proxy office365 exchangewebservices

我已成功设法在非Office 365帐户上运行EWS服务, 但是,使用内部办公室365

public ExchangeService connectToExchange()
{
    var ews = new ExchangeService(ExchangeVersion.Exchange2010_SP1) 
    {Credentials = new WebCredentials(authenticate.ExchangeUsername, 
     authenticate.ExchangePassword) };
}
try
    {
      ews.AutodiscoverUrl(authenticate.ExchangeURL);
    }

网址未设置,当我对网址进行硬编码时,我们可以在Office365中从哪里获取此信息?当我硬编码以下内容时      网址:https://mail.domain.com/EWS/Exchange.asmx“);

我得到代理需要进行身份验证的错误,如何才能实现此目的?

感谢:

到目前为止,我已设法获得此功能,但仍然需要验证身份验证错误,我如何在此进行身份验证?

             public ExchangeService connectToExchange()
    {

        var ews = new ExchangeService(ExchangeVersion.Exchange2010_SP1) {Credentials = new WebCredentials(authenticate.ExchangeUsername, authenticate.ExchangePassword) };

        try
        {

            WebProxy myproxy = new WebProxy("proxyurl", port);
            myproxy.BypassProxyOnLocal = false;

            myproxy.Credentials = new NetworkCredential("user","pass");
            ews.WebProxy = myproxy;



            ews.Url = new Uri("exchangeurl");


        }
        catch
        {

        }

        return ews;
    }

几乎那里......代理现在正确,错误现在是:

“请求失败。基础连接已关闭:无法为SSL / TLS安全通道建立信任关系。”

1 个答案:

答案 0 :(得分:1)

您必须为应用程序创建证书验证回调方法。请参阅解释here

    using System.Security.Cryptography.X509Certificates;
    using System.Net.Security;

    // Validate the server certificate.
    ServicePointManager.ServerCertificateValidationCallback =
    delegate(object sender,
             X509Certificate certificate,
             X509Chain chain,
             SslPolicyErrors sslPolicyErrors)
    { return true; };