WCF 格式化程序在尝试反序列化消息时抛出异常

WCF The formatter threw an exception while trying to deserialize the message

我制作了2个Win-forms桌面应用程序。他们互相传递数据,而且主要是字符串格式。

但是,如果字符串内容变得有点大,我会收到以下错误:

"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."

创建服务器的代码在这里

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

触发字符串的代码在这里

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

尽管我已经完成了所有工作,但它无法正常工作并给出相同的错误。我该怎么办?

这个参数在服务端和客户端之间是序列化的,所以我们也需要考虑在服务端增加配置。
服务器端。

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();

如果问题仍然存在,请随时告诉我。