【问题标题】:WCF Issue: The remote server returned an error: (413) Request Entity Too LargeWCF 问题:远程服务器返回错误:(413)请求实体太大
【发布时间】:2015-03-21 06:52:10
【问题描述】:

我知道这个问题以前被问过很多次,但不幸的是,他们都没有解决我的问题。

我有一个 wcf Web 服务,我可以在其中以字节的形式发送文件。如果文件的大小很大(大约 400 KB),则会出现此错误。对于小型文件,这个问题不会出现。以下是我的服务器端点配置,

<service behaviorConfiguration="CPServicesBehaviour" name="ConsumerPortalAPI.ReceiveNoteService">
  <endpoint address="" binding="customBinding" bindingConfiguration="CustomBinding_IReceiveNoteService" contract="ConsumerPortalAPI.IReceiveNoteService" />
</service>

绑定配置是,

<binding name="CustomBinding_IReceiveNoteService" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
  <security defaultAlgorithmSuite="Default" authenticationMode="SecureConversation" requireDerivedKeys="false" includeTimestamp="false" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"
  canRenewSecurityContextToken="true">
    <secureConversationBootstrap defaultAlgorithmSuite="Default" authenticationMode="UserNameOverTransport" requireDerivedKeys="true" includeTimestamp="true" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
      <localClientSettings detectReplays="false" />
      <localServiceSettings detectReplays="false" />
    </secureConversationBootstrap>
    <localClientSettings detectReplays="false" />
    <localServiceSettings detectReplays="false" />
  </security>
  <binaryMessageEncoding>
    <readerQuotas maxDepth="32767" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="32767" maxNameTableCharCount="2147483647" />
  </binaryMessageEncoding>
  <httpsTransport />
</binding>

默认绑定是,

<binding maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
  <security defaultAlgorithmSuite="Default" authenticationMode="SecureConversation" requireDerivedKeys="false" includeTimestamp="false" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"
  canRenewSecurityContextToken="true">
    <secureConversationBootstrap defaultAlgorithmSuite="Default" authenticationMode="UserNameOverTransport" requireDerivedKeys="true" includeTimestamp="true" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
      <localClientSettings detectReplays="false" />
      <localServiceSettings detectReplays="false" />
    </secureConversationBootstrap>
    <localClientSettings detectReplays="false" />
    <localServiceSettings detectReplays="false" />
  </security>
  <binaryMessageEncoding>
    <readerQuotas maxDepth="32767" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="32767" maxNameTableCharCount="2147483647" />
  </binaryMessageEncoding>
  <httpsTransport />
</binding>

在我的测试客户端配置是,

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="CustomBinding_IReceiveNoteService" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
          <security defaultAlgorithmSuite="Default" authenticationMode="SecureConversation" requireDerivedKeys="false" includeTimestamp="false" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"
          canRenewSecurityContextToken="true">
            <secureConversationBootstrap defaultAlgorithmSuite="Default" authenticationMode="UserNameOverTransport" requireDerivedKeys="true" includeTimestamp="true" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
              <localClientSettings detectReplays="false" />
              <localServiceSettings detectReplays="false" />
            </secureConversationBootstrap>
            <localClientSettings detectReplays="false" />
            <localServiceSettings detectReplays="false" />
          </security>
          <binaryMessageEncoding />
          <httpsTransport />
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="https://cnsportal3.lineartitle.com/cnsAPI/v4/ReceiveNoteService.svc" binding="customBinding" bindingConfiguration="CustomBinding_IReceiveNoteService" contract="CPAction.IReceiveNoteService" name="CustomBinding_IReceiveNoteService" />
    </client>
  </system.serviceModel>
</configuration>

我尝试将我网站的 uploadReadAheadSize 增加到 10485759。 我还尝试将我的网站的 maxAllowedContentLength 增加到 3000000000。

