WCF 配置文件中的MaxStringContentLength & MaxReceivedMessageSize
中午测试员在测试系统模块时发现无法通过WCF从服务器下载数据,检查配置文件后,建议开发人员修改站点的WEB.CONFIG文件,具体修改对比如下:
旧的:
<binding name="BasicHttpBinding_ICentaMiddleService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
新的:
<binding name="BasicHttpBinding_ICentaMiddleService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="9223372036854775807"
messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed"
useDefaultWebProxy="true">
<readerQuotas maxDepth="6553500" maxStringContentLength="2147483647"
maxArrayLength="6553500" maxBytesPerRead="6553500" maxNameTableCharCount="6553500" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
注意这里修改的主要是maxReceivedMessageSize这个属性,解决了从服务器通过WCF下载大容量数据的问题。
下午测试人员继续测试,发现无法将数据通过WCF保存回服务器端。检查数据后发现,需要被保存的数据超过9K,而WCF服务器端使用的是binding="basicHttpBinding"这个数据绑定方式。思路打开,则应该是由于服务器端的接收的数据大小有限制。
当初次引用服务后,显示的服务器端binding="basicHttpBinding" 的最大上传数据容量是:
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
注意是maxStringContentLength="8192" ,那么判定,是由于绑定的默认值未被修改的缘故。接着修改服务器端的web.config配置文件。修改对比如下:
旧的:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="CVMTransactionCaseServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="AuthTaxTransactionInfoServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="DealingTransactionInfoServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="HousePassTransactionInfoServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="PreAuthTransactionInfoServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="PropertyApplyInfoServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="CommonInfoServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="CenterAssignServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="CentaLine.CVM.Services.CVMTransactionCaseService" behaviorConfiguration="CVMTransactionCaseServiceBehavior">
<endpoint address="" binding="basicHttpBinding" contract="CentaLine.CVM.Services.ICVMTransactionCaseService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="CentaLine.CVM.Services.AuthTaxTransactionInfoService" behaviorConfiguration="AuthTaxTransactionInfoServiceBehavior">
<endpoint address="" binding="basicHttpBinding" contract="CentaLine.CVM.Services.IAuthTaxTransactionInfoService"/>
</service>
<service name="CentaLine.CVM.Services.DealingTransactionInfoService" behaviorConfiguration="DealingTransactionInfoServiceBehavior">
<endpoint address="" binding="basicHttpBinding" contract="CentaLine.CVM.Services.IDealingTransactionInfoService"/>
</service>
<service name="CentaLine.CVM.Services.HousePassTransactionInfoService" behaviorConfiguration="HousePassTransactionInfoServiceBehavior">
<endpoint address="" binding="basicHttpBinding" contract="CentaLine.CVM.Services.IHousePassTransactionInfoService"/>
</service>
<service name="CentaLine.CVM.Services.PreAuthTransactionInfoService" behaviorConfiguration="PreAuthTransactionInfoServiceBehavior">
<endpoint address="" binding="basicHttpBinding" contract="CentaLine.CVM.Services.IPreAuthTransactionInfoService"/>
</service>
<service name="CentaLine.CVM.Services.PropertyApplyInfoService" behaviorConfiguration="PropertyApplyInfoServiceBehavior">
<endpoint address="" binding="basicHttpBinding" contract="CentaLine.CVM.Services.IPropertyApplyInfoService"/>
</service>
<service name="CentaLine.CVM.Services.CommonInfoService" behaviorConfiguration="CommonInfoServiceBehavior">
<endpoint address="" binding="basicHttpBinding" contract="CentaLine.CVM.Services.ICommonInfoService"/>
</service>
<service name="CentaLine.CVM.Services.CenterAssignService" behaviorConfiguration="CenterAssignServiceBehavior">
<endpoint address="" binding="basicHttpBinding" contract="CentaLine.CVM.Services.ICenterAssignService"/>
</service>
</services>
</system.serviceModel>
新的:
<system.serviceModel>
<!--<behaviors />-->
<bindings>
<basicHttpBinding>
<binding name="NewBinding0" maxReceivedMessageSize="6553600">
<readerQuotas maxStringContentLength="6553600" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="CVMTransactionCaseServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="AuthTaxTransactionInfoServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="DealingTransactionInfoServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="HousePassTransactionInfoServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="PreAuthTransactionInfoServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="PropertyApplyInfoServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="CommonInfoServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="CenterAssignServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="CentaLine.CVM.Services.CVMTransactionCaseService"behaviorConfiguration="CVMTransactionCaseServiceBehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="NewBinding0"contract="CentaLine.CVM.Services.ICVMTransactionCaseService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="CentaLine.CVM.Services.AuthTaxTransactionInfoService"behaviorConfiguration="AuthTaxTransactionInfoServiceBehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="NewBinding0"contract="CentaLine.CVM.Services.IAuthTaxTransactionInfoService"/>
</service>
<service name="CentaLine.CVM.Services.DealingTransactionInfoService"behaviorConfiguration="DealingTransactionInfoServiceBehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="NewBinding0"contract="CentaLine.CVM.Services.IDealingTransactionInfoService"/>
</service>
<service name="CentaLine.CVM.Services.HousePassTransactionInfoService"behaviorConfiguration="HousePassTransactionInfoServiceBehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="NewBinding0"contract="CentaLine.CVM.Services.IHousePassTransactionInfoService"/>
</service>
<!--<service name="CentaLine.CVM.Services.PreAuthTransactionInfoService" behaviorConfiguration="PreAuthTransactionInfoServiceBehavior">
<endpoint address="" binding="basicHttpBinding" contract="CentaLine.CVM.Services.IPreAuthTransactionInfoService"/>
</service>-->
<service name="CentaLine.CVM.Services.PreAuthTransactionInfoService"behaviorConfiguration="PreAuthTransactionInfoServiceBehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="NewBinding0"
contract="CentaLine.CVM.Services.IPreAuthTransactionInfoService" />
<!--<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8080/service" />
</baseAddresses>
</host>-->
</service>
<service name="CentaLine.CVM.Services.PropertyApplyInfoService"behaviorConfiguration="PropertyApplyInfoServiceBehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="NewBinding0"contract="CentaLine.CVM.Services.IPropertyApplyInfoService"/>
</service>
<service name="CentaLine.CVM.Services.CommonInfoService"behaviorConfiguration="CommonInfoServiceBehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="NewBinding0"contract="CentaLine.CVM.Services.ICommonInfoService"/>
</service>
<service name="CentaLine.CVM.Services.CenterAssignService"behaviorConfiguration="CenterAssignServiceBehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="NewBinding0"contract="CentaLine.CVM.Services.ICenterAssignService"/>
</service>
</services>
</system.serviceModel>
主要添加内容:
<bindings>
<basicHttpBinding>
<binding name="NewBinding0" maxReceivedMessageSize="6553600">
<readerQuotas maxStringContentLength="6553600" />
</binding>
</basicHttpBinding>
</bindings>
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="NewBinding0"
contract="CentaLine.CVM.Services.IPreAuthTransactionInfoService" />
最后单元测试,通过!爽!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
2012-09-13 CSS3 @font-face
2012-09-13 cannot create windows service for mysql.error:0
2011-09-13 android 日期选择器(DatePicker)学习与应用 (转)