[ServiceContract]
public interface IService
{
[OperationContract]
void Test(string s);
}
public class Service : IService 
{
public void Test(string s)
{
Console.WriteLine(s.Length);
}
}
public class WcfTest
{
public static void Test()
{
AppDomain.CreateDomain("Server").DoCallBack(delegate
{
ServiceHost host = new ServiceHost(typeof(Service), new Uri("net.tcp://localhost:8080/service"));
host.AddServiceEndpoint(typeof(IService), new NetTcpBinding(), "");
host.Open();
});
IService channel = ChannelFactory<IService>.CreateChannel(new NetTcpBinding(), 
new EndpointAddress("net.tcp://localhost:8080/Service"));

using (channel as IDisposable)
{
channel.Test(new String('a', 1024 * 10));
}
}
}

运行一下,目标出现~~~

  未处理 System.ServiceModel.FaultException

Message="The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'Test'. The maximum string content length quota (8192) has been exceeded while reading <a href="http://tech.ddvip.com/web/xml/index.html" target="_blank">XML</a> data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader."

既然已经有了详细提示,那么我们就按照提示做。

AppDomain.CreateDomain("Server").DoCallBack(delegate

{
  XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas();
  quotas.MaxStringContentLength = 6553500;
  NetTcpBinding binding = new NetTcpBinding();
  binding.ReaderQuotas = quotas;
  ServiceHost host = new ServiceHost(typeof(Service), new Uri("net.tcp://localhost:8080/service"));
  host.AddServiceEndpoint(typeof(IService), binding, "");
  host.Open();
});
IService channel = ChannelFactory<IService>.CreateChannel(new NetTcpBinding(), 
  new EndpointAddress("net.tcp://localhost:8080/Service"));
  
using (channel as IDisposable)
{
  channel.Test(new String('a', 1024 * 10));
}

 OK!可以运行了。我们继续加大传递的字符串。

IService channel = ChannelFactory<IService>.CreateChannel(new NetTcpBinding(), 

  new EndpointAddress("net.tcp://localhost:8080/Service"));
  
using (channel as IDisposable)
{
  channel.Test(new String('a', 1024 * 100));
}

哎~~ 新的异常出现了。

  未处理 System.ServiceModel.CommunicationException

  Message="The maximum message size quota for incoming messages has been exceeded for the remote channel. See the server logs for more details."

  看异常提示,这回要改的是 channel 的信息。

AppDomain.CreateDomain("Server").DoCallBack(delegate 

{
  XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas();
  quotas.MaxStringContentLength = 6553500;
  NetTcpBinding binding = new NetTcpBinding();
  binding.ReaderQuotas = quotas;
  binding.MaxReceivedMessageSize = 6553500; // <---- Here!--------------
  ServiceHost host = new ServiceHost(typeof(Service), new Uri("net.tcp://localhost:8080/service"));
  host.AddServiceEndpoint(typeof(IService), binding, "");
  host.Open();
});
IService channel = ChannelFactory<IService>.CreateChannel(new NetTcpBinding(), 
  new EndpointAddress("net.tcp://localhost:8080/Service"));
  
using (channel as IDisposable)
{
  channel.Test(new String('a', 1024 * 100));
}

