我在IIS托管的WCF服务上使用NetMessagingBinding来使用在Windows Server Service Bus主题上发布的消息。
根据我的理解,对于Windows Server Service Bus的主题,邮件大小没有限制,但是我收到了从订阅反序列化邮件的错误:
System.ServiceModel.Dispatcher.NetDispatcherFaultException: (...)
The maximum string content length quota (8192) has been exceeded while reading XML data.
This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader.'.
Please see InnerException for more details. ---> System.Runtime.Serialization.SerializationException: There was an error deserializing the object of type [Type].
The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. ---> System.Xml.XmlException:
The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader.
我看到它的方式没有配置,我可以在WCF的web.config中更改以更改最大字符串内容。唯一可以关联的属性是MaxBufferPoolSize,但它不是通过web.config公开的。
使用的绑定配置是:
<bindings>
<netMessagingBinding>
<binding name="messagingBinding"
closeTimeout="00:03:00" openTimeout="00:03:00"
receiveTimeout="00:03:00" sendTimeout="00:03:00"
prefetchCount="-1" sessionIdleTimeout="00:01:00">
<transportSettings batchFlushInterval="00:00:01" />
</binding>
</netMessagingBinding>
</bindings>
提前致谢,
Joao Carlos de Sousa
答案 0 :(得分:1)
使用netMessagingTransport的自定义绑定也可以解决此问题。这样,readerQuotas节点可用于定义阅读器配额。
<customBinding>
<binding name="sbBindingConfiguration" sendTimeout="00:01:00" receiveTimeout="00:01:00" openTimeout="00:01:00">
<binaryMessageEncoding>
<readerQuotas maxDepth="100000000" maxStringContentLength="100000000"
maxArrayLength="100000000" maxBytesPerRead="100000000" maxNameTableCharCount="100000000"/>
</binaryMessageEncoding>
<netMessagingTransport manualAddressing="false" maxBufferPoolSize="100000" maxReceivedMessageSize="100000000">
<transportSettings batchFlushInterval="00:00:00"/>
</netMessagingTransport>
</binding>
</customBinding>
有关如何使用自定义绑定的更多详细信息,请参阅此post。
答案 1 :(得分:0)
从错误中看,这似乎是WCF级错误而不是Service Bus。你试过提高MaxMessageSize吗? This thread有关于它的信息,但基本上,您需要在web.config中的绑定配置上设置类似以下内容:
<binding name="yourBinding"
maxReceivedMessageSize="10000000"
maxBufferSize="10000000"
maxBufferPoolSize="10000000">
<readerQuotas maxDepth="32"
maxArrayLength="100000000"
maxStringContentLength="100000000"/>
</binding>
答案 2 :(得分:0)
NetMessagingBinding目前不允许通过XML配置更改MaxStringContentLenght。
对我有用的解决方案是通过实现IDispatchMessageFormatter接口来创建消息格式化程序行为扩展。
然后可以通过以下方式使用扩展名:
创建一个可在代码中使用的属性,以识别哪些操作合同将使用消息格式化程序行为
public class MessageFormatterExtensionBehaviorAttribute :
Attribute, IOperationBehavior
{
(...)
public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
{
dispatchOperation.Formatter = new MessageFormatterExtension();
}
(...)
}
创建一个公开自定义行为的configuration element。