c# - 在 C# 中处理/关闭 ExchangeService?

标签 c# dispose exchangewebservices exchange-server-2007

我正在使用 ExchangeService WebService API (Microsoft.Exchange.WebServices.Data),但找不到任何CloseDispose 方法.

是否不需要以某种方式关闭连接?

我的方法是这样的:

public void CheckMails()
{
    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
    IMAPCredentials creds = new IMAPCredentials();
    service.Credentials = new NetworkCredential(creds.User, creds.Pass, creds.Domain);
    service.AutodiscoverUrl(creds.User + "@example.com");

    // not the real code from here on but you'll get the idea...
    // var emails = service.FindItems();
    // emails[0].Load();
    // emails[0].Attachments[0].Load();
    // ...
}

最佳答案

ExchangeService 类没有 Close/Dispose 方法,因为该类不维护与 Web 服务的连接。而是根据需要创建和关闭新的 HTTP 连接。

例如,当您调用 ExchangeService.FindItems 时,会在对 FindItems 的方法调用中创建并关闭与 Exchange 服务器的新 HTTP 连接。

关于c# - 在 C# 中处理/关闭 ExchangeService?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9209903/

相关文章:

c# - 替代 ObservableCollection?

c# - 不可调用成员 'System.Windows.Forms.Control.Text' 不能像方法一样使用。在 C# 中

datatable - 我应该 Dispose() DataSet 和 DataTable 吗?

c# - Exchange 2013 API - 获取房间属性

c# - 从头开始创建有效的 ConversationReference 以发送主动消息

c# - ToList() 方法在哪里? (可查询)

c# - 数据表内部使用?

c# - Autofac:如何在不绕过 IoC 容器的情况下限制 IDisposable 对象的生命周期

c# - 如何在一封邮件中添加多个电子邮件收件人,但仅将邮件发送到选定的几个地址?

c# - 使用 EWS 阅读电子邮件时处理非法 XML 值