none
NetTcpBinding sending message >64k RRS feed

  • Question

  • This question may have been answered numerous times, but when I search I seem to find only questions relating to RECEIVING large messages, not SENDING.

    I have a service and a client, both of which I'm creating via code, not via a config file. The server side is as simple as this:

    _serviceHost = new ServiceHost(typeof(MyWebService), Shared.GetUri());
    _serviceHost.Open();
    

    "Shared.GetUri()" returns a URI of the format "net.tcp://server:port/wsname".

    The client uses a class based on "DuplexClientBase" with the same URI as the server and a binding configured like this:

    NetTcpBinding myBinding = new NetTcpBinding();
    myBinding.MaxBufferSize = int.MaxValue;
    myBinding.MaxReceivedMessageSize = int.MaxValue;
    

    I create a proxy on the client simply with "Proxy = _client.ChannelFactory.CreateChannel();"

    Everything works perfectly UNTIL the message I send from the client to the server is larger than 64k.  At that point I get "The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error".

    What other configuration setting do I need in order to send messages larger than 64k?

    At this point, please don't recommend streaming or other alternatives.  We're working on that, but I need to solve this one first/quickly.

    Thanks!

    Brad.

    Friday, September 25, 2015 12:19 AM

Answers

  • Yes, I was quite convinced I needed to tweak the server side as well, but I couldn't figure out how.  I was always wondering how the binding got set on the server side, and couldn't see how I could change it.  I finally figured it out.  Here is the server-side code that works for me:

    _serviceHost = new ServiceHost(typeof(MyWebService));
    _serviceHost.AddServiceEndpoint(typeof(IMyWebService), myBinding, Shared.GetUri());
    _serviceHost.Open();
    

    Brad.

    • Marked as answer by Pletzky Friday, September 25, 2015 3:43 PM
    Friday, September 25, 2015 3:43 PM

All replies

  • Hi Pletzky,

    May be you can add the following note in your app.config file.

    <bindings>
          <netTcpBinding>
            <binding name="webBingding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                             maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
            </binding>
          </netTcpBinding>
    </bindings>
    

    For more information, please refer to the following articles:

    1.<readerQuotas>

    I hope that will be helpful to you.

    Best Regards,

    Grady

    Friday, September 25, 2015 5:36 AM
    Moderator
  • Unfortunately I find this kind of blanket answer to be of little use.  1) as I mentioned, I'm not using a config file (though I'm sure I could translate it), and 2) I want to know/understand what's going on and which setting actually makes a difference.  I've tried the settings on the binding itself, and from I understand from reading the documentation, the "readerQuotas" don't apply to this scenario.

    Thanks anyway,

    Brad.

    Friday, September 25, 2015 2:01 PM
  • This question may have been answered numerous times, but when I search I seem to find only questions relating to RECEIVING large messages, not SENDING.

    Well, what is going to have the problem is the receiver and not the sender when the file is a bigger size than what the receiver is expecting.  

     Unfortunately I find this kind of blanket answer to be of little use.  1) as I mentioned, I'm not using a config file (though I'm sure I could translate it), and 2) I want to know/understand what's going on and which setting actually makes a difference.  I've tried the settings on the binding itself, and from I understand from reading the documentation, the "readerQuotas" don't apply to this scenario.

    ReaderQuotas probably is the problem,  and may be you should go to a config file and use it instead of doing it programmatically, which you would have to use a custom binding on the service side config to override any default settings.

    You can also attempt to do it programmatically.

    http://www.codeproject.com/Tips/243357/WCF-Custom-Binding

    Your problem is with the receiver and not the sender. The sender can send any size it wants. But can the receiver receive it? 

    Friday, September 25, 2015 2:45 PM
  • Yes, I was quite convinced I needed to tweak the server side as well, but I couldn't figure out how.  I was always wondering how the binding got set on the server side, and couldn't see how I could change it.  I finally figured it out.  Here is the server-side code that works for me:

    _serviceHost = new ServiceHost(typeof(MyWebService));
    _serviceHost.AddServiceEndpoint(typeof(IMyWebService), myBinding, Shared.GetUri());
    _serviceHost.Open();
    

    Brad.

    • Marked as answer by Pletzky Friday, September 25, 2015 3:43 PM
    Friday, September 25, 2015 3:43 PM