简体   繁体   中英

The remote server returned an unexpected response: (413) Request Entity too Large in wsHttpBinding

I am programming an application which uses the Service on server Side. I am trying to save a Word File with 50KB into to sql server. When I use the wsHttpBinding like this in web.Config of a service:

 <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>

there will be a error message: "The remote server returned an unexpected response: (413) Request Entity too Large"

but when I use the basicHttpBinding in web.config of service:

 <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>

and this is in app.config on client side

 <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>

The file could be saved to the Sql through the service:

How can I trace error?

WCF tracking is built on System.Diagnostics. To use tracking, you should define the tracking source in a configuration file or code.

You can configure tracking by editing the application's configuration file:

<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> 

For more detailed information about configuration tracking, you can refer to the link below:

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

I also found a problem similar to the one you encountered:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM