近日在使用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服务 提交或获取数据时数据大小限制问题解决方案的更多相关文章

  1. 使用phpexcel导入excel文件种的时期数据时数据导入格式

    在使用phpexcel导入类似于 YYYY-MM-DD HH:ii:ss格式的数据时,导入成功以后会发现导入的数据其实是类似于42085.746516204格式的数据( excel在存储时间类型的数据 ...

  2. 日志系统实战(二)-AOP动态获取运行时数据

    介绍 这篇距上一篇已经拖3个月之久了,批评自己下. 通过上篇介绍了解如何利用mono反射代码,可以拿出编译好的静态数据.例如方法参数信息之类的. 但实际情况是往往需要的是运行时的数据,就是用户输入等外 ...

  3. 使用Mono Cecil 动态获取运行时数据 (Atribute形式 进行注入 用于写Log) [此文报考 xxx is declared in another module and needs to be imported的解决方法]-摘自网络

    目录 一:普通写法 二:注入定义 三:Weave函数 四:参数构造 五:业务编写 六:注入调用 7.  怎么调用别的程序集的方法示例 8. [is declared in another module ...

  4. Oracle使用——impdp导入数据时数据表已经存在

    背景 在做数据迁移时,需要将不同地方的dmp文件整合到一个数据库中,在导入时,目标表已经存在,该如何把数据追加进入目标表中 方法介绍 当使用IMPDP完成数据库导入时,如遇到表已存在时,Oracle提 ...

  5. vs获取最新时,提示签出解决方案

    项目中的文件有被意外去掉了只读属性的. VSS中签入状态的文件在本地都有只读属性. 如果VSS中是签入状态,而对应的本机文件没有只读状态,在获取最新版本的时候,就会弹出一个对话框提示签出还是用VSS中 ...

  6. ajax 发送json数据时为什么需要设置contentType: "application/json”

    1. ajax发送json数据时设置contentType: "application/json”和不设置时到底有什么区别? contentType: "application/j ...

  7. ajax发送json数据时为什么需要设置contentType: "application/json”

    1. ajax发送json数据时设置contentType: "application/json”和不设置时到底有什么区别?contentType: "application/js ...

  8. 解决 el-autocomplete 不显示及没数据时闪一下的问题

    项目中用到了elementUI中的远程搜索即 el-autocomplete 组件,估计首次使用的都会遇到一些小问题,只要你能认真看完并且耐心理解,保证能帮到你,效果图如下: 组件代码: <el ...

  9. WCF RestFull提交数据超出限额解决方法

    最近在使用wcf restfull时出现了超大数据提交出错的问题. 服务端会返回错误:服务器处理请求时遇到错误.有关构造有效服务请求的内容,请参阅服务帮助页.异常消息为“反序列化对象 属于类型 Yes ...

随机推荐

  1. Zookeeper常用命令

    http://www.cnblogs.com/chengxin1982/p/3997706.html

  2. 一年之计在于春,2015开篇:PDF.NET SOD Ver 5.1完全开源

    前言: 自从我2014年下半年到现在的某电商公司工作后,工作太忙,一直没有写过一篇博客,甚至连14年股票市场的牛市都错过了,现在马上要过年了,而今天又是立春节气,如果再不动手,那么明年这个无春的年,也 ...

  3. 舍弃Nunit拥抱Xunit

    前言 今天与同事在讨论.Net下测试框架的时候,说到NUnit等大多数测试框架的SetUp以及TearDown方法并不是显得那么完美,所以在公司内部的项目中采用了Xunit框架.那么究竟是什么样的原因 ...

  4. 一步步开发自己的博客 .NET版(1、基本显示)

    前言 我们每个猿都有一个搭建自己独立博客的梦,我也不例外.以前想 现在想 以后也想.之所以一直迟迟没有着手,是因为难以跨出第一步.每次心里想着,等我以后技术好了再说,然后就没有然后了.以前用过word ...

  5. .NET Web开发技术简单整理

    在最初学习一些编程语言.一些编程技术的时候,做的更多的是如何使用该技术,如何更好的使用该技术解决问题,而没有去关注它的相关性.关注它的理论支持,这种学习技术的方式是短平快.其实工作中有时候也是这样,公 ...

  6. Top Coder算法题目浏览器

    作者:Lucida 微博:@peng_gong 豆瓣:@figure9 原文链接:http://zh.lucida.me/blog/top-code-offline-browser/ 关于 左耳朵耗子 ...

  7. epoll LT/ET 深度剖析

    EPOLL事件的两种模型: Level Triggered (LT) 水平触发 .socket接收缓冲区不为空 有数据可读 读事件一直触发 .socket发送缓冲区不满 可以继续写入数据 写事件一直触 ...

  8. .NET 程序集单元测试工具 SmokeTest 应用指南

    Smoke Test(冒烟测试),也称Regression Test(回归测试),是对软件的安装和基本功能的测试.一般地我们使用脚本来实现Smoke Test的自动化,可借用虚拟机的snapshot机 ...

  9. Hybrid App技术批量制作APP应用与跨平台解决方案

    前言 简单的聊一聊我开发了4年之久的Hybrid App(混合模式移动应用)平台开发,目前一直在持续开发与维护,支持无编程快速开发! 其本意也不是要吹捧前端有多么强大,只是用自己的实际项目阐述下对于前 ...

  10. 聊聊ASP.NET Core默认提供的这个跨平台的服务器——KestrelServer

    跨平台是ASP.NET Core一个显著的特性,而KestrelServer是目前微软推出了唯一一个能够真正跨平台的Server.KestrelServer利用一个名为KestrelEngine的网络 ...