Exchange Web服务身份验证问题401

时间:2019-11-14 10:37:30

标签: c# exchangewebservices exchange-server-2010

我尝试连接到Exchange Web服务以获取连接用户的约会。

我一直在寻找解决方案,但是我相信问题不在于代码,而在于Exchange的配置。

在Exchange中是否有要向Exchange Web Service授予所需权限的配置?

这是我的代码:

    private ExchangeService Service
    {
        get
        {

            //this code doesn't change the result. I tried without this code too.
            ServicePointManager
.ServerCertificateValidationCallback +=
(sender, cert, chain, sslPolicyErrors) => true;


            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
            service.Credentials = new WebCredentials("myemailaddress@ourdomain.com", "the correct password");

            //I tried this code too 
            //service.Credentials = new WebCredentials("username", "the correct password", "domain");

            service.Url = new Uri("https://mailhost.capronpodologie.com/EWS/Exhcange.asmx");


            var info = service.ServerInfo;
            return service;
        }
    }



    private CalendarFolder FindNamedCalendarFolder(string name)
    {
        FolderView view = new FolderView(100);
        view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
        view.PropertySet.Add(FolderSchema.DisplayName);
        view.Traversal = FolderTraversal.Deep;

        SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(FolderSchema.FolderClass, "IPF.Appointment");

        //Here, i have the error, 401 not authorised.
        FindFoldersResults findFolderResults = Service.FindFolders(WellKnownFolderName.Root, sfSearchFilter, view);
        return findFolderResults.Where(f => f.DisplayName == name).Cast<CalendarFolder>().FirstOrDefault();
    }

总是相同的结果,未授权401。

我从以下地址尝试了Microsoft Exchange连接测试:

https://testconnectivity.microsoft.com enter image description here

测试通过: enter image description here 任何想法 ?

0 个答案:

没有答案