例外:WCF服务在将图像作为字节数组保存到数据库时抛出Bad Request

时间:2013-01-25 13:46:25

标签: .net wcf exception

我创建了一个WCF服务,用于将图像保存为字节数组。以下是合同,实施和要点详情

合同

  [OperationContract]
        void InsertEmployeeData(EmployeeDetail empName);

实施

 public void InsertEmployeeData(EmployeeDetail empName)
        {
            ctx.EmployeeDetails.AddObject(empName);
            ctx.SaveChanges();
        }

当我尝试保存低于15 kb时,我可以成功保存。当上传超过15 kb时,我得到异常远程服务器返回了意外响应:(400)错误请求我该如何解决这个问题错误?

绑定详情

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_ImobService" closeTimeout="00:10:00"
          openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
          maxBufferSize="250000000" maxBufferPoolSize="250000000" maxReceivedMessageSize="250000000">
          <readerQuotas maxDepth="4500000" maxStringContentLength="4500000"
            maxArrayLength="4500000" maxBytesPerRead="40960000" maxNameTableCharCount="250000000" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://anishk.india-powai.orioninc.com/mobservice/MobService.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ImobService"
        contract="MobileService.ImobService" name="BasicHttpBinding_ImobService" />
    </client>
  </system.serviceModel>

1 个答案:

答案 0 :(得分:0)

如果您在IIS上托管服务,那么请求长度限制为15 kb是一个很好的变化。尝试更改IIS设置

<httpRuntime maxRequestLength="25000" /> 

将请求长度更改为最大值。您要上传的文件大小。