2014-05-17 166 views
1

我正在开发一个项目。该网站建立在MVC http://www.example.com上,最近,另一位开发人员在该项目中添加了一个windows web服务(不是WCF),该项目为http://www.example.com/WebServices/upload.asmx。它应该用于将图像上传到服务器。路由被添加到RouteConfig,所以它的工作原理:System.ServiceModel.ProtocolException:远程服务器返回意外响应:(413)请求实体太大

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

但是,我注意到它适用于小尺寸文件。当文件大小达到某一点时,即> 1MB(不确定确切的#,但650KB文件工作和1.1MB文件失败)。错误信息是:

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: 

我搜索了2天,我找到的所有解决方案都无法工作。现在,在网站上,在web.config中,我有:

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

我们使用桌面应用程序来使用Web服务。在App.config,我有:

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

奇怪的是:600KB文件的工作,但如果文件大小> 1MB,它有这个错误。但是,从这些配置无处可以找到与这些数字的任何关系。

任何人都知道问题是什么?有什么建议么?是否因为MVC中的路由?

感谢

+0

入住这http://stackoverflow.com/questions/8225736/transfer-large-amount-of-data-in-wcf-service – malkam

回答

0

基于搜索结果多次尝试后,由于种种原因,它永远不会成功。最大上传文件总是大约600KB,不知道这个#从哪里来。我怀疑这是因为我在MVC项目中使用传统的asmx web服务。

在结束时,我决定这样做:

  1. 从客户端,分割文件到“帧”,它是512KB。
  2. 使用web服务将框架传递给服务器。
  3. 服务器决定是否需要将文件保存到文件系统(即文件大小< 512KB,那么它只有1帧),或者保存到数据库并等待 下一帧。每个帧保存到SQL与GUID和帧#和 总#。
  4. 如果收到最后一帧,则从sql 加载帧并合并它们,然后执行其他处理。

它不是要做到这一点的最好办法,但至少它的工作原理。我们可以选择选择框架大小。

感谢

+0

嗨,你怎么确定在C# – zeetit

+0

的512KB帧在我们的环境中,最大上传文件大小约为600KB。我选择512KB只是因为它是2^8 KB,没有任何特殊原因。 – urlreader

相关问题