超出了传入消息的最大消息大小配额(65536).Silverlight WCF



我已经在整天搜索解决我的问题(也在stackoverflow上),但没有任何效果。我仍然遇到错误:

"超过了传入消息的最大消息大小配额(65536)。要增加配额,请在适当的绑定元素上使用MaxReceivedMessagesize属性。"

有数百种解决方案,但基于项目中的.config文件。我有WCF服务和Silverlight客户端。它们之间的绑定仅通过编程方式设置。

这是WCF服务配置的块代码:

private ServiceHostBase CreateService(Uri baseAddress)
    {
        var serviceHost = new ServiceHost(typeof(MyService), new[] { baseAddress });
        var endPointWithoutSSL = new BasicHttpBinding()
        {
            MaxBufferSize = int.MaxValue,
            MaxReceivedMessageSize = int.MaxValue,
            MaxBufferPoolSize = int.MaxValue,
        };
        serviceHost.AddServiceEndpoint(typeof(MyService), endPointWithoutSSL,                                       baseAddress.ToString());
        return serviceHost;
    }

在Silverlight项目的端点项目配置中,如下

private BasicHttpBinding GetBinding()
    {
        var securityMode = GetSecurityMode();
        var binding = new BasicHttpBinding(securityMode)
        {
            SendTimeout = TimeSpan.FromMinutes(10),
            OpenTimeout = TimeSpan.FromMinutes(10),
            CloseTimeout = TimeSpan.FromMinutes(10),
            ReceiveTimeout = TimeSpan.FromMinutes(10),
            TextEncoding = Encoding.UTF8,
            TransferMode = TransferMode.Buffered,
            MaxReceivedMessageSize = int.MaxValue,
            MaxBufferSize = int.MaxValue,
        };
        return binding;
    }

无论我多么努力,MaxReceivedMessagesize都将其设置为从客户端设置为65K。Microsoft WCF跟踪工具表明,在抛出超过最大收到的消息大小的例外之后。

更有趣的是,在端点中启用basichttpsecuritymode.transport不会导致此错误。但是,我必须在没有basichttpsecuritymode.transport选项的情况下设置端点。

任何帮助将不胜感激。

谢谢

在WCF侧的代码下方尝试下面的代码。

    private ServiceHostBase CreateService(Uri baseAddress)
    {
        var serviceHost = new ServiceHost(typeof(MyService), new[] { baseAddress });
        var endPointWithoutSSL = new BasicHttpBinding()
        {
            MaxBufferSize = int.MaxValue,
            MaxReceivedMessageSize = int.MaxValue,
            MaxBufferPoolSize = int.MaxValue,
        };
        endPointWithoutSSL.ReaderQuotas.MaxStringContentLength = int.MaxValue;
        endPointWithoutSSL.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;
        endPointWithoutSSL.ReaderQuotas.MaxDepth = int.MaxValue;
        endPointWithoutSSL.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
        endPointWithoutSSL.ReaderQuotas.MaxArrayLength = int.MaxValue;
        serviceHost.AddServiceEndpoint(typeof(MyService), endPointWithoutSSL, baseAddress.ToString());
        return serviceHost;
    }

相关内容

  • 没有找到相关文章

最新更新