Results 1 to 3 of 3

Thread: WCF How to increase string size

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    India
    Posts
    517

    Post WCF How to increase string size

    Hello Everyone,

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

    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
    Code:
    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
    Code:
    Try
                Dim B As New BasicHttpBinding()
                B.MaxBufferSize = B.MaxBufferSize * 3
                B.MaxReceivedMessageSize = B.MaxBufferSize
                'B.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max
                B.GetType().GetProperty("ReaderQuotas").SetValue(B, XmlDictionaryReaderQuotas.Max, Nothing)
    
                Dim httpFactory As New ChannelFactory(Of TAFunc)(B, 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
    I don't know how to solve it. Please help. If string content becomes bigger program fails. If its small then okay. There are no config files in the project.

    Thank you,

    Regards,
    GR

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: WCF How to increase string size

    Based on the documentation here:

    https://docs.microsoft.com/en-au/dot...tframework-4.8

    this should work:
    vb.net Code:
    1. Dim binding As New BasicHttpBinding
    2. Dim readerQuotas As New XmlDictionaryReaderQuotas
    3.  
    4. readerQuotas.MaxStringContentLength = Integer.MaxValue
    5.  
    6. binding.ReaderQuotas = readerQuotas
    It's better to work out what the actual maximum will be if possible, rather than just allowing the absolute maximum possible.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    India
    Posts
    517

    Re: WCF How to increase string size

    Quote Originally Posted by jmcilhinney View Post
    Based on the documentation here:

    https://docs.microsoft.com/en-au/dot...tframework-4.8

    this should work:
    vb.net Code:
    1. Dim binding As New BasicHttpBinding
    2. Dim readerQuotas As New XmlDictionaryReaderQuotas
    3.  
    4. readerQuotas.MaxStringContentLength = Integer.MaxValue
    5.  
    6. binding.ReaderQuotas = readerQuotas
    It's better to work out what the actual maximum will be if possible, rather than just allowing the absolute maximum possible.
    I added the following code:
    Code:
    binding.ReaderQuotas.MaxStringContentLength = Integer.MaxValue
    It's still giving the same error. What am I missing? Do I need to make changes somewhere else also.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width