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

时间:2016-06-22 06:52:26

标签: c# .net wcf wcf-binding

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

然而,当我发送大数据时,Web服务似乎仍然无法接受我的绑定并将错误413请求实体返回到大。老实说,我对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>

1 个答案:

答案 0 :(得分:1)

在服务器上,您应配置basicHttpsBinding和/或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>

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

此致