在从客户端向WCF服务端传送较大数据(>65535B)的时候,发现程序直接从Reference的BeginInvoke跳到EndInvoke,没有进入服务端的Service实际逻辑中,怀疑是由于数据过大超出限定导致的。

问题是我实际发送的数据是刚刚从WCF服务端接收过来的,一来一去,数据量差别并不大。

然后发现,在客户端和服务端实际使用的是不同的配置,对于客户端,在添加ServiceReference时自动生成的ServiceReferences.ClientConfig文件中system.serviceModel节下有这样的设置:

  1. <bindings>  
  2.     <basicHttpBinding>  
  3.         <binding name="BasicHttpBinding_WcfService" maxBufferSize="2147483647"  
  4.             maxReceivedMessageSize="2147483647">  
  5.             <security mode="None" />  
  6.         </binding>  
  7.     </basicHttpBinding>  
  8. </bindings>  

<bindings>

<basicHttpBinding>

<binding name="BasicHttpBinding_WcfService" maxBufferSize="2147483647"

maxReceivedMessageSize="2147483647">

<security mode="None" />

</binding>

</basicHttpBinding>

</bindings>

 

然后在Client节里应用Binding Configuration:

  1. <client>  
  2.             <endpoint address="http://localhost:22000/Service/WcfService.svc"  
  3.                 binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_WcfService"  
  4.                 contract="WcfServiceReference.WcfService" name="BasicHttpBinding_WcfService" />  
  5. </client>  

<client>

<endpoint address="http://localhost:22000/Service/WcfService.svc"

binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_WcfService"

contract="WcfServiceReference.WcfService" name="BasicHttpBinding_WcfService" />

</client>

 

的大小。

问题找到,解决就比较容易了:

在Bindings节添加新的Binding设置,指定最大接受数据:

  1. <system.serviceModel>  
  2. .......  
  3. <bindings>  
  4.     <basicHttpBinding>  
  5.         <binding name="LargeDataTransferServicesBinding" maxReceivedMessageSize="2147483647"  
  6.   messageEncoding="Text" transferMode="Streamed" sendTimeout="00:10:00" />  
  7.     </basicHttpBinding>  
  8. </bindings>  
  9. ............  
  10. </system.serviceModel>  

<system.serviceModel>

.......

<bindings>

<basicHttpBinding>

<binding name="LargeDataTransferServicesBinding" maxReceivedMessageSize="2147483647"

messageEncoding="Text" transferMode="Streamed" sendTimeout="00:10:00" />

</basicHttpBinding>

</bindings>

............

</system.serviceModel>

 

之后给相应的Service指定bindingConfiguration属性:

  1. <system.serviceModel>  
  2. ......  
  3.     <services>  
  4.       <service name="FitFindFW.WCFService.SalaryManage.WageManageService">  
  5.         <endpoint address="" binding="basicHttpBinding"  
  6.           bindingConfiguration="LargeDataTransferServicesBinding" name="XXX" contract="FitFindFW.WCFService.SalaryManage.IWageManageService" />  
  7.       </service>  
  8.     </services>  
  9. ............  
  10. </system.serviceModel>  
  11. contract : 命名空间 + 类名  

<system.serviceModel>

......

<services>

<service name="FitFindFW.WCFService.SalaryManage.WageManageService">

<endpoint address="" binding="basicHttpBinding"

bindingConfiguration="LargeDataTransferServicesBinding" name="XXX" contract="FitFindFW.WCFService.SalaryManage.IWageManageService" />

</service>

</services>

............

</system.serviceModel>

contract : 命名空间 + 类名

 

这样就可以从客户端发送足够大的数据了。

P.S.:

.net默认只能传4M的文件,所以尽管设定了Wcf两端的配置,还是超不出.net的限定,所以如果要传输大文件,还需要在System.Web节下加上

  1. <httpRuntimemaxRequestLengthhttpRuntimemaxRequestLength="102400" />  

<httpRuntimemaxRequestLength="102400" />

这里的单位是KB,这样就可以传100M的文件了。当然,这么大的文件,最好还是分段传输比较好。

