C# soap 客户端 System.OverflowException: 算术运算导致溢出



928mb 文件工作正常,但是当我尝试将 1.08GB 发送到 SOAP 服务(mtom 分块传输,_service引用.cs是从 wsdl 生成的(时会发生此溢出错误。在提琴手跟踪中,我只看到请求的标头,但没有请求正文,也没有响应

相关代码:

var httpsTransportBindingElement = new HttpsTransportBindingElement
{
    MaxReceivedMessageSize = int.MaxValue,
    TransferMode = TransferMode.Streamed //Chunked transfer
};
var binding = new CustomBinding();
var mtomEncoding = new MtomMessageEncodingBindingElement(MessageVersion.Soap12, Encoding.UTF8);
mtomEncoding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
binding.Elements.Add(mtomEncoding);
binding.Elements.Add(httpsTransportBindingElement);
binding.SendTimeout = TimeSpan.FromHours(1);
binding.ReceiveTimeout = TimeSpan.FromMinutes(5);
_service = new FileuploadSoapPortTypeClient(binding, new EndpointAddress(configuration.HttpUploadUrl));
_service.PostFile(request);

错误堆栈跟踪如下:

System.OverflowException: Arithmetic operation resulted in an overflow. 
Server stack trace: 
at System.IO.BufferedStream.Write(Byte[] array, Int32 offset, Int32 count) 
at System.Xml.XmlMtomWriter.WriteXOPBinaryParts() 
at System.ServiceModel.Channels.Message.WriteMessagePostamble(XmlDictionaryWriter writer) 
at System.ServiceModel.Channels.MtomMessageEncoder.WriteMessage(Message message, Stream stream, String startInfo, String boundary, String startUri, Boolean writeMessageHeaders) 
at System.ServiceModel.Channels.HttpOutput.WriteStreamedMessage(TimeSpan timeout) 
at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout) 
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout) 
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) 
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) 
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) 
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) 
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) 
Exception rethrown at [0]: 
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) 
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 
at MyServiceClient.FileuploadSoapPortType.PostFile(UploadRequest request) 
at MyServiceClient.FileuploadSoapPortType.PostFile(UploadRequest request) in C:MyServiceClientReference.cs:line 8473 

我无法比 PostFile(( 调用更进一步地调试它,所以我的问题是 - 错误发生在哪里,在服务器或我的客户端上? 当然如何修复它?谢谢!

从堆栈跟踪中,它告诉您它是服务器端:

Server stack trace:

该错误是由以下位置发生的情况引起的:

at MyServiceClient.FileuploadSoapPortType.PostFile(UploadRequest request) in C:MyServiceClientReference.cs:line 8473 

访问该文件并查看该行上发生的情况。我想想想 Web 服务托管在哪里,他们都有发生类似事情时的日志。

要找出我建议的原因:

  • 给出它发生的时间(如果他们有日志,则更容易找到堆栈跟踪(
  • 发生
  • 错误时尝试执行的操作的详细说明。

最新更新