2014-10-07 49 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

相關問題