3

I have this code I am implemented from this azure wcf relay

I am getting this exception when sending a message bigger than 64K (with smaller message it works OK):

System.ServiceModel.CommunicationException: 'The maximum message size quota for incoming messages has been exceeded for the remote channel. See the server logs for more details.

the quota is unlimited in NetTcpRelayBinding according to this quota web page

here is my code

class WCFRelay
{
    [ServiceContract(Namespace = "urn:ps")]
    interface IProblemSolver
    {
        [OperationContract]
        int Test(byte[] bytes);
    }

    class ProblemSolver : IProblemSolver
    {
        public int Test(byte[] bytes)
        {
            return bytes.Length;
        }
    }

    interface IProblemSolverChannel : IProblemSolver, IClientChannel { }

    public static void CreateClient()
    {
        var cf = new ChannelFactory<IProblemSolverChannel>(
        new NetTcpRelayBinding(),
        new EndpointAddress(ServiceBusEnvironment.CreateServiceUri("sb", "...", "solver")));

        cf.Endpoint.Behaviors.Add(new TransportClientEndpointBehavior
        { TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider("RootManageSharedAccessKey", "...") });

        using (var ch = cf.CreateChannel())
        {
            // if its 50K its ok - if its 70K i get exception
            Console.WriteLine(ch.Test(new byte[1000 * 70]));
        }
    }

    public static void CreateServer()
    {
        ServiceHost sh = new ServiceHost(typeof(ProblemSolver));

        sh.AddServiceEndpoint(
           typeof(IProblemSolver), new NetTcpRelayBinding(),
           ServiceBusEnvironment.CreateServiceUri("sb", "...", "solver"))
            .Behaviors.Add(new TransportClientEndpointBehavior
            {
                TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider("RootManageSharedAccessKey", "...")
            });

        sh.Open();

        while (true)
        {
            Thread.Sleep(1000);
        }
        Console.WriteLine("Press ENTER to close");
        Console.ReadLine();

        sh.Close();
    }
}
asaf
  • 958
  • 1
  • 16
  • 38
  • 4
    Possible duplicate of [The maximum message size quota for incoming messages (65536) has been exceeded](https://stackoverflow.com/questions/2908857/the-maximum-message-size-quota-for-incoming-messages-65536-has-been-exceeded) – spodger Oct 25 '17 at 08:12
  • 1
    its a web.config and not a code implementation, and its not related to azure relay – asaf Oct 25 '17 at 09:02

1 Answers1

2

According to your description,I checked this issue and found the cause. When you construct the NetTcpRelayBinding, the default value for MaxBufferSize and MaxReceivedMessageSize is 64K as follows:

enter image description here

You could specific the MaxBufferSize,MaxReceivedMessageSize,MaxBufferPoolSize to a larger value when constructing the NetTcpRelayBinding instance both in your server and client side.

Result:

enter image description here

Bruce Chen
  • 18,207
  • 2
  • 21
  • 35