代码之家  ›  专栏  ›  技术社区  ›  nnmmss

远程服务器返回了意外响应:(413)wsHttpBinding中的请求实体太大

  •  0
  • nnmmss  · 技术社区  · 4 年前

    我正在编写一个使用服务器端服务的应用程序。我正试图将一个50KB的Word文件保存到sql server中。当我在web中使用这样的wsHttpBinding时。服务配置:

     <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <bindings>
      <wsHttpBinding>       
        <binding name="BasicHttpBinding_IECartService"
             maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" ></binding>
      </wsHttpBinding>      
    </bindings>   
    </system.serviceModel>
    

    将出现错误消息:“远程服务器返回意外响应:(413)请求实体太大”

    但是当我在service的web.config中使用basicHttpBinding时:

     <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IECartService" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>      
    </bindings>       
    </system.serviceModel>
    

    这位于客户端的app.config中

     <system.serviceModel>
     <bindings>
      <basicHttpBinding>        
    
        <binding name="BasicHttpBinding_IECartService"
                         maxBufferSize="2097152"
                         maxBufferPoolSize="2097152"
                         maxReceivedMessageSize="2097152"
                         closeTimeout="00:50:00"
                         openTimeout="00:50:00"
                         sendTimeout="00:50:00"
                         receiveTimeout="00:50:00" >
          <readerQuotas maxDepth="32" maxStringContentLength="100000"
                        maxArrayLength="2097152" maxBytesPerRead="4096"
                        maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    
    
    <client>
      <endpoint address="http://localhost:1085/ECartService.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IECartService"
        contract="ECartServiceReference.IECartService" name="BasicHttpBinding_IECartService" />
    </client>
    </system.serviceModel>
    

    该文件可以通过以下服务保存到Sql:

    我如何追踪错误?

    0 回复  |  直到 4 年前
        1
  •  0
  •   Ding Peng    4 年前

    WCF跟踪是在System上构建的。诊断。要使用跟踪,您应该在配置文件或代码中定义跟踪源。

    您可以通过编辑应用程序的配置文件来配置跟踪:

    <configuration>  
       <system.diagnostics>  
          <sources>  
             <source name="System.ServiceModel"
                        switchValue="Information, ActivityTracing"  
                        propagateActivity="true">  
                <listeners>  
                   <add name="traceListener"
                       type="System.Diagnostics.XmlWriterTraceListener"
                       initializeData= "c:\log\Traces.svclog" />  
                </listeners>  
             </source>  
          </sources>  
       </system.diagnostics>  
    </configuration> 
    

    有关配置跟踪的更多详细信息,请参阅下面的链接:

    https://learn.microsoft.com/en-us/dotnet/framework/wcf/diagnostics/tracing/configuring-tracing

    我还发现了一个与你遇到的问题类似的问题:

    https://learn.microsoft.com/en-us/archive/blogs/dsnotes/large-file-upload-failure-for-web-application-calling-wcf-service-413-request-entity-too-large