.net - 发送soap请求时刷新XmlSerializer缓冲区时出错(存档条目是使用不受支持的压缩方法压缩的。)
问题描述
尝试从 .NET Core 3.1 向无处不在的点对点支付平台发送请求时出现错误。该代码对于自动生成的 SOAP 来说是相当标准的,但这里是我试图序列化的自动生成模型:
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.2")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="<redacted>")]
public partial class EbMtvnSvcReq
{
private MtvnSvcVerType mtvnSvcVerField;
private string msgUUIDField;
private PrcsParmsType prcsParmsField;
private ServiceRequestType[] svcField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=0)]
public MtvnSvcVerType MtvnSvcVer
{
get
{
return this.mtvnSvcVerField;
}
set
{
this.mtvnSvcVerField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=1)]
public string MsgUUID
{
get
{
return this.msgUUIDField;
}
set
{
this.msgUUIDField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=2)]
public PrcsParmsType PrcsParms
{
get
{
return this.prcsParmsField;
}
set
{
this.prcsParmsField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Svc", Order=3)]
public ServiceRequestType[] Svc
{
get
{
return this.svcField;
}
set
{
this.svcField = value;
}
}
}
抛出异常:
System.Exception : The archive entry was compressed using an unsupported compression method. at System.IO.Compression.Inflater.Inflate(FlushCode flushCode) at System.IO.Compression.Inflater.Inflate(FlushCode flushCode) in /_/src/System.IO.Compression/src/System/IO/Compression/DeflateZLib/Inflater.cs:line 300
at System.IO.Compression.Inflater.ReadInflateOutput(Byte* bufPtr, Int32 length, FlushCode flushCode, Int32& bytesRead) in /_/src/System.IO.Compression/src/System/IO/Compression/DeflateZLib/Inflater.cs:line 266
at System.IO.Compression.Inflater.ReadOutput(Byte* bufPtr, Int32 length, Int32& bytesRead) in /_/src/System.IO.Compression/src/System/IO/Compression/DeflateZLib/Inflater.cs:line 122
at System.IO.Compression.Inflater.InflateVerified(Byte* bufPtr, Int32 length) in /_/src/System.IO.Compression/src/System/IO/Compression/DeflateZLib/Inflater.cs:line 92
at System.IO.Compression.DeflateStream.<FinishReadAsyncMemory>d__54.MoveNext() in /_/src/System.IO.Compression/src/System/IO/Compression/DeflateZLib/DeflateStream.cs:line 506
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in /_/src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs:line 63
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 180
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 151
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 369
at System.ServiceModel.Channels.HttpResponseMessageHelper.<GetStreamAsync>d__17.MoveNext() in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/HttpResponseMessageHelper.cs:line 316
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in /_/src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs:line 63
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 180
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 151
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 369
at System.ServiceModel.Channels.HttpResponseMessageHelper.<ReadChunkedBufferedMessageAsync>d__12.MoveNext() in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/HttpResponseMessageHelper.cs:line 190
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in /_/src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs:line 63
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 180
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 151
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 369
at System.ServiceModel.Channels.HttpResponseMessageHelper.<ParseIncomingResponse>d__7.MoveNext() in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/HttpResponseMessageHelper.cs:line 58
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in /_/src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs:line 63
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 180
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 151
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 369
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpClientRequestChannel.HttpClientChannelAsyncRequest.<ReceiveReplyAsync>d__17.MoveNext() in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/HttpChannelFactory.cs:line 1098
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in /_/src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs:line 63
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 180
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 151
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 369
at System.ServiceModel.Channels.RequestChannel.<RequestAsync>d__33.MoveNext() in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/RequestChannel.cs:line 280
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in /_/src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs:line 63
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 180
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 151
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 369
at System.ServiceModel.Channels.RequestChannel.<RequestAsyncInternal>d__32.MoveNext() in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/RequestChannel.cs:line 239
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in /_/src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs:line 63
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 180
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 151
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 369
at System.Runtime.TaskHelpers.WaitForCompletionNoSpin[TResult](Task`1 task) in /_/src/System.Private.ServiceModel/src/Internals/System/Runtime/TaskHelpers.cs:line 282
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/RequestChannel.cs:line 228
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Dispatcher/RequestChannelBinder.cs:line 107
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/ServiceChannel.cs:line 758
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/ServiceChannel.cs:line 715
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(MethodCall methodCall, ProxyOperationRuntime operation) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/ServiceChannelProxy.cs:line 372
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(MethodInfo targetMethod, Object[] args) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/ServiceChannelProxy.cs:line 144
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in /_/src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs:line 63
at System.Reflection.DispatchProxyGenerator.Invoke(Object[] args) in /_/src/System.Reflection.DispatchProxy/src/System/Reflection/DispatchProxyGenerator.cs:line 162
at generatedProxy_1.SendMessage(SendMessageRequest )
at <my code>
我遵循了内部代码,尝试刷新缓冲区似乎失败了。
有没有人对此有任何见解?
解决方案
我通过在 GetBindingForEndpoint 方法中将缓冲区值设置为较低的值(比 int.Max)解决了这个问题:
System.ServiceModel.BasicHttpsBinding result = new System.ServiceModel.BasicHttpsBinding();
result.MaxBufferSize = 1024000;
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
result.MaxReceivedMessageSize = 1024000;
result.MaxBufferPoolSize = 524288;
...
result.TextEncoding = System.Text.Encoding.BigEndianUnicode;
result.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
return result;