在 ExchangeService 中,我收到此错误通常只允许每个套接字地址 (protocol/network address/port) 使用一次 XX.XXX.XXX.XXX:443

In ExchangeService I Got This Error Only one usage of each socket address (protocol/network address/port) is normally permitted XX.XXX.XXX.XXX:443

我们正在使用 Microsoft.Exchange.WebServices 我们有 30 多个用户。一些用户得到这个

Only one usage of each socket address (protocol/network address/port) is normally permitted XX.XXX.XXX.XXX:443

错误。当他们试图删除邮件时。我的代码在下面,我不明白哪里出了问题,如果你知道请帮忙。

ExchangeService esb = new msExchange.ExchangeService(msExchange.ExchangeVersion.Exchange2007_SP1);
esb.Credentials = new NetworkCredential(username, password);
esb.Url = new Uri("URL");
int i = 0;
foreach (var item in emailId)
{
    itemIds[i] = new msExchange.ItemId(item.MsgId);
    i++;
}
ServiceResponseCollection<msExchange.ServiceResponse> deleteResponse = esb.DeleteItems(itemIds, msExchange.DeleteMode.HardDelete, msExchange.SendCancellationsMode.SendToNone, msExchange.AffectedTaskOccurrence.AllOccurrences);

Microsoft.Exchange.WebServices.Data.ServiceRequestException: The request failed. Unable to connect to the remote server ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted xx.xxx.xxx.xxx:443 at System.Net.Sockets.Socket.InternalEndConnect(IAsyncResult asyncResult) at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.GetResponse() at Microsoft.Exchange.WebServices.Data.EwsHttpWebRequest.Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest.GetResponse() at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request) --- End of inner exception stack trace --- at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request) at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest& request) at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.InternalExecute() at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest1.Execute() at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalDeleteItems(IEnumerable1 itemIds, DeleteMode deleteMode, Nullable1 sendCancellationsMode, Nullable1 affectedTaskOccurrences, ServiceErrorHandling errorHandling, Boolean suppressReadReceipts) at Microsoft.Exchange.WebServices.Data.ExchangeService.DeleteItems(IEnumerable1 itemIds, DeleteMode deleteMode, Nullable1 sendCancellationsMode, Nullable1 affectedTaskOccurrences, Boolean suppressReadReceipt) at Microsoft.Exchange.WebServices.Data.ExchangeService.DeleteItems(IEnumerable1 itemIds, DeleteMode deleteMode, Nullable1 sendCancellationsMode, Nullable1 affectedTaskOccurrences)

根据我的搜索,这个错误可能是地址已经在使用中。

通常,每个套接字地址 (protocol/IP address/port) 只允许使用一次。如果应用程序尝试将套接字绑定到已用于现有套接字的 IP address/port,或未正确关闭的套接字,或仍在关闭过程中的套接字,则会发生此错误。对于需要将多个套接字绑定到同一端口号的服务器应用程序,请考虑使用 setsockopt (SO_REUSEADDR)。客户端应用程序通常根本不需要调用 bind — connect 会自动选择一个未使用的端口。当使用通配符地址(涉及 ADDR_ANY)调用绑定时,WSAEADDRINUSE 错误可能会延迟到特定地址被提交。这可能会在稍后调用另一个函数时发生,包括 connect、listen、WSAConnect 或 WSAJoinLeaf。

更多信息,请参考这个link: