【问题标题】:WCF Service Exception The remote server returned an unexpected response: (413) Request Entity Too LargeWCF 服务异常远程服务器返回意外响应:(413)请求实体太大
【发布时间】:2013-01-13 07:47:38
【问题描述】:

我有以下 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) Request Entity Too Large

谷歌搜索我遇到了许多绑定配置的错误,但没有一个有效,不是 maxReceivedMessageSize 也不是 readerQuotas。

这是服务和客户端的网络配置:

服务

<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>

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

【问题讨论】:

  • 如果服务托管在 IIS 中,那么您也有 IIS 的限制。
  • 是的,服务托管在 IIS 中,请问我该如何配置

标签: asp.net wcf .net-4.0


【解决方案1】:

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

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

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

【讨论】:

  • 谢谢,我已经尝试过这个配置,但它不起作用,也许我错过了一些我更新了帖子并添加了网络配置的东西。感谢您的帮助。
  • 发布您的服务 web.config
  • 我已经这样做了,我发布了服务的 Web 配置,标题为 Service。
  • 这是什么?这就是您的网络配置中的全部内容吗?服务配置和端点配置在哪里?
  • 这就是我在服务 web 配置中的全部内容,我创建了一个新的 web 应用程序并添加了新服务,除了我在帖子中提供的内容之外,什么都没有,我应该手动添加配置吗?跨度>
【解决方案2】:

我按照另一篇文章中配置 wcf web config 文件的步骤设法解决了这个问题。

configuring WCF wtih tag

【讨论】:

    【解决方案3】:

    使用此设置

     <basicHttpBinding>
            <binding maxReceivedMessageSize="2147483647"  messageEncoding="Text" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" >
              <readerQuotas  maxStringContentLength="525288"></readerQuotas>
            </binding>
          </basicHttpBinding>
    

    【讨论】:

      猜你喜欢
      • 2014-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多