WCF:远程服务器返回错误:(413)请求实体太大

时间:2014-06-03 07:35:23

标签: c# asp.net web-services wcf web-config

我有一个wcf服务

有一种方法可以获取base64字符串来上传文件我的文件大小为100kb,它可能会更大

我收到错误消息:远程服务器返回错误:(413)请求实体太大 同时尝试获取HttpWebResponse

这是我的wcf服务web.config

<system.serviceModel>
<bindings>

  <webHttpBinding>

    <binding name="webHttpTransportSecurity" allowCookies="false" maxReceivedMessageSize="104857600">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
       maxBytesPerRead="2147483647" />
      <security mode="Transport">
        <transport clientCredentialType="None" />
      </security>
    </binding>
  </webHttpBinding>
</bindings>
<services>
  <service name="FHServices.FHSmartService" behaviorConfiguration="ServiceBehaviour">

    <endpoint address="" binding="webHttpBinding" contract="FieldHoundServices.IFHSmartService" behaviorConfiguration="web">
    </endpoint>
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost/FHServices/FHSmartService.svc/" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehaviour">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>
 <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>

我的错误是什么?


解决

我发现了自己的错误 我删除这些代码

<security mode="Transport">
    <transport clientCredentialType="None" />
  </security>

我认为https的传输模式,我们没有ssl所以我们不需要传输模式。无论如何,我删除它后,现在一切似乎都好了

1 个答案:

答案 0 :(得分:1)

您没有为端点分配定义的WebHttpBinding配置,因此端点使用绑定的默认值。

您可以通过在bindingConfiguration元素的<endpoint>属性中指定绑定配置来告知端点使用绑定配置,如下所示:

<endpoint address="" binding="webHttpBinding"
          bindingConfiguration="webHttpTransportSecurity"
          contract="FieldHoundServices.IFHSmartService" 
          behaviorConfiguration="web">
</endpoint>