WCF - MaxStringContentLength MaxReceivedMessageSize相关推荐

  1. C# WCF WinCE 解决方案 错误提示之:已超过传入消息(65536)的最大消息大小配额。若要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性...

    C# WCF WinCE 解决方案 错误提示之:已超过传入消息(65536)的最大消息大小配额.若要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性 网上的解决方案 ...

  2. 构建RESTful风格的WCF服务

    RESTful Wcf是一种基于Http协议的服务架构风格. 相较 WCF.WebService 使用 SOAP.WSDL.WS-* 而言,几乎所有的语言和网络平台都支持 HTTP 请求. RESTf ...

  3. 大数据量传输时配置WCF的注意事项

    WCF传输数据量的能力受到许多因素的制约,如果程序中出现因需要传输的数据量较大而导致调用WCF服务失败的问题,应注意以下配置: 1.MaxReceivedMessageSize:获取或设置配置了此绑定 ...

  4. WCF错误:413 Request Entity Too Large

    在我们用WCF传输数据的时候,如果启用默认配置,传输的数据量过大,经常会出这个错误. WCF包含服务端与客户端,所以这个错误可能出现在服务端返回数据给客户端,或客户端传数据给服务端时. 1. 服务端返 ...

  5. 使用WC“.NET研究”F实现SOA面向服务编程——简单的WCF开发实例

    前面为大家介绍过WCF的特点,现在再讲解一下WCF基础概念. 在WCF里,各个Application之间的通信是由EndPoint来实现的,EndPoint是WCF实现通信的核心要素.一个WCF Se ...

  6. [转]Silverlight在调用wcf时传输数据过大返回Not Found的解决办法

    原文地址:http://www.cnblogs.com/gavinyao/archive/2012/04/17/2454495.html Silverlight在调用wcf时传输数据过大返回Not F ...

  7. wcf系列---- binding的使用(1)

    文转自http://www.cnblogs.com/huangxincheng/archive/2011/10/23/2221845.html 作为WCF速成系列,只介绍些项目开发中常用到的实战知识. ...

  8. WCF创建到使用到发布

    1,在VS里面新建一个类库项目 2,向类库项目里添加WCF服务文件 3.按照WCF约束规范编写接口和实现类 using System; using System.Collections.Generic ...

  9. Wcf 双工通信的应用

    概述 双工(Duplex)模式的消息交换方式体现在消息交换过程中,参与的双方均可以向对方发送消息.基于双工MEP消息交换可以看成是多个基本模式下(比如请求-回复模式和单项模式)消息交换的组合.双工ME ...

  10. WCF异常:HTTP 无法注册,另一应用程序正在使用 TCP 端口 80

    今天,调试服务的时候,忽然抛了个异常.异常信息是:"HTTP 无法注册 URL http://+/Temporary_Listen_Addresses/144ff7cb-10a4-4836- ...

最新文章

  1. Android开发万能Utils(工具大全)
  2. python怎么调用另一个文件的函数_python如何调用另一个py文件的所有函数?
  3. 【Java】冒泡排序
  4. Log--日志变大原因总结
  5. Windows vpn 远程桌面 使用快捷键
  6. Bootstrap3 滚动监听插件的调用方式
  7. 智能优化算法:龙格-库塔优化算法 - 附代码
  8. SVS为某大学打造无纸化会议室
  9. 【Python】监控GPU温度
  10. 大数据分析师技能图谱详解
  11. 百度网盘开放平台接口调用前的准备
  12. C++猜数字(文曲星游戏)
  13. 小程序源码:修复登录大河盲盒小程序源码,实现运营“玩法自由”,超多功能的盲盒型抽奖挖矿程序源码下载
  14. 【CVE-2021-4034】 漏洞详细原理以及复现,polkit的pkexec中的本地提权漏洞
  15. Chapter 5 (Eigenvalues and Eigenvectors): The characteristic equation (特征方程)
  16. dns服务器经赏要修复,十要诀帮你修复DNS域名解析服务故障
  17. 【黑马程序员C++ STL】学习记录
  18. 苏州5G最新规划:2021年建成23000个5G基站,大力推进5G应用
  19. Windows10家庭版VMWare15.5安装虚拟机启动蓝屏问题
  20. 《跨界杂谈》开源不是美女不要乱抱

热门文章

  1. paip.提升用户检验--------取回密码-忘记密码提醒
  2. Rust : codewars的Product of consecutive Fib numbers
  3. 黑客松Demo: Kata 的下一代镜像系统
  4. 我与OTC的诸位大神
  5. 【优化分配】基于matlab粒子群算法求解火车票分配优化问题【含Matlab源码 1137期】
  6. 【路径规划】基于matlab模拟退火算法求解火灾巡逻最短路径问题【含Matlab源码 252期】
  7. 米家扫地机器人怎么加水_最省心的扫地机器人,米家扫地机器人1C:视觉动态导航实力强劲...
  8. python函数式编程模式_Python 函数式编程
  9. word2vec字向量_Anything2Vec:将Reddit映射到向量空间
  10. numpy.loadtxt() 用法