如何验证传递给 NetworkCredential 构造函数以用于 EWS 的凭据?

How can i validate credentials passed to the NetworkCredential constructor for use with EWS?

有没有一种方法可以验证传递给 System.Net.NetworkCredential class 的凭据?我想确保对 Exchange Web 服务的调用有效,以便调用可以正常工作。

示例代码如下:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
 service.Credentials = new NetworkCredential(user_id, password);

//how to validate credentials here? 

service.Url = new System.Uri("some_url");
Microsoft.Exchange.WebServices.Data.Appointment meeting1 = new Microsoft.Exchange.WebServices.Data.Appointment(service);

 //add some extra stuff to the meeting object

  ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;

 Microsoft.Exchange.WebServices.Data.Mailbox test = new Microsoft.Exchange.WebServices.Data.Mailbox(email);

 Microsoft.Exchange.WebServices.Data.FolderId folderid = new Microsoft.Exchange.WebServices.Data.FolderId(WellKnownFolderName.Calendar, test);

 meeting1.Save(folderid,SendInvitationsMode.SendToAllAndSaveCopy);

此外,有没有办法检查 .Save() 是否真的有效?该函数没有 return 值。

Is there a way that you can validate credentials passed to System.Net.NetworkCredential class?

这些是 Active Directory 凭据,因此如果您想验证它们,您可以查看类似 Validate a username and password against Active Directory? 的内容。EWS 不提供任何凭据验证方法,如果它们不正确则返回 401 .

Also, is there a way to check if the .Save() actually worked? the function has no return value

如果从服务器收到无效响应,则会引发异常,因此在这种情况下,您至少应该在保存周围有一个 try/catch(异常可以基于请求或响应)。对于 Meetings,如果在您的示例中创建成功,meeting1 对象现在将在其 Id 属性.

中具有一个基础 Id