我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圖像文件)引發錯誤。
你能告訴我們你的服務合同? – MickyD 2014-10-07 09:27:21
@ User52784246已更新 – iJade 2014-10-07 09:31:31
謝謝。所以,** SaveAlertSettings()**上傳圖片?也許顯示我們** AlertSettingInfo **太請如此 – MickyD 2014-10-07 09:34:18