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

跟風遠走 提交于 2019-12-02 04:07:32

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

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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!