远程服务器返回了意外相应:(413) Request Entity Too Large。的更多相关文章

  1. WCF错误远程服务器返回了意外响应: (413) Request Entity Too Large。解决方案

    这个问题出现的原因是  调用wcf服务的时候传递的参数 长度太大   wcf数据传输采用的默认的大小是65535字节. ---------------------------------------- ...

  2. wcf 远程服务器返回了意外响应: (413) Request Entity Too Large。

    我遇到这个问题的原因是:我使用asp.net 网站调用wcf服务后,通过方法提交数据产生的.我提交的数据是一个实体,包含很多字符串和图片格式的二进制数据超过4M 就报个错误. 后来同事帮忙解决了.他说 ...

  3. WCF (413) Request Entity Too Large

    有网友碰到过这样的问题:wcf 远程服务器返回了意外响应: (413) Request Entity Too Large. - wsx_net,问题详细内容为:挺不错的博文:wcf 远程服务器返回了意 ...

  4. 上传文件异常问题 | 413 Request Entity Too Large

    开发中遇到这样的问题:一个上传文件的功能,内网测试都正常了,但是发布到外网就无法上传大点的(大于1MB)文件,更奇怪的是,后台还没有任何的异常信息. 于是就用Http抓包工具(HttpDetect)看 ...

  5. 413 Request Entity Too Large

    做小视频上传,结果接口总是返回500,服务器端跟踪,根本就进不来,再次翻查,发下服务器返回的其实是413,只不过APP底层接口将所有不是200的回包都转成500了,问题定位. 有了错误码,有了描述,字 ...

  6. nginx解决超长请求串(413 request Entity too Large错误解决办法)

    <div class="hide-article-box text-center" style="display: block;"> <a c ...

  7. nginx 出现413 Request Entity Too Large问题的解决方法

    nginx 出现413 Request Entity Too Large问题的解决方法 使用php上传图片(大小1.9M),出现 nginx: 413 Request Entity Too Large ...

  8. dnmp(docker的lnmp)安装WordPress之后图片上传问题 问题:图片上传大小问题解决和 报错413 Request Entity Too Large

    首先是提示超过图片尺寸和大小, 最后发现都是图片大小的问题, 需要修改php的最大上传size 修改之后查看php配置  已经生效  但是还是报错, 提示返回不是合法的json,  查看控制台, 报错 ...

  9. (原)使用TortoiseGit提交代码push的时候报错:HTTP 413 curl 22 The requested URL returned error: 413 Request Entity Too Large

    今天我想rk的sdk包里面的一些东西提交到我的git服务器上,结果,总是报错,折腾了一下午,结果才解决. 首先看看我提交代码的时候,报错的信息: git.exe push --progress &qu ...

  10. WCF错误:413 Request Entity Too Large 的一个解决方法

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

随机推荐

  1. Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)

    Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense ...

  2. 复制文件到U盘错误0x80071AC3,请运行chkdsk并重试

    转载:https://www.xitmi.com/1157.html 在日常的工作学习中,我们经常会用到U盘拷贝文件.有时候当我们复制文件到U盘时,总会碰到各种问题,那如果我们碰到错误0x80071A ...

  3. struts2 action中字符串转json对象出错 java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException

    commons-lang包有错,要么是引入错误,要么是没引入. 报不同错误,引入不同包. commons-beanutils-1.8.0.jar不加这个包 java.lang.NoClassDefFo ...

  4. python --- 17. 面向对象成员

    面向对象的成员 能写的所有成员 一.变量 1.实例变量 访问时      对象.变量 2.类变量 访问时     类名.变量 注意: 二.方法 1.实例方法 必须有一个参数(self) 调用时    ...

  5. Linux下调整ext3分区大小【转】

    本文转载自:https://blog.csdn.net/cruise_h/article/details/22403529 本文讨论如何再不丢失数据的情况下调整已有ext3分区的大小,包括: 压缩已有 ...

  6. Spring Boot 项目中常见注解

    @Autowired 自动导入依赖的 Bean.byType方式.把配置好的 Bean拿来用,完成属性.方法的组装,它可以对类成员变量.方法及构造函数进行标注,完成自动装配的工作 import org ...

  7. 【做题】Codeforces Round #453 (Div. 1) D. Weighting a Tree——拆环

    前言:结论题似乎是我的硬伤…… 题意是给你一个无向图,已知连接到每一个点的边的权值和(为整数,且属于区间[-n,n]),需要求出每条边权值的一个合法解(都要是在区间[-2*n^2,2*n^2]内的整数 ...

  8. 【入门】Gradle的基本使用、在IDEA中的配置、常用命令

    一.介绍 java的源码构建工具,大致经历了 ant -> maven -> gradle 这个过程,每一次进步,都是在解决之前的工具所带来的问题,简单来说: 1. ant 功能虽然也很强 ...

  9. 【Dalston】【第七章】分布式链路跟踪(Sleuth)

    当我们进行微服务架构开发时,通常会根据业务来划分微服务,各业务之间通过REST进行调用.一个用户操作,可能需要很多微服务的协同才能完成,如果在业务调用链路上任何一个微服务出现问题或者网络超时,都会导致 ...

  10. HDU 1465 不容易系列之一

    扯淡 貌似有傻逼的做法XD 话说我没开long long,忘读入n,忘了清零ans WA了三遍是什么操作啊 傻了傻了 思路 显然是一个错排问题啊XD 但是我们不套公式,我们用一发二项式反演 二项式反演 ...