WCF 服务应用程序不接受我的绑定

WCF service application does not accept my bindings

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

但是,Web 服务似乎仍然不接受我的绑定,当我发送大数据时,returns 错误 413 请求实体变大。老实说,我对 WCF 服务的经验很少,所以我的错误一定是微不足道的。但是几个小时后,我似乎不知道它是什么。

此外,我不太确定在 WCF 中定义什么 web.config 以及桌面应用程序中属于什么 app.config,所以也许我也错了。

当前,WCF 服务在本地主机上 运行(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>

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

<system.serviceModel> 下,您应该添加如下内容:

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

: 绑定配置没有名称属性,因此它适用于相同 class.

的每个绑定实例

此致