C# 接收字节数组超过350 MB时WCF客户端失败

C# 接收字节数组超过350 MB时WCF客户端失败,c#,wcf,C#,Wcf,当我收到超过350 MB的字节数组时,我收到错误,因为“服务器没有提供有意义的回复;这可能是由于契约不匹配、会话过早关闭或内部服务器错误造成的。” 客户端配置 var binding = new NetTcpBinding(SecurityMode.None) { PortSharingEnabled = true, MaxBufferSize = Int32.MaxValue, MaxReceivedM

当我收到超过350 MB的字节数组时,我收到错误,因为“服务器没有提供有意义的回复;这可能是由于契约不匹配、会话过早关闭或内部服务器错误造成的。”

客户端配置

  var binding = new NetTcpBinding(SecurityMode.None)
        {
            PortSharingEnabled = true,
            MaxBufferSize = Int32.MaxValue,
            MaxReceivedMessageSize = Int32.MaxValue,
            ReaderQuotas = new XmlDictionaryReaderQuotas
            {
                MaxArrayLength = Int32.MaxValue,
                MaxBytesPerRead = Int32.MaxValue,
                MaxDepth = Int32.MaxValue,
                MaxNameTableCharCount = Int32.MaxValue,
                MaxStringContentLength = Int32.MaxValue,
            },

            MaxBufferPoolSize = 0,
            TransactionFlow = false,
            TransactionProtocol = TransactionProtocol.Default,
            TransferMode = TransferMode.Streamed,
            OpenTimeout = new TimeSpan(0, 10, 0),
            CloseTimeout = new TimeSpan(0, 10, 0),
            SendTimeout = new TimeSpan(0, 10, 0),
            ReceiveTimeout = new TimeSpan(0, 10, 0)
        }; 

container.Register(Component.For<IFtpsServiceFacade>()
            .AsWcfClient(
                new DefaultClientModel(
                    WcfEndpoint.BoundTo(binding)
                       .At(string.Format("net.tcp://{0}/FileService.Ftps",
                            "localhost")))
            )); 
var binding=new nettcppbinding(SecurityMode.None)
{
PortSharingEnabled=true,
MaxBufferSize=Int32.MaxValue,
MaxReceivedMessageSize=Int32.MaxValue,
ReaderQuotas=新的XmlDictionaryReaderQuotas
{
MaxArrayLength=Int32.MaxValue,
MaxBytesPerRead=Int32.MaxValue,
MaxDepth=Int32.MaxValue,
MaxNameTableCharCount=Int32.MaxValue,
MaxStringContentLength=Int32.MaxValue,
},
MaxBufferPoolSize=0,
TransactionFlow=false,
TransactionProtocol=TransactionProtocol.Default,
TransferMode=TransferMode.Streamed,
OpenTimeout=新的时间跨度(0,10,0),
CloseTimeout=新的时间跨度(0,10,0),
SendTimeout=新的时间跨度(0,10,0),
ReceiveTimeout=新的时间跨度(0,10,0)
}; 
container.Register(Component.For())
.AsWcfClient(
新的DefaultClientModel(
WcfEndpoint.BoundTo(绑定)
.At(string.Format(“net.tcp://{0}/FileService.Ftps”,
“本地主机”))
)); 
服务器端配置

var binding = new NetTcpBinding
        {
            PortSharingEnabled = true,
            MaxBufferSize = Int32.MaxValue,
            MaxReceivedMessageSize = Int32.MaxValue,
            ReaderQuotas = new XmlDictionaryReaderQuotas
            {
                MaxArrayLength = Int32.MaxValue,
                MaxBytesPerRead = Int32.MaxValue,
                MaxDepth = Int32.MaxValue,
                MaxNameTableCharCount = Int32.MaxValue,
                MaxStringContentLength = Int32.MaxValue,
            },
            MaxBufferPoolSize = 0,
            TransactionFlow = false,
            TransactionProtocol = TransactionProtocol.Default,
            TransferMode = TransferMode.Buffered,
            OpenTimeout = new TimeSpan(0, 10, 0),
            CloseTimeout = new TimeSpan(0, 10, 0),
            SendTimeout = new TimeSpan(0, 10, 0),
            ReceiveTimeout = new TimeSpan(0, 10, 0)
        }; 
        container.Register(Component.For<IFtpsServiceFacade>()
          .ImplementedBy<FtpsServiceFacade>()
          .AsWcfService(
              new DefaultServiceModel()
                  .AddEndpoints(
                      WcfEndpoint.BoundTo(binding)
                           .At(string.Format("net.tcp://{0}/FileService.Ftps",
                              "localhost"))
                  )).LifestyleSingleton() );
var binding=new nettcppbinding
{
PortSharingEnabled=true,
MaxBufferSize=Int32.MaxValue,
MaxReceivedMessageSize=Int32.MaxValue,
ReaderQuotas=新的XmlDictionaryReaderQuotas
{
MaxArrayLength=Int32.MaxValue,
MaxBytesPerRead=Int32.MaxValue,
MaxDepth=Int32.MaxValue,
MaxNameTableCharCount=Int32.MaxValue,
MaxStringContentLength=Int32.MaxValue,
},
MaxBufferPoolSize=0,
TransactionFlow=false,
TransactionProtocol=TransactionProtocol.Default,
TransferMode=TransferMode.Buffered,
OpenTimeout=新的时间跨度(0,10,0),
CloseTimeout=新的时间跨度(0,10,0),
SendTimeout=新的时间跨度(0,10,0),
ReceiveTimeout=新的时间跨度(0,10,0)
}; 
container.Register(Component.For())
.由()实施
.ASWCF服务(
新的DefaultServiceModel()
.加点(
WcfEndpoint.BoundTo(绑定)
.At(string.Format(“net.tcp://{0}/FileService.Ftps”,
“本地主机”))
)).singleton()的生活方式;

在服务器端和客户端之间建立通信通道需要服务器端和客户端具有相同的绑定设置。因此,出现了上述错误。为了解决这个问题,我们应该更改服务器端而不是客户端的设置。支持的文件的最大大小超过2GB,通过以下配置完成

NetTcpBinding binding = new NetTcpBinding();
            binding.Security.Mode = SecurityMode.None;
            binding.MaxBufferSize = Int32.MaxValue;
            binding.MaxBufferPoolSize = Int32.MaxValue;
            binding.MaxReceivedMessageSize = Int32.MaxValue;
特别是对于安全模式,它应该与位于客户端的设置完全一致。
如果问题仍然存在,请随时通知我。

我想知道服务器端的配置。以及通过添加服务引用自动生成的客户端配置。我们可能会忘记将绑定配置应用于服务端点。Abraham Qian,我已经更新了我的问题,我添加了服务器和客户端配置“通信通道的建立”-不,在出现此错误之前已经建立了。“要求服务器端和客户端具有相同的绑定设置”-否,您可以将客户端完美配置为仅发送1MB消息,而服务器接受1GB的消息。在这种情况下,您可能认为某些配置的某些部分限制了消息大小,但您的声明是不正确的。@dragullar,请尝试设置MaxBufferPoolSize属性。此外,请查看此链接,希望它对您有用。