WCF 端点绑定设置未更新
所有更改 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)。
请问我做错了什么?如何编辑我的代码以便更新新值?
All attempts to change configuration settings of WCF self hosted service endpoint fail:
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();
}
but I can easily change the MaxReceivedMessageSize
property with the help of wcfStorm application and in this case it really is changed. But after restarting service, everything gets back to its default settings (for example MaxReceivedMessageSize = 65536).
Please, what am I doing whrong? How to edit my code in order new values get updated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在服务器端上设置这些值不会自动在客户端上设置它们。
仅在服务器端设置它们是不够的 - 客户端和服务器之间的传输由客户端和服务器之间的两个设置中最小的一个决定。即使服务器允许 2 GB 的消息大小,如果客户端仍然坚持 64 KB,则 64 KB 中较小的值获胜。这并不意味着服务器端不存在 2 GB 设置 - 确实存在,但它并不有效,因为客户端使用较小的设置。
如果您想在客户端使用相同的设置,则需要相应地配置客户端。创建客户端代理时,您需要执行相同的操作,或者从 app.config 文件配置客户端。
Setting those values on the SERVER SIDE does not automagically set them on the CLIENT SIDE.
Only setting them on the server side is not enough - the transfer between client and server is dictated by the smallest of the two settings between client and server. Even if the server allows 2 GB of message size, if the client still insists on 64 KB, the smaller value of 64 KB wins. That doesn't mean the 2 GB setting on the server side isn't there - it is, but it's not being effective because the client uses a smaller setting.
If you want to use the same settings on the client side, you will need to configure the client side accordingly. You will need to do the same thing when creating your client proxy, or configure your client from an app.config file.