У нас есть служба WEPAPI, которая записывает данные в сжатом виде на клиент с помощью обработчика сообщений. Так как мы иногда получаем очень большие сообщения, система настроена с использованием
HttpSelfHostConfiguration.TransferMode = TransferMode.Streamed;
Логика сжатия:
public class CompressedHttpContent : CompressionHttpContent
{
public CompressedHttpContent(HttpContent content, ICompressor compressor)
: base(content, compressor)
{
}
protected async override Task SerializeToStreamAsync(System.IO.Stream stream, System.Net.TransportContext context)
{
try
{
if (this.OriginalContent != null)
using (OriginalContent)
{
using (var contentStream = await OriginalContent.ReadAsStreamAsync())
{
var compressedStream = Compressor.CreateCompressionStream(stream);
await contentStream.CopyToAsync(compressedStream);
compressedStream.Close();
compressedStream.Dispose();
}
}
}
catch (Exception e)
{
...
throw;
}
}
}
И иногда мы получаем исключение, например:
System.InvalidOperationException: The AsyncEventArgs implementation 'System.ServiceModel.Channels.BufferedOutputAsyncStream+WriteAsyncState' tried to set the state to Pending multiple times without completing a pending operation. This could be caused by an incorrect application AsyncEventArgs implementation or other extensibility code that invokes Set() multiple times.
Server stack trace:
at System.Runtime.AsyncEventArgs.set_State(OperationState value)
at System.Runtime.AsyncEventArgs.SetAsyncState(AsyncEventArgsCallback callback, Object state)
at System.Runtime.AsyncEventArgs`1.Set(AsyncEventArgsCallback callback, TArgument arguments, Object state)
at System.ServiceModel.Channels.BufferedOutputAsyncStream.BeginWrite(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state)
at System.IO.Compression.DeflateStream.WriteDeflaterOutput(Boolean isAsync)
at System.IO.Compression.DeflateStream.InternalWrite(Byte[] array, Int32 offset, Int32 count, Boolean isAsync)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)
Exception rethrown at [0]:
at System.IO.Compression.DeflateStream.EndWrite(IAsyncResult asyncResult)
at System.IO.Compression.GZipStream.EndWrite(IAsyncResult asyncResult)
at System.IO.Stream.<>c.<BeginEndWriteAsync>b__53_1(Stream stream, IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory`1.FromAsyncTrimPromise`1.Complete(TInstance thisRef, Func`3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.IO.Stream.<CopyToAsyncInternal>d__27.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at CompressedHttpContent.<SerializeToStreamAsync>d__2.MoveNext()
К сожалению, когда я ищу эту ошибку, я не получаю никаких хитов.
Мы не получили этого, когда использовали буферный режим передачи. Мы потенциально можем перейти в режим StreamedRequest, так как только входящие запросы могут быть очень большими.
Кто-нибудь видел это или есть мысли?
Спасибо.