0
votes

I have made 2 Win-forms desktop applications. They pass data to each other and its mostly in string format.

However if string content becomes a bit bigger I get the following error:

"The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:Code. The InnerException message was 'There was an error deserializing the object of type System.String[]. 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. Line 216, position 104.'. Please see InnerException for more details."

The code that creates the server is here

Try
            host = New ServiceHost(GetType(MainServerCode), New Uri("http://localhost:6767"))
            host.AddServiceEndpoint(GetType(MainInterface), New BasicHttpBinding(), "Editor")
            host.Open()
        Catch ex As Exception
         End If

The code that fires the string is here

Try
            Dim Binding As New BasicHttpBinding()
            binding.MaxBufferSize = binding.MaxBufferSize * 2
            binding.MaxReceivedMessageSize = binding.MaxBufferSize
            binding.ReaderQuotas.MaxStringContentLength = Integer.MaxValue

            Dim httpFactory As New ChannelFactory(Of TAFunc)(binding, New EndpointAddress("http://localhost:6768/XXX"))
            Dim httpProxy As TAFunc = httpFactory.CreateChannel(), R(-1), D(-1) As String

            httpProxy.RunScript(name, scode, type, nbar, R, D)

            ' array sc code contains textual data (string)

            Result = R
            DebugData = D

        Catch ex As Exception
            Debug.Print(ex.Message)
        End Try

In-spite of all I have done its not working and giving the same error. What should I do?

1

1 Answers

2
votes

This parameter is serialized between the server and the client, so we also need to consider adding configuration on the server-side.
Server-side.

BasicHttpBinding binding = new BasicHttpBinding();
            binding.MaxReceivedMessageSize = int.MaxValue;
            binding.ReaderQuotas.MaxArrayLength = int.MaxValue;
            binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
            binding.ReaderQuotas.MaxDepth = int.MaxValue;
            binding.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
            using (ServiceHost sh = new ServiceHost(typeof(MyService), uri))
            {
                sh.AddServiceEndpoint(typeof(IService), binding, "");
               sh.Open();

Feel free to let me know if the problem still exists.