【问题标题】:Service Bus Topics and Incoming Messages服务总线主题和传入消息
【发布时间】:2013-06-04 14:50:00
【问题描述】:

我在 IIS 托管的 WCF 服务上使用 NetMessagingBinding 来使用发布在 Windows Server 服务总线主题上的消息。

据我了解,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>

提前致谢,

若昂·卡洛斯·德索萨

【问题讨论】:

    标签: wcf servicebus


    【解决方案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

    【讨论】:

      【解决方案2】:

      从错误来看,这似乎是 WCF 级别的错误,而不是服务总线。您是否尝试提高 MaxMessageSize? This thread 有相关信息,但基本上,您需要在 web.config 中的绑定配置中设置如下内容:

           <binding name="yourBinding"
                   maxReceivedMessageSize="10000000" 
                   maxBufferSize="10000000"
                   maxBufferPoolSize="10000000">
              <readerQuotas maxDepth="32" 
                   maxArrayLength="100000000"
                   maxStringContentLength="100000000"/>
          </binding>
      

      【讨论】:

      • 添加这些配置后,我得到了解析器错误(例如,无法识别的属性“maxReceivedMessageSize”。请注意,属性名称区分大小写。)。请注意,我使用的是“netMessagingBinding”。谢谢拉米罗!
      【解决方案3】:

      NetMessagingBinding 目前不允许通过 XML 配置更改 MaxStringContentLenght。

      一个对我有用的解决方案是通过实现IDispatchMessageFormatter 接口来创建消息格式化程序行为扩展。

      然后可以通过以下任一方式使用该扩展:

      • 创建一个可在代码中使用的属性来识别哪些操作合约将使用消息格式化程序行为

        public class MessageFormatterExtensionBehaviorAttribute : 
           Attribute, IOperationBehavior
        {
        
          (...)
        
        public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
        {
            dispatchOperation.Formatter = new MessageFormatterExtension();
        }
        
        (...)
        
        }
        
      • 创建一个公开自定义行为的configuration element

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-10-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-11-06
        • 1970-01-01
        相关资源
        最近更新 更多