我从WCF服务调用中收到以下CommunicationException。我理解according to this answer,我需要设置TextMessageEncodingBindingElement.ReaderQuotas
对象,但它似乎只读(虽然在文档中它说它是Get / Set)。
有人知道如何在代码中执行此操作吗?
System.ServiceModel.CommunicationException was caught
Message="Error in deserializing body of reply message for operation 'PutMessage'."
Source="mscorlib"
StackTrace:
Server stack trace: at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, Object[] parameters, Boolean isRequest) at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest) at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest) at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at
...
InnerException: System.InvalidOperationException
Message="There is an error in XML document (1, 695)."
Source="System.Xml"
StackTrace:
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle) at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, Object[] parameters, Boolean isRequest)
InnerException: System.Xml.XmlException
LineNumber=0
LinePosition=0
Message="The maximum nametable character count quota (16384) has been exceeded while reading XML data. The nametable is a data structure used to store strings encountered during XML processing - long XML documents with non-repeating element names, attribute names and attribute values may trigger this quota. This quota may be increased by changing the MaxNameTableCharCount property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 695."
Source="System.Runtime.Serialization"
StackTrace:
at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3) at System.Xml.XmlExceptionHelper.ThrowMaxNameTableCharCountExceeded(XmlDictionaryReader reader, Int32 maxNameTableCharCount) at System.Xml.XmlBaseReader.QuotaNameTable.Add(Int32 charCount) at System.Xml.XmlBaseReader.QuotaNameTable.Add(String value) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderstarTransportPortTypes.InitIDs() at System.Xml.Serialization.XmlSerializationReader.Init(XmlReader r, XmlDeserializationEvents events, String encodingStyle, TempAssembly tempAssembly) at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
InnerException:
这是我用来构建绑定的代码:
Private Function GetCustomBinding() As Channels.Binding
Dim asbe As New Channels.AsymmetricSecurityBindingElement
'... set various properties on asbe object
'Add the elements to the custom binding
Dim myBinding As New CustomBinding
'Protocol Binding Elements (security)
myBinding.Elements.Add(asbe)
'Encoding Binding Element
Dim textMsgEncoder As New TextMessageEncodingBindingElement(MessageVersion.Soap11, System.Text.Encoding.UTF8)
Dim rQuota As New System.Xml.XmlDictionaryReaderQuotas
rQuota.MaxDepth = 2147483647
rQuota.MaxStringContentLength = 2147483647
rQuota.MaxArrayLength = 2147483647
rQuota.MaxBytesPerRead = 2147483647
rQuota.MaxNameTableCharCount = 2147483647
''''''''''
'textMsgEncoder.ReaderQuotas = rQuota 'this is readonly, so can't do it
''''''''''
myBinding.Elements.Add(textMsgEncoder)
'Transport Binding Element
Dim httpsBindingElement As New HttpsTransportBindingElement()
httpsBindingElement.MaxBufferSize = 5000000
httpsBindingElement.MaxReceivedMessageSize = 5000000
myBinding.Elements.Add(httpsBindingElement)
Return myBinding
End Function
答案 0 :(得分:0)
您无法设置ReaderQuotas对象,但您可以在其上设置单个属性,如下所示:
textMsgEncoder.ReaderQuotas.MaxNameTableCharCount = 2147483647
或其他适当的值