2014-10-07 78 views
1

我GOOGLE了很多关于这个问题。有很多解决方案,但没有为我工作。我试图使用WCF服务上传图片文件。小图像上传得很好,但一旦尺寸增加,就会发出错误。下面是我得到WCF服务错误,同时上传大图像 - 远程服务器返回意外的响应:(413)请求实体太大

the remote server returned an unexpected response: (413) request entity too large 

,并在这里的错误是我的web.config(我相信它的东西做的web.config文件)

<system.web> 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5" /> 
</system.web> 
<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
      <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text"> 
       <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
      </binding> 
     </basicHttpBinding> 
    </bindings> 
    <behaviors> 
     <endpointBehaviors> 
      <behavior name="web"> 
       <webHttp automaticFormatSelectionEnabled="true" /> 
      </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 

      <behavior> 
       <!-- To avoid disclosing metadata information, set the values below to false before deployment --> 
       <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
       <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
       <serviceDebug includeExceptionDetailInFaults="false" /> 

      </behavior> 

     </serviceBehaviors> 
    </behaviors> 
    <protocolMapping> 
     <add binding="basicHttpsBinding" scheme="https" /> 
    </protocolMapping> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"> 
     <serviceActivations> 
      <add factory="System.ServiceModel.Activation.WebServiceHostFactory" relativeAddress="WebService.svc" service="ChargeMe.Service.WebService"></add> 
     </serviceActivations> 

    </serviceHostingEnvironment> 
</system.serviceModel> 

服务合同:

[OperationContract] 
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] 
ResponseBase SaveAlertSettings(AlertSettingInfo alertSettingInfo); 

AlertSettingInfo.fileToUpload有base64string首先转换为流,然后作为图像文件写入服务器。它适用于小尺寸图像文件。针对较大文件(如4 MB图像文件)引发错误。

+0

你能告诉我们你的服务合同? – MickyD 2014-10-07 09:27:21

+0

@ User52784246已更新 – iJade 2014-10-07 09:31:31

+0

谢谢。所以,** SaveAlertSettings()**上传图片?也许显示我们** AlertSettingInfo **太请如此 – MickyD 2014-10-07 09:34:18

回答

0

绑定必须添加webHttpBinding

<webHttpBinding> 
    <binding name="webHttpBindingConfig" sendTimeout="05:00:00" hostNameComparisonMode="Exact" maxReceivedMessageSize="2147483647"></binding> 
    <binding name="webHttpsBindingConfig" sendTimeout="05:00:00" hostNameComparisonMode="Exact" maxReceivedMessageSize="2147483647"> 
     <security mode="Transport"> 
     <transport clientCredentialType="None" /> 
     </security> 
    </binding> 
    </webHttpBinding> 
+0

不起作用! – iJade 2014-10-07 09:49:20

+0

限制必须添加到服务和客户端配置。如果你的服务没有配置为处理大尺寸或者你无法控制它,那么你无法做任何事情。 http://stackoverflow.com/questions/16265725/wcf-error-the-maximum-message-size-quota-for-incoming-messages-65536-has-bee?answertab=active#tab-top – 2014-10-07 10:13:40

相关问题