WCF The remote server returned an error: (400) Bad Request
如果是小数据量调用WCF服务不会出现,但如果大量数据时会出现这个错误。花了几个小时的时间才知道WCF服务层也需要bindingConfiguration属性,修改服务层的web.config
web.config
==========
<services>
<service name="DocCube.BusinessLogic.DocumentManager"
behaviorConfiguration="HttpGetBehavior">
<endpoint binding="wsHttpBinding" bindingConfiguration="wsHttp"
contract="DocCube.Interfaces.IDocumentManager"
address=""/>
</service>
</services>
注意: 手动增加 "bindingConfiguration" 属性,VS平台不会自动生成这个属性,与bindingConfiguration关联的配置如下:
<bindings>
<wsHttpBinding>
<binding name="wsHttp" maxReceivedMessageSize ="9999999"
messageEncoding="Mtom" maxBufferPoolSize="9999999" >
<readerQuotas maxDepth="9999999"
maxArrayLength="9999999" maxBytesPerRead="9999999"
maxNameTableCharCount="9999999" maxStringContentLength="9999999"/>
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
然后,把客户端的App.config文件删除,重新获取服务层的服务引用,需要注意到是:客户端和服务端引用的绑定协议binding都需要相同,比如客户端的app.config引用的binding,maxReceivedMessageSize 值大小等于9999999,那么服务层也要有相同的配置,这个值也是9999999。
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步