当我的应用程序托管在IIS上时,Microsoft Exchange Web服务(EWS)无法正常工作

时间:2015-08-05 07:03:48

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

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开发服务器上运行它时,它工作正常。
如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

尝试在自动发现中添加此代码;它在我在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;
    }

答案 1 :(得分:0)

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