在这里找到了答案(最后一篇文章): http://social.msdn.microsoft.com/Forums/eu/wcf/thread/f5c0ea22-1d45-484e-b2c0-e3bc9de20915
我的定制(TextOrMtomEncoder)的实现还有最后一个问题,那就是ReaderQuotas的实现。
我已经搜索了很多网络,但我不知道最后一块拼图。
我有一堂课,它包含我对'BindingElementExtensionElement‘和'MessageEncodingBindingElement’的实现。
MessageEncodingBindingElement实现包含以下内容的重写:
T GetProperty<T>(BindingContext context)我“借用”了默认的.NET MessageEncoding实现,就像TextMessageEncoding。
这必须是正确的实现,因为MSDN这么说。
从web.config中可以很好地加载配置,我可以看到我的两个类中的ReaderQuotas属性设置正确,但是看起来.NET没有从MessageEncodingBindingElement实现中读取ReaderQuotas配置。
我的猜测是,.NET使用GetProperty方法加载配置,因为MessageVersion是通过该方法请求的。但是问题是,T永远不等于XmlDictionaryReaderQuotas,所以ReaderQuotas永远不会被请求。
我问题的根源是奇怪的--顺便说一句,我正在一个带有IIS7.5的Windows7 x64机器上开发。在我的机器上发布“大”文件(比如100 KB)是可行的。但是,当我将服务部署到Windows 2008 R2 (尝试了2台不同的服务器)时,我会得到以下错误:
格式化程序在试图反序列化消息时抛出一个异常:试图反序列化参数http://socialproxy.infocaster.net:argument时出错。InnerException消息是“反序列化System.Object类型对象的错误。读取System.Object数据时超过了最大数组长度配额(16384)。此配额可能会通过更改在创建XmlDictionaryReaderQuotas读取器时使用的XmlDictionaryReaderQuotas对象上的MaxArrayLength属性来增加。”有关更多细节,请参见InnerException。
就像我说的,它在我的机器上工作:
有人能告诉我怎么解决这个问题吗?
事先非常感谢!
WCF服务配置:
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name="wsdlExtensions" type="WCFExtras.Wsdl.WsdlExtensionsConfig, WCFExtras, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<add name="textOrMtomMessageBehavior" type="InfoCaster.SocialProxy.lib.TextOrMtom.TextOrMtomMessageBehavior, InfoCaster.SocialProxy" />
</behaviorExtensions>
<bindingElementExtensions>
<add name="textOrMtomEncoding" type="InfoCaster.SocialProxy.lib.TextOrMtom.TextOrMtomEncodingElement, InfoCaster.SocialProxy" />
</bindingElementExtensions>
</extensions>
<bindings>
<customBinding>
<binding name="TextOrMtomBinding">
<textOrMtomEncoding messageVersion="Soap11">
<readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="204800000" maxBytesPerRead="5242880" maxNameTableCharCount="5242880" />
</textOrMtomEncoding>
<httpTransport maxBufferSize="5242880" maxReceivedMessageSize="5242880" transferMode="Buffered" authenticationScheme="Anonymous" />
</binding>
</customBinding>
</bindings>
<services>
<clear />
<service name="InfoCaster.SocialProxy.SocialProxy" behaviorConfiguration="InfoCaster.SocialProxy.ISocialProxyServiceBehavior">
<endpoint name="SocialProxyServiceEndpoint" address="" binding="customBinding" bindingConfiguration="TextOrMtomBinding" contract="InfoCaster.SocialProxy.ISocialProxy" behaviorConfiguration="InfoCaster.SocialProxy.ISocialProxyEndpointBehavior" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<clear />
<behavior name="InfoCaster.SocialProxy.ISocialProxyServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<clear />
<behavior name="InfoCaster.SocialProxy.ISocialProxyEndpointBehavior">
<textOrMtomMessageBehavior />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>发布于 2012-05-11 14:21:38
在这里找到答案(最后一篇文章):http://social.msdn.microsoft.com/Forums/eu/wcf/thread/f5c0ea22-1d45-484e-b2c0-e3bc9de20915
好吧,我找到了。您必须将读取器引号传递给标准编码器。不幸的是,这里没有构造函数,所以您必须设置属性。
class TextOrMtomEncoder : MessageEncoder {
MessageEncoder _textEncoder;
MessageEncoder _mtomEncoder;
public TextOrMtomEncoder(MessageVersion messageVersion, XmlDictionaryReaderQuotas readerQuotas)
{
TextMessageEncodingBindingElement textEncoderBindingElement = new TextMessageEncodingBindingElement(messageVersion, Encoding.UTF8);
MtomMessageEncodingBindingElement mtomEncoderBindingElement = new MtomMessageEncodingBindingElement(messageVersion, Encoding.UTF8);
readerQuotas.CopyTo(mtomEncoderBindingElement.ReaderQuotas);
readerQuotas.CopyTo(textEncoderBindingElement.ReaderQuotas);
_mtomEncoder = mtomEncoderBindingElement.CreateMessageEncoderFactory().Encoder;
_textEncoder = textEncoderBindingElement.CreateMessageEncoderFactory().Encoder;
}https://stackoverflow.com/questions/10245739
复制相似问题