我正在尝试将数据文件上传到 WCF 服务,它适用于小文件。但是,当我尝试上传大小为 2MB 的文件时,我只会收到错误 400 Bad Request。
由于它适用于小文件,我不得不认为最大大小限制存在问题,但我已经增加了它们,我仍然得到同样的错误。
感谢您帮助我走向正确的方向。谢谢 :)
我在 WCF 服务中使用以下配置。
这是服务配置
<!-- WIZARD FILE UPLOAD CONFIGURATION -->
<service behaviorConfiguration="BBS.eBillity.Services.ServiceBehavior" name="BBS.eBillity.Services.Modules.IWizardUploadFile">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="WizardUploadFile_StreamedBinding"
contract="BBS.eBillity.Services.Contracts.ServicesContracts.IWizardUploadFile">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</service>
服务的绑定配置
<binding name="WizardUploadFile_StreamedBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"
transferMode="StreamedRequest" closeTimeout="04:01:00"
openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
</binding>
服务合同,很简单...
[ServiceContract]
public interface IWizardUploadFile
{
[OperationContract]
void UploadFiletoServer(Stream request);
}
在 system.web 标记内,我在客户端和服务器配置文件中添加了以下内容
<httpRuntime maxRequestLength="2147483647" />
这是客户端配置:
<basicHttpBinding>
<binding name="BasicHttpBinding_IWizardUploadFile" closeTimeout="04:01:00"
openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00"
allowCookies="false" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
transferMode="Streamed"
useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None"
proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
端点配置
<endpoint address="http://localhost:1234/WCFeBillity/WizardUploadFile.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWizardUploadFile"
contract="WizardUploadFile.IWizardUploadFile" name="BasicHttpBinding_IWizardUploadFile" />