1

貌似这个问题已经被问过千百次了,但是每个人的配置问题都不一样。我有提供图像并接收上传图像请求的 WCF 服务器。上传图片时,当大小超过 65k 时出现错误 400。

我在 WCF 上打开了跟踪,我得到了确切的错误

已超出传入邮件 (65536) 的最大邮件大小配额。要增加配额,请在适当的绑定元素上使用 MaxReceivedMessageSize 属性。

我知道我需要增加这个参数,但我只能在我的 web.config 文件中找到它应该在哪里。这是我在 web.config 中的内容:

  <system.serviceModel>
    <protocolMapping>
      <add binding="webHttpBinding" scheme="http" />
    </protocolMapping>
    <services>
      <service behaviorConfiguration="ReportTransferServiceBehavior" name="ReportTransferService">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="ReportTransferService" contract="IReportTransferService"></endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
        <behavior name="ReportTransferServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" maxConcurrentInstances="500" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior>
          <webHttp helpEnabled="true" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <domainServices>
      <endpoints>
        <add name="json" type="Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
            maxReceivedMessageSize="2000000" />
      </endpoints>
    </domainServices>
    <bindings>
      <basicHttpBinding>
        <binding name="ReportTransferService" maxReceivedMessageSize="2000000" maxBufferSize="2000000" transferMode="Streamed">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2000000" maxArrayLength="2000000" maxBytesPerRead="2000000" maxNameTableCharCount="2000000" />
          <security mode="None"></security>
        </binding>
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>

The URL I'm sending images (HTTP POST) is hostname/ReportTransferService.svc/UploadImage. Looks like it's using some kind of default binding and not basicHttpBinding configured for bigger size.

Anyone can tell me what's wrong with my web.config?

Update: Resolved

I had to specify fully qualified name for ReportTransferService in service configuration and serviceBehavior configuration and added whole new webHttpBinding section with similiar limits and pointed service to use this binding.

Thanks for your help.

4

1 回答 1

1

Your service section should have fully qualified names as shown below:

     <services>
      <service behaviorConfiguration="ReportTransferServiceBehavior" name="namespace.ReportTransferService">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="ReportTransferService" contract="namespace.IReportTransferService"></endpoint>
      </service>
    </services>
于 2012-06-15T16:24:01.090 回答