我搜索了很多关于这个问题的信息。有很多解决方案,但没有一个适合我。我尝试使用WCF服务上传图像文件。小图像上传得很好但是一旦尺寸增加就会发出错误。这是我得到的错误
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 :(得分: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>