简体   繁体   中英

System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (413) Request Entity Too Large

I'm working on a project. The website was built on MVC, http://www.example.com , recently, another developer added a windows web service (not WCF) to the project, http://www.example.com/WebServices/upload.asmx . It is supposed to for uploading images to server. The Route is added to RouteConfig, so it works:

routes.IgnoreRoute("WebServices/*/{resource}.aspx/{*pathInfo}");

However, I noticed that it works for small size files. When the file size reaches certain point, ie > 1MB (not sure the exact #, but 650KB file works and 1.1MB file fails). The error message is:

System.ServiceModel.ProtocolException was caught
  HResult=-2146233087
  Message=The remote server returned an unexpected response: (413) Request Entity Too Large.
  Source=mscorlib
  StackTrace:
    Server stack trace: 
       at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding)
       at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at SyncDatabase.eyephoto.com.upload.UploadSoap.UploadImage(UploadImageRequest request)
       ....
  InnerException: System.Net.WebException
       HResult=-2146233079
       Message=The remote server returned an error: (413) Request Entity Too Large.
       Source=System
       StackTrace:
            at System.Net.HttpWebRequest.GetResponse()
            at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       InnerException: 

I searched 2 days, all the solutions I could find did not work. Now, on the site, in web.config, I have:

<httpRuntime maxRequestLength="40960000" executionTimeout="300"  />
...

<system.serviceModel>
    <client />
    <bindings>
      <basicHttpBinding>
        <binding closeTimeout="00:10:00"
          openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
          maxReceivedMessageSize="2147483647"  >
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

        </binding>
      </basicHttpBinding>
    </bindings>
</system.serviceModel>

We use a desktop application to consume the web service. In the app.config, I have:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="UploadSoap1" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
          maxReceivedMessageSize="2147483647" closeTimeout="00:10:00"
          openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" >

          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

          <security mode="None" />
        </binding>        
      </basicHttpBinding>
    </bindings>

    <client>
      <endpoint address="http://www.example.com/WebServices/Upload.asmx"
        binding="basicHttpBinding" bindingConfiguration="UploadSoap1"
        contract="mysite.com.upload.UploadSoap" name="UploadSoap1" />
    </client>
 </system.serviceModel>

The weird thing is: 600KB file works, but if file size > 1MB, it has this error. BUT, nowhere from these configuration I can find any relation with these numbers.

Anyone knows what the problem is? Any suggestions? Could it because of route in MVC?

Thanks

after many tries based on search results, for some reasons, it never succeeded. The max upload file is always about 600KB, do not know where this # come from. I suspects it is because I use traditional asmx web service in MVC project.

At the end, I decided to do this:

  1. from client end, split the file into 'frame', which is 512KB.
  2. use the web service to pass the frame to server.
  3. server decides whether it needs save the file to file system (ie file size < 512KB, then it only has 1 frame), or, save to database and wait for next frame. each frame save to sql with a guid and frame #, and total #.
  4. if the last frame received, then load frames from sql and combine them, then do other processing.

it is not the best way to do this, but at least it works. and we can optionally to choose the frame size.

thanks

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