我的设置:
- 托管在 IIS Express 中的 ASP.NET 客户端
- 控制台应用程序中托管的 WCF 服务
- 在管理模式下运行 Visual Studio.NET 2012
我试图从 WCF 服务返回 2 个 List 对象。当我只返回 1 个 List 对象时,我的设置工作正常。但是当我返回 2 个 List 对象时,我收到错误:
已超出传入消息的最大消息大小配额 (65536)。要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性。
我知道这个问题已经在这个网站和其他网站上被问过很多次了。我已经尝试了互联网上发布的几乎所有内容以及配置文件的各种组合,但这对我来说仍然没有成功。
客户端配置:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxRequestLength="1572864"/>
</system.web>
<system.serviceModel>
<client>
<endpoint name="basicHttpBinding"
address="http://localhost:9502/HCDataService"
binding="basicHttpBinding"
bindingConfiguration="basicHttpBinding"
contract="HC.APP.Common.ServiceContract.IHCServiceContract"
behaviorConfiguration="ServiceBehaviour">
</endpoint>
</client>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483646" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="ServiceBehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
服务器配置:
<configuration>
<system.serviceModel>
<services>
<service name="HC.APP.Server.Service.HCDataService" behaviorConfiguration="ServiceBehaviour">
<host>
<baseAddresses>
<add baseAddress="http://localhost:9502/HCDataService"/>
</baseAddresses>
</host>
<endpoint name="basicHttpBinding"
address="http://localhost:9502/HCDataService"
binding="basicHttpBinding"
bindingConfiguration="basicHttpBinding"
contract="HC.APP.Common.ServiceContract.IHCServiceContract">
</endpoint>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" closeTimeout="01:50:00" openTimeout="01:50:00" sendTimeout="01:50:00" receiveTimeout="01:50:00" >
<readerQuotas maxDepth="128" maxStringContentLength="8388608" maxArrayLength="2147483646" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
<dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
那是因为您没有在服务器上指定要使用的绑定。让我们看一下您的服务器配置:
Under <bindings>
您正在创建绑定配置<basicHttpBinding>
,并且你正在命名它name="basicHttpBinding"
。另外,您的端点名称是<endpoint name="basicHttpBinding" ...>
它的绑定是binding="basicHttpBinding"
. However,它不是指你的绑定配置,但对于绑定type。所以,它实际上使用的是默认设置basicHttpBinding
.
要解决此问题,首先以不同的方式命名您的端点和绑定配置。例如,<endpoint name="basicEndpoint" ... >
and <binding name="myBasicBinding" ... >
。然后,您需要使用此属性将绑定配置分配给端点:bindingConfiguration="myBasicBinding"
.
这是客户端配置:
<system.web>
<httpRuntime maxRequestLength="32768"/>
</system.web>
<system.serviceModel>
<client>
<endpoint name="basicEndpoint"
address="http://localhost:9502/HCDataService"
binding="basicHttpBinding"
bindingConfiguration="myBasicBinding"
contract="HC.APP.Common.ServiceContract.IHCServiceContract"
behaviorConfiguration="ServiceBehaviour">
</endpoint>
</client>
<bindings>
<basicHttpBinding>
<binding name="myBasicBinding" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="ServiceBehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
这是服务器配置:
<system.serviceModel>
<services>
<service name="HC.APP.Server.Service.HCDataService" behaviorConfiguration="ServiceBehaviour">
<host>
<baseAddresses>
<add baseAddress="http://localhost:9502/HCDataService"/>
</baseAddresses>
</host>
<endpoint name="basicEndpoint"
address="http://localhost:9502/HCDataService"
binding="basicHttpBinding"
bindingConfiguration="myBasicBinding"
contract="HC.APP.Common.ServiceContract.IHCServiceContract">
</endpoint>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="myBasicBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" closeTimeout="01:50:00" openTimeout="01:50:00" sendTimeout="01:50:00" receiveTimeout="01:50:00" >
<readerQuotas maxDepth="128" maxStringContentLength="8388608" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
<dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
别忘了update service reference
在您的客户端上获取正确的配置。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)