我通过 system.diagnostics 检查了服务器上的 Web 跟踪。以下是跟踪中记录的 Xml 消息,

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
  <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
    <EventID>524326</EventID>
    <Type>3</Type>
    <SubType Name="Information">0</SubType>
    <Level>8</Level>
    <TimeCreated SystemTime="2015-01-21T11:01:33.3751197Z" />
    <Source Name="System.ServiceModel" />
    <Correlation ActivityID="{90d52ffb-d886-4164-9d84-e74c04eb79b4}" />
    <Execution ProcessName="w3wp" ProcessID="5916" ThreadID="16" />
    <Channel />
    <Computer>RES-DEV-WEB</Computer>
  </System>
  <ApplicationData>
    <TraceData>
      <DataItem>
        <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information">
          <TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.GetServiceElement.aspx</TraceIdentifier>
          <Description>Get ServiceElement.</Description>
          <AppDomain>/LM/W3SVC/5/ROOT/cnsAPI/v4-2-130663116927511157</AppDomain>
          <ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/ServiceConfigurationTraceRecord">
            <FoundServiceElement>True</FoundServiceElement>
            <ConfigurationFileSource>C:\inetpub\wwwroot\cnsportal3.lineartitle.com\ConsumerPortalAPI\v4\web.config</ConfigurationFileSource>
            <ConfigurationFileLineNumber>133</ConfigurationFileLineNumber>
            <ServiceConfigurationInformation>
              <ServiceName>ConsumerPortalAPI.ReceiveNoteService</ServiceName>
              <BehaviorConfiguration>CPServicesBehaviour</BehaviorConfiguration>
              <Host>
                <Timeouts>
                  <OpenTimeout>00:01:00</OpenTimeout>
                  <CloseTimeout>00:00:10</CloseTimeout>
                </Timeouts>
              </Host>
              <Endpoints>
                <Endpoint>
                  <Binding>customBinding</Binding>
                  <BindingConfiguration>CustomBinding_IReceiveNoteService</BindingConfiguration>
                  <Contract>ConsumerPortalAPI.IReceiveNoteService</Contract>
                  <ListenUriMode>Explicit</ListenUriMode>
                </Endpoint>
              </Endpoints>
            </ServiceConfigurationInformation>
          </ExtendedData>
        </TraceRecord>
      </DataItem>
    </TraceData>
  </ApplicationData>
</E2ETraceEvent>

这似乎可以得到正确的绑定配置,但不知道为什么不使用它。

附:所有绑定都在 customBinding 标签下定义。

在这方面的任何帮助将不胜感激。也许我在这里缺少一些非常小的东西,你们中的任何人都可以指出我正确的方向。

提前致谢。

【问题讨论】:

  • 这是您的客户端踢出的错误还是您的主机返回的错误?你有没有试过把它连接到 Fiddler 看看里面到底发生了什么?您是否尝试过错误记录?
  • 问题来自服务器端。通过跟踪日志,我可以看到我的服务器没有收到该消息。
  • 好吧,您已经为所有配置设置了最大限制。所以,问题不在于限制。不知何故,正在使用默认配置 (65Kb)。我的第一个猜测,请确保您设置完整的合格服务名称,即
  • 感谢 Husnain 的回复。我检查了标记文件和服务名称,似乎是正确的。 ConsumerPortalAPI.ReceiveNoteService 和配置文件一样。

标签: wcf


【解决方案1】:

我能够通过在绑定配置中添加以下行来解决此问题。

&lt;httpsTransport maxReceivedMessageSize="2147483647"/&gt;

整个绑定配置现在看起来像,

<binding name="CustomBinding_IReceiveNoteService" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
		   <security defaultAlgorithmSuite="Default" authenticationMode="SecureConversation" requireDerivedKeys="false" includeTimestamp="false" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" canRenewSecurityContextToken="true">
            <secureConversationBootstrap defaultAlgorithmSuite="Default" authenticationMode="UserNameOverTransport" requireDerivedKeys="true" includeTimestamp="true" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
              <localClientSettings detectReplays="false" />
              <localServiceSettings detectReplays="false" />
            </secureConversationBootstrap>
            <localClientSettings detectReplays="false" />
            <localServiceSettings detectReplays="false" />
          </security>
          <binaryMessageEncoding>
            <readerQuotas maxDepth="32767" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="32767" maxNameTableCharCount="2147483647" />
          </binaryMessageEncoding>
          <httpsTransport maxReceivedMessageSize="2147483647"/>
	    </binding>

【讨论】:

    猜你喜欢
    • 2016-06-10
    • 1970-01-01
    • 2014-07-23
    • 2021-10-08
    • 1970-01-01
    • 1970-01-01
    • 2021-02-22
    • 2015-10-18
    • 1970-01-01
    相关资源
    最近更新 更多