Wcf – The formatter threw an exception while trying to deserialize the message.. sending from android

wcf

I am new for wcf services.

some time no error,but some time getting error. please help me on this

The service model

<system.serviceModel>
        <bindings>
          <wsHttpBinding>
            <binding name="ExStreamWCFBinding"
                     closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"                
                    hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="2147483647"
                    maxReceivedMessageSize="2147483647">
              <readerQuotas
                            maxDepth="2147483647"
                            maxStringContentLength="2147483647"
                            maxArrayLength="2147483647"
                            maxBytesPerRead="2147483647"
                            maxNameTableCharCount="2147483647"
                             />
            </binding>
          </wsHttpBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="wsServiceBehavior">
              <dataContractSerializer maxItemsInObjectGraph="2147483646" />
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <services>
          <service name="Wcf_tblt_rTest.Service1" behaviorConfiguration="ServiceBehavior" >
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:900/mex/"/>
                <add baseAddress="net.tcp://localhost:9000/" />
              </baseAddresses>
            </host>
            <endpoint bindingConfiguration="ExStreamWCFBinding" binding="basicHttpBinding" contract="Wcf_tblt_rTest.IService1" />
            <endpoint  address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
        </services>

      </system.serviceModel>

error coming like this

an error while trying to deserialize parameter http://tempuri.org/:tm.
The InnerException message was 'There was an error deserializing the
object of type JSONSample.GetResp. 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.'. See server logs for more
details. The exception stack trace is:

at
System.ServiceModel.Dispatcher.DataContractJsonSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader
reader, PartInfo part) at
System.ServiceModel.Dispatcher.DataContractJsonSerializerOperationFormatter.DeserializeParameter(XmlDictionaryReader
reader, PartInfo part) at
System.ServiceModel.Dispatcher.DataContractJsonSerializerOperationFormatter.DeserializeParameters(XmlDictionaryReader
reader, PartInfo[] parts, Object[] parameters, PartInfo returnInfo,
Object& returnValue) at
System.ServiceModel.Dispatcher.DataContractJsonSerializerOperationFormatter.DeserializeBodyCore(XmlDictionaryReader
reader, Object[] parameters, Boolean isRequest) at
System.ServiceModel.Dispatcher.DataContractJsonSerializerOperationFormatter.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.DeserializeRequest(Message
message, Object[] parameters) at
System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message
message, Object[] parameters) at
System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message
message, Object[] parameters) at
System.ServiceModel.Dispatcher.CompositeDispatchFormatter.DeserializeRequest(Message
message, Object[] parameters) at
System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc&
rpc) at
System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&
rpc) at
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&
rpc) at
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&
rpc) at
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&
rpc) at
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&
rpc) at
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&
rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean
isOperationContextSet)

Best Answer

WCF has many quotas (aka limits) that prevents either malicious or unintentional denial of service attacks.

The message "The maximum string content length quota (8192) has been exceeded" means that you're sending a string containing more than 8192 characters. You have to alter the config file to allow larger content.

Your settings are not applied here because you specified reader quotas for wsHttpBinding and your service is exposed via basicHttpBinding : there is mismatch and new quotas settings are not applied.

Related Topic