【问题标题】:C# EWS in Exchange AutodiscoverUrl Exception while using Version 2010 or latest使用版本 2010 或最新版本时 Exchange AutodiscoverUrl 中的 C# EWS 异常
【发布时间】:2021-02-19 08:40:42
【问题描述】:

a 与 ExchangeVersion.Exchange2007_SP1 成功连接,当我在 2010 年或最近更改它时,我在这一行得到了异常:

service.AutodiscoverUrl(MailboxToAccess, RedirectionUrlValidationCallback); ->System.NullReferenceException:“对象引用未设置为对象的实例。” 我试过包: Exchange.WebServices.Managed.Api v2.2.1.2 和 Microsoft.Exchange.WebServices v2.2.0

static void Main(string[] args)
        {
            String MailboxToAccess = "username@domain";
            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
            SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false);

            service.Credentials = new WebCredential("username@domain", "password");
            service.AutodiscoverUrl(MailboxToAccess, RedirectionUrlValidationCallback);

            SetStreamingNotifications(service);
        }
 private static bool RedirectionUrlValidationCallback(string redirectionUrl)
        {
            bool result = false;

            Uri redirectionUri = new Uri(redirectionUrl);
            if (redirectionUri.Scheme == "https")
            {
                result = true;
            }
            return result;
        }

【问题讨论】:

    标签: exchange-server exchangewebservices exchange-server-2010


    【解决方案1】:

    我使用手动设置 Exchange 服务 URL

    / Create the binding.
    ExchangeService service = new ExchangeService();
    // Set the credentials for the on-premises server.
    service.Credentials = new WebCredentials("user1@contoso.com", "password");
    // Set the URL.
    service.Url = new Uri("https://computername.domain.contoso.com/EWS/Exchange.asmx");
    

    我仍然不明白为什么它对我不起作用

    service.AutodiscoverUrl("User1@contoso.com");
    

    【讨论】:

      猜你喜欢
      • 2013-09-28
      • 1970-01-01
      • 1970-01-01
      • 2013-12-07
      • 2022-07-24
      • 1970-01-01
      • 2015-05-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多