【问题标题】:WCF service application does not accept my bindingsWCF 服务应用程序不接受我的绑定
【发布时间】:2016-06-22 06:52:25
【问题描述】:

WCF 服务应用程序配置为仅接受有限数量和大小的数据;我们需要撤销这个限制。我一直在尝试使用绑定,并且在 StackOverflow 上阅读了很多线程以及其他资源。

但是,当我发送大数据时,Web 服务似乎仍然不接受我的绑定并返回 Error 413 request entity to large。老实说,我对 WCF 服务的经验很少,所以我的错误一定是微不足道的。但几个小时后,我似乎不知道它是什么。

另外,我不确定在 WCF web.config 中定义什么以及在桌面应用程序 app.config 中定义什么,所以也许我对此也有误。

目前,WCF 服务在 localhost (Visual Studio 2013) 上运行。


WPF 客户端应用程序 app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed">
                    <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                </binding>
            </basicHttpBinding>
            <netTcpBinding>
                <binding receiveTimeout="01:00:00" sendTimeout="01:00:00">
                    <security mode="None" />
                </binding>
            </netTcpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:52911/Service.svc" binding="basicHttpBinding" contract="MyWebService.IService" bindingConfiguration="BasicHttpBinding_IService" name="BasicHttpBinding_IService" />
        </client>
    </system.serviceModel>
</configuration>

WCF 服务应用程序 Web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </configSections>
    <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    </appSettings>
    <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" />
    </system.web>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior>
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <protocolMapping>
            <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
        <directoryBrowse enabled="true" />
    </system.webServer>
    <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
            <parameters>
                <parameter value="v11.0" />
            </parameters>
        </defaultConnectionFactory>
        <providers>
            <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
    </entityFramework>
    <connectionStrings>
        <add name="Entities" connectionString="[...]" />
    </connectionStrings>
</configuration>

【问题讨论】:

  • 尝试启用请求实体的流式传输
  • 我试过了(有问题的代码已更新),现在我收到了 400 错误请求。另外我仍然不确定哪个配置文件属于哪个配置文件,因为 WPF 应用程序的 app.config 似乎被完全覆盖了。
  • @bytecode77,在客户端, 配置部分没用,因为你没有 netTcp 端点

标签: c# .net wcf wcf-binding


【解决方案1】:

在服务器上,您应该配置 basicHttpsBinding 和/或 basicHttpBinding 以更改大小。

&lt;system.serviceModel&gt; 下,您应该添加如下内容:

<bindings>
  <basicHttpBinding>
    <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed">
        <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </basicHttpBinding>
  <basicHttpsBinding>
    <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed">
        <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </basicHttpsBinding>
</bindings>

注意: 绑定配置没有名称属性,因此它适用于同一类的每个绑定实例。

问候

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-30
    • 2011-10-10
    • 1970-01-01
    • 1970-01-01
    • 2014-02-03
    • 1970-01-01
    相关资源
    最近更新 更多