Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

[Exchange-Online] [EWSMA] [C#] [Windows]: EWS - CreateAttachment problem - The underlying connection was closed: An unexpected error occurred on a send

$
0
0

Hello,

 

I have a problem with ExchangeServiceBinding.CreateAttachment(...) method (EWS with Office 365)

  • When I try to add a small attachment (e.g. 5 MB), then the method works fine.
  • When I try to add a big attachment (e.g.12 MB), then the following exception is thrown:

 System.Net.WebException
The underlying connection was closed: An unexpected error occurred on a send.
   at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
   at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at C2EWS.Proxy.ExchangeServiceBinding.CreateAttachment(CreateAttachmentType CreateAttachment1) in d:\source\EWSProxyClasses.cs:line 1471
   at EWSRequest.Program.UploadAttachment(ExchangeServiceBinding esb, ItemIdType parentItemIdType) in d:\source\EWSRequest\Program.cs:line 90
   at EWSRequest.Program.Main(String[] args) in d:\source\EWSRequest\Program.cs:line 59

 

Inner exception:

 System.IO.IOException
 Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.
    at System.Net.Sockets.NetworkStream.MultipleWrite(BufferOffsetSize[] buffers)
    at System.Net.Security._SslStream.StartWriting(SplitWritesState splitWrite, SplitWriteAsyncProtocolRequest asyncRequest)
    at System.Net.Security._SslStream.ProcessWrite(BufferOffsetSize[] buffers, SplitWriteAsyncProtocolRequest asyncRequest)
    at System.Net.TlsStream.MultipleWrite(BufferOffsetSize[] buffers)
    at System.Net.Connection.Write(ScatterGatherBuffers writeBuffer)
    at System.Net.ConnectStream.ResubmitWrite(ConnectStream oldStream, Boolean suppressWrite)

 

Inner exception:
  System.Net.Sockets.SocketException
  An existing connection was forcibly closed by the remote host
     at System.Net.Sockets.Socket.MultipleSend(BufferOffsetSize[] buffers, SocketFlags socketFlags)
     at System.Net.Sockets.NetworkStream.MultipleWrite(BufferOffsetSize[] buffers)

 

The C# code is the following:

private void UploadAttachment(ExchangeServiceBinding esb, ItemIdType parentItemIdType, string attachmentPath)
{
    // File Attachment
    FileAttachmentType fileAttach = new FileAttachmentType();

    // Attachment details
    byte[] bytes = System.IO.File.ReadAllBytes(attachmentPath);
    fileAttach.Content = bytes;
    fileAttach.IsInlineSpecified = false;
    fileAttach.LastModifiedTimeSpecified = false;
    fileAttach.Name = System.IO.Path.GetFileName(attachmentPath);

    // Create Attachment
    CreateAttachmentType reqCreateAttach = new CreateAttachmentType();

    // Add parent Id
    reqCreateAttach.ParentItemId = parentItemIdType;

    // Add attachment to the query
    reqCreateAttach.Attachments = new AttachmentType[1];
    reqCreateAttach.Attachments[0] = fileAttach;

    // Upload attachment
    CreateAttachmentResponseType resp = esb.CreateAttachment(reqCreateAttach);

    // Check response errors
    CheckErrors(resp);
}


Could you advise a solution, please?

 

Robert


Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>