上帝你不只是喜欢 WCF。
我阅读了所有可能的线程,但我现在真的被困住了。
这是WCF配置:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BaseHttp"
maxBufferSize="4194304"
maxBufferPoolSize="4194304"
maxReceivedMessageSize="4194304" />
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="TaskServiceBehavior">
<serviceMetadata httpGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="TaskServiceBehavior" name="TaskService">
<endpoint
address="http://www.mysite.com/TableTaskService/TableTaskService.svc"
binding="basicHttpBinding" bindingConfiguration="BaseHttp"
contract="TableTaskService.ITableTaskService" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://www.mysite.com/TableTaskService/" />
</baseAddresses>
</host>
</service>
</services>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://www.mysite.com/" />
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
</system.serviceModel>
现在我发送一条消息并抛出这个默认异常(在 svclog 文件中看到):
已超出传入邮件 (65536) 的最大邮件大小配额。要增加配额,请在适当的绑定元素上使用 MaxReceivedMessageSize 属性。
现在我明确指出它应该是 4mb。
我的客户代码:
TableTaskServiceClient client =
new TableTaskServiceClient(
new BasicHttpBinding { MaxBufferSize = 4194304,
MaxReceivedMessageSize = 4194304 },
new EndpointAddress(GetEndpointAddressString())
);
然而,它向我抛出了这个 65536 大小错误。是从哪里来的???
MaxReceivedMessageSize
客户端设置为与服务器相同的值真的很重要吗?我认为服务器负责确定长度而不是客户端是合乎逻辑的。
还有这个警告(注意它的用处有多大,即:没有关于被覆盖的元素的信息或者我错过了什么),也许 basichttpbinding 正是被覆盖的内容?但为什么会这样呢?反正:
[TraceRecord] 严重警告 TraceIdentifier http://msdn.microsoft.com/en-US/library/System.ServiceModel.OverridingDuplicateConfigurationKey.aspx 描述 配置系统在不同的配置范围内检测到重复键,并用更新的键覆盖价值。AppDomain /LM/W3SVC/11/ROOT/TableTaskService-33-1296567 源 System.ServiceModel.Configuration.ServiceBehaviorElementCollection/-851144413 ElementName 行为 OldElementLineNumber 0 NewElementLineNumber 0
UPDTE:重新配置服务和客户端:
TableTaskServiceClient client = new TableTaskServiceClient(
new BasicHttpBinding {
MaxBufferSize = 4194304,
MaxReceivedMessageSize = 4194304,
MaxBufferPoolSize=4194304,
ReaderQuotas = new XmlDictionaryReaderQuotas
{
MaxArrayLength = 4194304,
MaxBytesPerRead = 4194304,
MaxDepth = 4194304,
MaxNameTableCharCount = 4194304,
MaxStringContentLength = 4194304
}
}, new EndpointAddress(GetEndpointAddressString()));
还是一样的错误。
如果我对此感兴趣,我将发送一个 467000~ 长度的 byte[] 数组