0

我已经到处搜索并尝试了所有解决方案,但似乎没有什么对我有用。上传大于 64k 的图像时,我收到错误的 400 请求。它正在工作,然后突然停止工作。也无需更改代码或更改配置文件。还有什么可能影响配置文件设置?这是我的配置文件

<system.web>
    <customErrors mode="Off"/>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime maxRequestLength="2147483647"/>
  </system.web>
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="webHttpBehavior" name="EzFindWCFService.EZFindWebService">
        <endpoint address="" behaviorConfiguration="EzFindWCFService.EZFindWebServiceAspNetAjaxBehavior"
          binding="webHttpBinding" contract="EzFindWCFService.EZFindWebService" />
      </service>
    </services>
    <behaviors>



      <endpointBehaviors>
        <behavior name="EzFindWCFService.EZFindWebServiceAspNetAjaxBehavior">
          <!--<enableWebScript />-->
          <webHttp/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="webHttpBehavior">          
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>

      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />

    <bindings>
      <basicHttpBinding>
        <binding name="webHttpBinding" closeTimeout="00:10:00" openTimeout="00:10:00"
          receiveTimeout="00:10:00" sendTimeout="00:05:00" allowCookies="false"
          bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="64" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>

  </system.serviceModel>
4

1 回答 1

0

在 system.serviceModel/services/service 中,您将绑定设置为“webHttpBinding”,但您没有定义 bindingConfiguration。问题是您没有在 system.serviceModel/bindings 中设置 webHttpBinding。您设置了一个 basicHttpBinding 并将其名称设置为 webHttpBinding!所以实际上这个完整的绑定没有被使用,因为你的服务元素寻找一个默认的(因为你没有定义一个 bindingConfiguration)webHttpBinding 而不是一个名为 webHttpBinding 的 basicHttpBinding!这就是您上传大于 64k 的文件失败的原因。因为这将超过 64k 的默认配额。我希望你能理解我 :) 混合默认绑定名称很容易出错 ;)

更新:

这个 system.serviceModel-Section 应该可以工作:

<services>
  <service name="EzFindWCFService.EZFindWebService" 
           behaviorConfiguration="webHttpBehavior" >
    <endpoint address="" 
              binding="webHttpBinding" bindingConfiguration="ConfigWebHttp"
              behaviorConfiguration="EzFindWCFService.EZFindWebServiceAspNetAjaxBehavior"
              contract="EzFindWCFService.EZFindWebService" />
  </service>
</services>

<behaviors>
  <endpointBehaviors>
    <behavior name="EzFindWCFService.EZFindWebServiceAspNetAjaxBehavior">
      <!--<enableWebScript />-->
      <webHttp/>
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="webHttpBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<bindings>
  <webHttpBinding>
    <binding name="ConfigWebHttp"
             openTimeout="00:10:00" closeTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:05:00"
             maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" 
                    maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </webHttpBinding>
</bindings>

我遗漏了一些默认设置(例如绑定/安全),以使配置更苗条。还有一件事:我会小心地将所有这些配额设置为 Int32.MaxValue。测试可能没问题,但请记住在投入生产时设置这些值。

于 2013-04-20T21:25:08.950 回答