【问题标题】:Microsoft exchange web service (EWS) not working when my application is hosted on IIS当我的应用程序托管在 IIS 上时,Microsoft Exchange Web 服务 (EWS) 无法正常工作
【发布时间】:2015-08-05 07:03:47
【问题描述】:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1)
{
    Credentials = new WebCredentials("usrname", "pass#1234")
};

//to add logic for itemview
service.AutodiscoverUrl("emailaddress@test.com");

当我在托管在 iis 上的应用程序中运行上述代码时,它会抛出错误“找不到自动发现服务”。

但是当我在 Visual Studio 开发服务器上运行相同的程序时,它工作正常。
如何解决这个问题?

【问题讨论】:

  • IIS 服务器是否与 Exchange Server 在同一个域中?
  • 如果您的凭据错误,您将得到同样的错误。
  • 我正在使用我的 Outlook 凭据,而 iis 服务器仅托管在我的桌面上。

标签: c# asp.net iis exchange-server exchangewebservices


【解决方案1】:

尝试将此代码添加到您的自动发现中;它在我托管在 IIS 中的应用程序中完美运行。

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1)
{
    Credentials = new WebCredentials("usrname", "pass#1234")
};

//to add logic for itemview
service.AutodiscoverUrl("emailaddress@test.com", RedirectionUrlValidationCallback);

private static bool RedirectionUrlValidationCallback(string redirectionUrl)
    {
        // The default for the validation callback is to reject the URL.
        var result = false;

        var redirectionUri = new Uri(redirectionUrl);

        // Validate the contents of the redirection URL. In this simple validation
        // callback, the redirection URL is considered valid if it is using HTTPS
        // to encrypt the authentication credentials. 
        if (redirectionUri.Scheme == "https")
        {
            result = true;
        }
        return result;
    }

【讨论】:

  • 当我使用 VS 开发服务器运行代码时,它运行良好,但在我的系统上托管 IIS 时,它无法正常工作。上面的链接没有解决。
【解决方案2】:

出现该错误的原因有很多。您需要 enable tracing 打开所有与自动发现相关的跟踪标记,然后查看发生的情况以查找原因。它可能是 DNS、凭据、防火墙等。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 2022-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多