WCF - MaxStringContentLength MaxReceivedMessageSize
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 的信息。
{
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相关推荐
- C# WCF WinCE 解决方案 错误提示之:已超过传入消息(65536)的最大消息大小配额。若要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性...
C# WCF WinCE 解决方案 错误提示之:已超过传入消息(65536)的最大消息大小配额.若要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性 网上的解决方案 ...
- 构建RESTful风格的WCF服务
RESTful Wcf是一种基于Http协议的服务架构风格. 相较 WCF.WebService 使用 SOAP.WSDL.WS-* 而言,几乎所有的语言和网络平台都支持 HTTP 请求. RESTf ...
- 大数据量传输时配置WCF的注意事项
WCF传输数据量的能力受到许多因素的制约,如果程序中出现因需要传输的数据量较大而导致调用WCF服务失败的问题,应注意以下配置: 1.MaxReceivedMessageSize:获取或设置配置了此绑定 ...
- WCF错误:413 Request Entity Too Large
在我们用WCF传输数据的时候,如果启用默认配置,传输的数据量过大,经常会出这个错误. WCF包含服务端与客户端,所以这个错误可能出现在服务端返回数据给客户端,或客户端传数据给服务端时. 1. 服务端返 ...
- 使用WC“.NET研究”F实现SOA面向服务编程——简单的WCF开发实例
前面为大家介绍过WCF的特点,现在再讲解一下WCF基础概念. 在WCF里,各个Application之间的通信是由EndPoint来实现的,EndPoint是WCF实现通信的核心要素.一个WCF Se ...
- [转]Silverlight在调用wcf时传输数据过大返回Not Found的解决办法
原文地址:http://www.cnblogs.com/gavinyao/archive/2012/04/17/2454495.html Silverlight在调用wcf时传输数据过大返回Not F ...
- wcf系列---- binding的使用(1)
文转自http://www.cnblogs.com/huangxincheng/archive/2011/10/23/2221845.html 作为WCF速成系列,只介绍些项目开发中常用到的实战知识. ...
- WCF创建到使用到发布
1,在VS里面新建一个类库项目 2,向类库项目里添加WCF服务文件 3.按照WCF约束规范编写接口和实现类 using System; using System.Collections.Generic ...
- Wcf 双工通信的应用
概述 双工(Duplex)模式的消息交换方式体现在消息交换过程中,参与的双方均可以向对方发送消息.基于双工MEP消息交换可以看成是多个基本模式下(比如请求-回复模式和单项模式)消息交换的组合.双工ME ...
- WCF异常:HTTP 无法注册,另一应用程序正在使用 TCP 端口 80
今天,调试服务的时候,忽然抛了个异常.异常信息是:"HTTP 无法注册 URL http://+/Temporary_Listen_Addresses/144ff7cb-10a4-4836- ...
最新文章
- 修改Linux内核参数提高服务器并发能力
- docker容器内部无法ping通域名?
- 从php传过来的是字符串吗,PHP 字符串
- Find All Numbers Disappeared in an Array
- 如何将docker 镜像上传到docker hub仓库
- Python多重继承(一分钟读懂)
- 设置元素的高度为百分比,结果不起作用的解决方法
- 最新喜鹊相亲交友平台微信小程序源码V2.1.2版
- Mysql环境变量的配置(详细图解)
- [算法导论] 邮递员问题
- 线下实体零售门店如何做好会员运营管理系统?
- 统计矩形中的正方形和长方形
- 组网雷达融合处理组件化设计与仿真
- 从项目管理角度如何保证质量
- 宇宙的本源—存在之道和变化之道
- VC中的所有WM消息
- 毕业论文开题报告怎么写
- go 变量大写_go语言如何将大写转小写
- 错误类型:reflection.ReflectionException: Could not set property ‘xxx‘ of ‘class ‘xxx‘ with value ‘xxx‘
- 隐藏在QRCode二维码背后的秘密
热门文章
- paip.SOCKET抓包工具总结V2012.9.17
- 最近卡脖子的汽车芯片产业链全景图(车规级芯片)
- 中证协 | 安青松:“金融+科技”是证券业高质量发展的战略引擎
- 实话实说?基金公司“存量时代”的创新
- (转)谭志勇、赵微:区块链技术在中国商品交易市场的应用与发展
- (转)BlackRock:全球最大资管公司如何一步步倒戈人工智能?
- Julia: Atom 来了!如何在Atom中操作Julia?
- 程序员 | 我在大厂烧垃圾
- 那一年,创业 vs 阿里(下):阿里篇
- 【图像去噪】基于matlab GUI均值+中值+空间+高斯滤波图像去噪【含Matlab源码 763期】