我有以下wcf服务方法,它接受Attachment对象,Attachment类定义是:
[DataContract]
public class Attachment
{
[DataMember]
public int AttachmentId { get; set; }
[DataMember]
public String DMSFileId { get; set; }
[DataMember]
public String FileName { get; set; }
[DataMember]
public int? FileSize { get; set; }
[DataMember]
public String FileSource { get; set; }
[DataMember]
public byte[] File { get; set; }
}
方法定义是:
[OperationContract]
public int AddAttachment(DataTypes.Administration.Attachment attachment)
{
return AttachmentBusinessLogic.AddAttachment(attachment);
}
调用该方法时,我得到以下异常: 远程服务器返回意外响应:(413)请求实体太大
谷歌搜索错误我遇到了许多绑定配置,但没有一个工作不是maxReceivedMessageSize和readerQuotas。
以下是服务和客户端的Web配置:
服务
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
客户端
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<behaviors>
<endpointBehaviors>
<behavior name="AdministrationBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IAdministrationService" sendTimeout="00:05:00"
openTimeout="00:05:00"
receiveTimeout="00:05:00"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647">
<readerQuotas maxArrayLength="2147483647"
maxStringContentLength="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8001/AdministrationService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAdministrationService" contract="AdministrationService.IAdministrationService" name="BasicHttpBinding_IAdministrationService" behaviorConfiguration="AdministrationBehavior" />
</client>
</system.serviceModel>
有关如何克服此异常的任何建议请。
答案 0 :(得分:0)
您需要处理的地方是Web配置,您需要添加服务行为,您可以在其中设置数据大小。例如,像这样,
</serviceBehaviors>
<endpointBehaviors>
<behavior name="SilverlightWCFLargeDataApplication">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
如果不起作用,请在此处发布您的网络配置。希望它有所帮助。
答案 1 :(得分:0)
我设法通过按照在另一篇文章中配置wcf web配置文件的步骤来解决它。
答案 2 :(得分:0)
使用此设置
<basicHttpBinding>
<binding maxReceivedMessageSize="2147483647" messageEncoding="Text" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" >
<readerQuotas maxStringContentLength="525288"></readerQuotas>
</binding>
</basicHttpBinding>