WCF端点绑定设置不会更新

时间:2009-12-19 10:49:34

标签: wcf web-services binding endpoints

所有更改WCF自托管服务端点的配置设置的尝试都失败:

public void Start()
    {
        BasicHttpBinding binding = new BasicHttpBinding();
        binding.Name = "NAVBinding";
//--------------------START editing-------------------------------
        TimeSpan interval = new TimeSpan(1, 50, 00); // all these following (inbetween comments) lines have no effect
        binding.MaxReceivedMessageSize = 2147483647;
        binding.MaxBufferSize = 2147483647;
        binding.ReceiveTimeout = interval;
        binding.OpenTimeout = interval;
        binding.CloseTimeout = interval;
        binding.SendTimeout = interval;
        XmlDictionaryReaderQuotas readerQuotas = new XmlDictionaryReaderQuotas();
        readerQuotas.MaxDepth = 2147483647;
        readerQuotas.MaxStringContentLength = 2147483647;
        readerQuotas.MaxArrayLength = 2147483647;
        readerQuotas.MaxBytesPerRead = 2147483647;
        readerQuotas.MaxNameTableCharCount = 2147483647;
        binding.ReaderQuotas = readerQuotas;
//----------------------END editing---------------------------
        binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
        Uri baseAddress = new Uri("http://localhost:8000/nav/customer");
        Customer_Service service = new Customer_Service();
        serviceHost = new ServiceHost(service, baseAddress);
        serviceHost.AddServiceEndpoint(typeof(ICustomer_Service), binding, baseAddress);
        OpenMetadataExchange(baseAddress);
        service.navEventListner = this;
        serviceHost.Open();

    }

但我可以在 wcfStorm 应用程序的帮助下轻松更改MaxReceivedMessageSize属性,在这种情况下,它确实已更改。但重新启动服务后,所有内容都恢复为默认设置(例如MaxReceivedMessageSize = 65536)。

拜托,我做错了什么?如何编辑我的代码以便更新新值?

1 个答案:

答案 0 :(得分:1)

SERVER SIDE 上设置这些值不会在 CLIENT SIDE 上自动设置它们。

仅在服务器端设置它们是不够的 - 客户端和服务器之间的传输由客户端和服务器之间的两个设置中的最小设置决定。即使服务器允许2 GB的邮件大小,如果客户端仍然坚持64 KB,则较小的64 KB值会获胜。这并不意味着服务器端的2 GB设置不存在 - 它是,但它没有效果,因为客户端使用较小的设置。

如果要在客户端使用相同的设置,则需要相应地配置客户端。在创建客户端代理时,您需要执行相同的操作,或者从app.config文件配置客户端。