ExchangeServiceBinding:在进行实际调用之前如何测试连接

时间:2015-02-12 07:35:32

标签: exchangewebservices

我正在使用ExchangeServiceBinding来创建/更新/删除约会。而且效果很好。

在调用esb.CreateItem / esb.UpdateItem / esb.DeleteItem之前,有没有办法检查我使用的凭据是否有效

基本上我想在调用任何这些方法之前验证凭据!!

任何帮助将不胜感激......谢谢

2 个答案:

答案 0 :(得分:0)

除了进行某种EWS通话外,我不相信这是一种验证方式。当然,这取决于你通过验证的意思。 :)

答案 1 :(得分:0)

确认凭据有效的唯一方法是尝试使用EWS连接到邮箱。

在下面的代码段中,它会尝试绑定到收件箱文件夹。如果凭据有效,则呼叫将成功。如果凭据无效,则会抛出异常。

try
{
    exchangeService.Credentials = new WebCredentials(userName, password, domain);
    exchangeService.Url = new Uri(url);

    Folder.Bind(exchangeService, WellKnownFolderName.Inbox);

    //if no exception thrown then Bind operation was successful and credentials are valid
} 
catch (Exception e)
{
    //exception thrown -  most likely related to invalid credentials
}