Sending object to WCF service. MaxStringContentLength (8192 bytes) exceeded when deserializing

后端 未结 2 1397
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-25 15:09

I created a simple WCF web service that has one method: SubmitTicket(flightticket ft, string username, string password)

On the client side, I have an application for fil

相关标签:
2条回答
  • 2021-01-25 15:46

    This is the answer! I have searched everywhere the solution to this problem in WCF 4.0, and this entry by Richard Blewett was the final piece of the puzzle.

    Key things learned from my research:

    • if the exception is thrown by the service, then only change the Server Web.config file; don't worry about the client
    • create a custom basicHttpBinding:
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="customBindingNameForLargeMessages">
    
    • add the larger readerQuota values (largest possible shown here, adjust to taste)
            <binding name="customBindingNameForLargeMessages"
              maxReceivedMessageSize="2147483647">
              <readerQuotas maxDepth="2147483647"
                 maxStringContentLength="2147483647"
                 maxArrayLength="2147483647"
                 maxBytesPerRead="2147483647"
                 maxNameTableCharCount="2147483647" />
            </binding>
        </basicHttpBinding>
    </bindings>
    
    • create a service entry, with an endpoint that maps to the custom binding. The mapping happens when the endpoint's bindingConfiguration is the same as the binding's name:
    • Make sure the service name and the contract value are fully qualified - use the namespace, and the name of the class.
    <system.serviceModel>
        <services>
            <service name="Namespace.ServiceClassName">
                 <endpoint 
                     address="http://urlOfYourService"
                     bindingConfiguration="customBindingNameForLargeMessages"                     
                     contract="Namespace.ServiceInterfaceName" 
                     binding="basicHttpBinding"
                     name="BasicHTTPEndpoint" />
            </service>
        </services>
    
    0 讨论(0)
  • 2021-01-25 15:49

    I think the problem is that your service is not picking up its config because you have set the service name to be FlightTicketWebService whereas I would guess that the actual type is in a namespace. Fully qualify the service name with the namespace and it should pick up your config

    Essentially this is a by-product of the WCF 4 default endpoint functionality that if it finds no matching config it puts endpoints up with the default config

    0 讨论(0)
提交回复
热议问题