我有一个类结构作为具有许多属性的WCF请求。其中一个属性是byte [],它包含要上载到服务器的文件。根据上传的文件,它可能非常大,有时大到1.5 GB。 我的WCF调用工作正常,而byte []保持在约。 250 MB。但是,如果上传的文件大于250 MB,我会在启动呼叫后1秒(!)收到以下异常:
System.ServiceModel.CommunicationObjectFaultedException: The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.
Server stack trace:
at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
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 System.ServiceModel.ICommunicationObject.Close(TimeSpan timeout)
at System.ServiceModel.ClientBase`1.System.ServiceModel.ICommunicationObject.Close(TimeSpan timeout)
at System.ServiceModel.ClientBase`1.Close()
at System.ServiceModel.ClientBase`1.System.IDisposable.Dispose()
我使用NetTcpBinding
,但现象仍然是BasicHttpBinding
和WSHttpBinding
。我在绑定上将所有与消息大小相关的参数设置为int32.MaxValue
。
我想使用流媒体进行上传,但之后我只能在通话中使用一个Stream
参数,这样做无效。
什么可能导致这种行为?我在考虑超时问题,但没有明确设置超时,并且没有超时默认为1秒(最短默认值为1分钟)。
更新 配置是通过代码进行的,而不是app.config。以下是客户端和服务器的设置:
var binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.None;
binding.Security.Message.ClientCredentialType = MessageCredentialType.None;
binding.Security.Transport.ProtectionLevel = ProtectionLevel.None;
binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
binding.MaxBufferPoolSize = Int32.MaxValue;
binding.MaxBufferSize = Int32.MaxValue;
binding.MaxConnections = 1000;
binding.MaxReceivedMessageSize = Int32.MaxValue;
binding.ListenBacklog = 128;
binding.PortSharingEnabled = false;
binding.TransactionFlow = false;
binding.ReaderQuotas.MaxBytesPerRead = Int32.MaxValue;
binding.ReaderQuotas.MaxArrayLength = Int32.MaxValue;
binding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;