近日在使用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. Spring WebService入门

    Web service是一个平台独立的,低耦合的,自包含的.基于可编程的web的应用程序,可使用开放的XML(标准通用标记语言下的一个子集)标准来描述.发布.发现.协调和配置这些应用程序,用于开发分布 ...

  2. 写个Fragment方便的抽象基类 BaseFragment

    package com.zb.zhihuianyang.base; import android.app.Activity; import android.os.Bundle; import andr ...

  3. 【深入浅出jQuery】源码浅析2--奇技淫巧

    最近一直在研读 jQuery 源码,初看源码一头雾水毫无头绪,真正静下心来细看写的真是精妙,让你感叹代码之美. 其结构明晰,高内聚.低耦合,兼具优秀的性能与便利的扩展性,在浏览器的兼容性(功能缺陷.渐 ...

  4. 分享阿里云推荐码 IC1L2A,购买服务器可以直接打9折,另附阿里云服务器部署ASP.NET MVC5关键教程

    阿里云推荐码为:IC1L2A 阿里云还是不错滴. 以windows server 2008 R2为例,介绍如何从全新的服务器部署MVC5 站点. 新购买的阿里云服务器是没有IIS的,要安装IIS: 控 ...

  5. Thread.Sleep(0) vs Sleep(1) vs Yeild

    本文将要提到的线程及其相关内容,均是指 Windows 操作系统中的线程,不涉及其它操作系统. 文章索引 核心概念 Thread.Yeild       Thread.Sleep(0) Thread. ...

  6. 如何开发一个简单的HTML5 Canvas 小游戏

    原文:How to make a simple HTML5 Canvas game 想要快速上手HTML5 Canvas小游戏开发?下面通过一个例子来进行手把手教学.(如果你怀疑我的资历, A Wiz ...

  7. Windows 2008 R2 安装sp1时未知错误的解决办法

    最近在为Windows Server 2008 R2 打sp1补丁时出现“发生未知错误”,详细信息错误:0x800f0818: google后找到解决问题步骤,参照:http://www.wikiho ...

  8. vue源码解析阅读列表

    https://zhuanlan.zhihu.com/p/24435564 开发vue(或类似的MVVM框架)的过程中,需要面对的主要问题有哪些? 剖析vue实现原理,自己动手实现mvvm 官网介绍

  9. 让DIV中文字换行显示

    1. <style> div { white-space:normal; word-break:break-all; word-wrap:break-word; } </style& ...

  10. Hadoop Shell命令大全

    hadoop支持命令行操作HDFS文件系统,并且支持shell-like命令与HDFS文件系统交互,对于大多数程序猿/媛来说,shell-like命令行操作都是比较熟悉的,其实这也是Hadoop的极大 ...