WCF+Restfull服务 提交或获取数据时数据大小限制问题解决方案
近日在使用wcf的restfull架构服务时遭遇到了提交大数据的问题。
大数据包含两种情形:
1)单条数据量过大。
2)提交或获取的数据条数过多。
在测试时发现,默认设置下当单条JSON数据大于30K时服务便不予受理。
提交或获取数据大小的限制来自两方面,即IIS服务和WCF服务。
这两方面的限制都可以通过配置WCF服务端的Web.config相关配置节点的方式解决。
废话不说了,直接上解决方案。
- 未配置的原始Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="BaseConnectionString" connectionString="server=.\SQLEXPRESS;database=TLPBizF;uid=*******;pwd==*******;" providerName="System.Data.SqlClient" />
<add name="BizDBConnectionString" connectionString="server=.\SQLEXPRESS;database=TLPBizDB;uid==******;pwd==*******;" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="TimeOutMinutes" value="20" />
<add key="BizDBName" value="TLPBizDB"/>
<add key="aspnet:MaxJsonDeserializerMembers" value="1500000000" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web> <system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers accessPolicy="Read, Execute, Script" />
<staticContent>
<mimeMap fileExtension=".svc" mimeType="application/octet-stream" />
</staticContent>
</system.webServer> </configuration>
- 已配置的Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="BaseConnectionString" connectionString="server=.\SQLEXPRESS;database=TLPBizF;uid=*******;pwd==*******;" providerName="System.Data.SqlClient" />
<add name="BizDBConnectionString" connectionString="server=.\SQLEXPRESS;database=TLPBizDB;uid==*******;;pwd==*******;" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="TimeOutMinutes" value="20" />
<add key="BizDBName" value="TLPBizDB"/>
<add key="aspnet:MaxJsonDeserializerMembers" value="1500000000" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxRequestLength="2147483644"/>
</system.web>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483644"/>
</webServices>
</scripting>
</system.web.extensions>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
<behavior name="BigDataServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<standardEndpoints>
<webHttpEndpoint>
<!-- 服务节点配置 -->
<standardEndpoint name="BigDataServiceEndPoint"
transferMode="Buffered"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647"
defaultOutgoingResponseFormat="Json"
helpEnabled="true"
automaticFormatSelectionEnabled="true">
<readerQuotas maxDepth="64"
maxNameTableCharCount="2147483647"
maxStringContentLength="2147483647"
maxBytesPerRead="2147483647"
maxArrayLength="2147483647"
></readerQuotas>
</standardEndpoint>
</webHttpEndpoint> </standardEndpoints>
<services>
<!-- 服务对应配置 -->
<service name="SFiresoft.TLP.Services.BizCoreService" behaviorConfiguration="BigDataServiceBehavior">
<endpoint endpointConfiguration="BigDataServiceEndPoint"
kind="webHttpEndpoint"
contract="SFiresoft.TLP.Services.IBizCoreService"
>
</endpoint>
</service>
</services>
</system.serviceModel> <system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers accessPolicy="Read, Execute, Script" />
<staticContent>
<mimeMap fileExtension=".svc" mimeType="application/octet-stream" />
</staticContent>
</system.webServer> </configuration>
对比:
1)system.web节点:
<httpRuntime maxRequestLength="2147483644"/>
应对IIS服务请求数据大小限制的设置。
2)system.serviceModel节点下“webHttpEndpoint”的配置:
<standardEndpoint
name="MyPoint"
transferMode="Buffered"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647"
defaultOutgoingResponseFormat="Json"
helpEnabled="false"
automaticFormatSelectionEnabled="true">
<readerQuotas
maxDepth="64"
maxNameTableCharCount="2147483647"
maxStringContentLength="2147483647"
maxBytesPerRead="2147483647"
maxArrayLength="2147483647"
></readerQuotas>
</standardEndpoint>
此处:
- name可以随意取。
- 数据大小设置部分不说了。
- helpEnabled属性:设置为true时则可以在服务URL后+/help的方式查看服务列表。
如服务地址:http://localhost:9900/MapService.svc
查看服务方式:http://localhost:9900/MapService.svc/help
如下图:
3)system.serviceModel节点下“service”的配置:
<services>
<service name="SFiresoft.TLP.Services.BizCoreService" behaviorConfiguration="Wcf4BigData.Web.BigDataServiceBehavior">
<endpoint endpointConfiguration="MyPoint" kind="webHttpEndpoint" contract="SFiresoft.TLP.Services.IBizCoreService">
</endpoint>
</service>
</services>
- Service name设置同实现服务的类名一致。
- behaviorConfiguration 内容与behavior节点中的相应名称一致。
- 此处Endpoint节点中contract要和描述服务结构的接口名一致。
其他的不多说了自悟。
着重参考:《已配置的Web.config》
南京酷得软件- 陈朕
WCF+Restfull服务 提交或获取数据时数据大小限制问题解决方案的更多相关文章
- 使用phpexcel导入excel文件种的时期数据时数据导入格式
在使用phpexcel导入类似于 YYYY-MM-DD HH:ii:ss格式的数据时,导入成功以后会发现导入的数据其实是类似于42085.746516204格式的数据( excel在存储时间类型的数据 ...
- 日志系统实战(二)-AOP动态获取运行时数据
介绍 这篇距上一篇已经拖3个月之久了,批评自己下. 通过上篇介绍了解如何利用mono反射代码,可以拿出编译好的静态数据.例如方法参数信息之类的. 但实际情况是往往需要的是运行时的数据,就是用户输入等外 ...
- 使用Mono Cecil 动态获取运行时数据 (Atribute形式 进行注入 用于写Log) [此文报考 xxx is declared in another module and needs to be imported的解决方法]-摘自网络
目录 一:普通写法 二:注入定义 三:Weave函数 四:参数构造 五:业务编写 六:注入调用 7. 怎么调用别的程序集的方法示例 8. [is declared in another module ...
- Oracle使用——impdp导入数据时数据表已经存在
背景 在做数据迁移时,需要将不同地方的dmp文件整合到一个数据库中,在导入时,目标表已经存在,该如何把数据追加进入目标表中 方法介绍 当使用IMPDP完成数据库导入时,如遇到表已存在时,Oracle提 ...
- vs获取最新时,提示签出解决方案
项目中的文件有被意外去掉了只读属性的. VSS中签入状态的文件在本地都有只读属性. 如果VSS中是签入状态,而对应的本机文件没有只读状态,在获取最新版本的时候,就会弹出一个对话框提示签出还是用VSS中 ...
- ajax 发送json数据时为什么需要设置contentType: "application/json”
1. ajax发送json数据时设置contentType: "application/json”和不设置时到底有什么区别? contentType: "application/j ...
- ajax发送json数据时为什么需要设置contentType: "application/json”
1. ajax发送json数据时设置contentType: "application/json”和不设置时到底有什么区别?contentType: "application/js ...
- 解决 el-autocomplete 不显示及没数据时闪一下的问题
项目中用到了elementUI中的远程搜索即 el-autocomplete 组件,估计首次使用的都会遇到一些小问题,只要你能认真看完并且耐心理解,保证能帮到你,效果图如下: 组件代码: <el ...
- WCF RestFull提交数据超出限额解决方法
最近在使用wcf restfull时出现了超大数据提交出错的问题. 服务端会返回错误:服务器处理请求时遇到错误.有关构造有效服务请求的内容,请参阅服务帮助页.异常消息为“反序列化对象 属于类型 Yes ...
随机推荐
- 技术笔记:Indy的TIdSMTP改造,解决发送Html和主题截断问题
使用Indy来发邮件坑不少啊,只不过有比没有好吧,使用delphi6这种老工具没办法,只能使用了新一点的Indy版本9,公司限制... 1.邮件包含TIdText和TIdAttachment时会出现T ...
- CYQ.Data 从入门到放弃ORM系列:开篇:自动化框架编程思维
前言: 随着CYQ.Data 开始回归免费使用之后,发现用户的情绪越来越激动,为了保持这持续的激动性,让我有了开源的念头. 同时,由于框架经过这5-6年来的不断演进,以前发的早期教程已经太落后了,包括 ...
- 2000条你应知的WPF小姿势 基础篇<63-68 Triggers和WPF类逻辑结构>
在正文开始之前需要介绍一个人:Sean Sexton. 来自明尼苏达双城的软件工程师.最为出色的是他维护了两个博客:2,000ThingsYou Should Know About C# 和 2,00 ...
- Entity Framework 6 Recipes 2nd Edition(10-7)译 -> TPH继承模型中使用存储过程
10-7. TPH继承模型中使用存储过程 问题 用一个存储过程来填充TPH继承模型的实体 解决方案 假设已有如Figure 10-7所示模型. 我们有两个派生实体: Instructor(教员)和St ...
- Atitti 载入类的几种方法 Class.forName ClassLoader.loadClass 直接new
Atitti 载入类的几种方法 Class.forName ClassLoader.loadClass 直接new 1.1. 载入类的几种方法 Class.forName ClassLo ...
- SVM分类与回归
SVM(支撑向量机模型)是二(多)分类问题中经常使用的方法,思想比较简单,但是具体实现与求解细节对工程人员来说比较复杂,如需了解SVM的入门知识和中级进阶可点此下载.本文从应用的角度出发,使用Libs ...
- Parallel并行之乱用
关于Parallel我也不细说了,一则微软封装的很好用,二来介绍这个的遍地都是. 我要说的是,要想成为一个优秀的标题党,一定要把重点放到别的地方,为了节省大家阅读时间,我先把结论说了,然后再慢慢从头说 ...
- 挑子学习笔记:BIRCH层次聚类
转载请标明出处:http://www.cnblogs.com/tiaozistudy/p/6129425.html 本文是“挑子”在学习BIRCH算法过程中的笔记摘录,文中不乏一些个人理解,不当之处望 ...
- Hibernate(6)—— 一对多 和 多对多关联关系映射(xml和注解)总结
俗话说,自己写的代码,6个月后也是别人的代码……复习!复习!复习!涉及的知识点总结如下: One to Many 映射关系 多对一单向外键关联(XML/Annotation) 一对多单向外键关联(XM ...
- Ubuntu 14.04 LTS中怎样安装fcitx中文输入法
轉載: http://jingyan.baidu.com/article/4b07be3c60da3f48b380f3f0.html 一,安装fcitx,这么好的软件,ubuntu软件中心肯定是找得到 ...