1

我有以下 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>

请提供有关如何克服此异常的任何建议。

4

3 回答 3

0

您需要处理的地方是web config,您需要添加可以设置数据大小的服务行为。比如像这样,

  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="SilverlightWCFLargeDataApplication">
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
  </endpointBehaviors>
</behaviors>

如果这不起作用,请在此处发布您的网络配置。希望对您有所帮助。

于 2013-01-14T03:11:49.307 回答
0

我设法通过按照在另一篇文章中配置 wcf Web 配置文件的步骤来解决它。

使用标签配置 WCF

于 2013-01-14T15:06:04.440 回答
0

使用此设置

 <basicHttpBinding>
        <binding maxReceivedMessageSize="2147483647"  messageEncoding="Text" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" >
          <readerQuotas  maxStringContentLength="525288"></readerQuotas>
        </binding>
      </basicHttpBinding>
于 2013-11-06T11:25:11.750 回答