c# - 实体太大错误

标签 c# wcf

我的服务有点问题。它不支持大量数据,我必须为它发送一个 base64 编码的图像。 服务配置是这样的:

[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "create", BodyStyle = WebMessageBodyStyle.Bare)]
WSResult<WebService.Model.Order> create(WSOrderCreateParams paramsData);

并且 web.config 具有以下配置:

<system.web>
    <compilation targetFramework="4.5" debug="true" />
    <httpRuntime targetFramework="4.5" maxRequestLength="1000000000"/>
<system.web>
...
<service.serviceModel>
...
  <webHttpBinding>
    <binding name="WebHttpEndpointBinding"
      maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
      transferMode="Buffered" useDefaultWebProxy="true">
      <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647"
        maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows"/>
      </security>
    </binding>
  </webHttpBinding>
...
</service.serviceModel>
...
<services>
  <service name="WebService.ws.Order">
    <endpoint address="" behaviorConfiguration="Web" binding="webHttpBinding" contract="WebService.ws.IOrder"/>
  </service>
</services>

谁能帮帮我?

最佳答案

我已经通过网络配置解决了它。这就是 Web.config 现在的样子:

<system.web>
  <compilation targetFramework="4.5" debug="true" />
  <httpRuntime targetFramework="4.5" maxRequestLength="1000000000"/>
<system.web>
    ...
<service.serviceModel>
  ...
  <webHttpBinding>
    <binding name="WebHttpEndpointBinding"
      maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
      transferMode="Buffered" useDefaultWebProxy="true">
      <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647"
        maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows"/>
      </security>
    </binding>
  </webHttpBinding>
  ...
</service.serviceModel>
    ...
<services>
  <service name="WebService.ws.Order">
    <endpoint address="" bindingConfiguration="WebHttpEndpointBinding" behaviorConfiguration="Web" binding="webHttpBinding" contract="WebService.ws.IOrder"/>
  </service>
</services>
...
<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="1073741824" />
    </requestFiltering>
  </security>
  <serverRuntime uploadReadAheadSize="2147483647" />
</system.webServer>

我已经在服务中添加了 bindingConfiguration,就像@kei 说的那样,并且

<serverRuntime uploadReadAheadSize="2147483647" /> 

在 system.webServer。 IIS 的默认池不允许您使用 uploadReadAheadSize,因此您必须继续:IIS 管理器 > 配置编辑器 > 部分:system.webServer/serverRuntime > 解锁部分。这样做,它应该工作:)

关于c# - 实体太大错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22971930/

相关文章:

c# - Installer工程多次打包文件

c# - 比较视频帧差异的良好图像处理算法是什么?

wcf - 使用 'add service reference' 生成的 App.config 中包含什么?

c# - Wcf数据服务投影及查询方法

.net 核心调用 wcf 服务 - SecurityAccessDeniedException : The security token could not be authenticated or authorized

c# - 迭代循环并在两个表达式之间切换,唯一的区别是符号

c# - ASP Core 2.1 电子邮件确认

wcf - 如何将 T (IEnumerable<T>) 数组转换为 IQueryable<T> 以便使用 LINQ 进行处理?

WCF net.tcp 绑定(bind)、消息格式和安全问题

c# - 如何隐藏 WPF 组合框中的选定项?