0
我從WCF服務調用接收下面的CommunicationException。我明白according to this answer,我需要設置TextMessageEncodingBindingElement.ReaderQuotas
對象,但它似乎是隻讀的(儘管在文檔中它說它是Get/Set)。如何繞過我的自定義綁定的最大可命名字符計數配額(16384)?
有誰知道如何在代碼中做到這一點?
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