【问题标题】:413 Request Entity Too Large error- WCF Service413 请求实体太大错误 - WCF 服务
【发布时间】:2015-10-18 18:38:25
【问题描述】:

我有一个 wcf 服务,当我把请求消息放入大数据时(我有一个请求包括 base64 字符串,这个请求是一个长文本)
我收到此错误“413 请求实体太大”。
帮我调用此服务。
这是我的 wcf 配置

<?xml version="1.0"?>

<system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <httpRuntime maxRequestLength="2097150"/>
</system.web>
<system.serviceModel>
    <services>
        <service behaviorConfiguration="ServiceBehaviour" name="ApiFrame.ApiFrame">
            <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding"
             contract="ApiFrame.IApiframe" />
            <endpoint address="soap" binding="basicHttpBinding" contract="ApiFrame.IApiframe" />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="ServiceBehaviour">
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled="true"/>
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
            <behavior name="jsonBehavior">
                <enableWebScript/>
                <!-- use JSON serialization -->
            </behavior>
            <behavior name="xmlBehavior">
                <webHttp/>
                <!-- use XML serialization -->
            </behavior>
            <behavior name="web">
                <webHttp/>
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <!--<serviceHostingEnvironment multipleSiteBindingsEnabled="false"/>-->
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="ServiceSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
                receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
        <webHttpBinding>
            <binding
              maxBufferPoolSize="2147483647"
              maxReceivedMessageSize="2147483647"
              maxBufferSize="2147483647" transferMode="Streamed">
            </binding>
        </webHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://10.16.8.54/T24WebServices/Service.asmx"
            binding="basicHttpBinding" bindingConfiguration="ServiceSoap"
            contract="ConnectT24_54.ServiceSoap" name="ServiceSoap" />
    </client>
</system.serviceModel>

这是我的客户端应用程序配置:

<?xml version="1.0"?>

<connectionStrings>
    <add name="ApplicationServices"
         connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
         providerName="System.Data.SqlClient" />
</connectionStrings>

<system.web>
    <compilation debug="true" targetFramework="4.0" />

    <httpRuntime requestValidationMode="2.0" maxRequestLength="2147483647"/>

    <pages validateRequest="false">
    </pages>
    <authentication mode="Forms">
        <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </authentication>

    <membership>
        <providers>
            <clear/>
            <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
                 enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
                 maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
                 applicationName="/" />
        </providers>
    </membership>

    <profile>
        <providers>
            <clear/>
            <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
        </providers>
    </profile>

    <roleManager enabled="false">
        <providers>
            <clear/>
            <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
            <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
        </providers>
    </roleManager>

</system.web>

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.serviceModel>

    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IApiframe" closeTimeout="00:01:00" openTimeout="00:01:00"
            receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
            bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
            messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
            useDefaultWebProxy="true">
                <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

            </binding>
        </basicHttpBinding>

    </bindings>
    <client>
        <endpoint address="http://localhost:10832/ApiFrame.svc/soap"
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IApiframe"
          contract="ApiServices.IApiframe" name="BasicHttpBinding_IApiframe" />
    </client>
</system.serviceModel>

【问题讨论】:

  • 您是否尝试更新客户端和服务器配置文件中的“maxReceivedMessageSize”设置?客户端是向 WCF 发出请求的应用程序,服务器是您的服务配置文件。
  • 是的,我在客户端和服务器配置文件中都更新了 maxReceivedMessageSize。我更新了我的问题,更新客户端配置文件

标签: .net web-services wcf


【解决方案1】:

您增加了绑定属性的大小,但您从未将该绑定分配到端点,因此 WCF 使用指定绑定的默认值。要解决此问题,请在服务配置中的 &lt;endpoint&gt; 元素上使用 bindingConfiguration 属性,如下所示:

<endpoint address="soap" 
          binding="basicHttpBinding" 
          bindingConfiguration="ServiceSoap"
          contract="ApiFrame.IApiframe" />

请注意,您的客户端配置已将指定的绑定分配给客户端端点。

【讨论】:

    猜你喜欢
    • 2014-01-06
    • 1970-01-01
    • 2016-09-08
    • 2020-02-05
    • 2012-11-14
    • 2015-05-03
    • 2016-06-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多