Is there any way to test the size of a message before it is sent back to the client? I'd like to handle the maximum message size quota on the service side of things.
You can write a custom MessageEncoder
, use it on the service side, and check an encoded message size inside it's WriteMessage
methods.
Follow this guide and override the methods in such a way:
public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
{
var result = this.text.WriteMessage(message, maxMessageSize, bufferManager, messageOffset);
// Encoded message check logic.
Console.WriteLine("Message sent. Length=" + result.Count);
return result;
}
public override void WriteMessage(Message message, Stream stream)
{
var position = stream.Position;
this.text.WriteMessage(message, stream);
// Encoded message check logic.
Console.WriteLine("Message sent. Length=" + (stream.Position - position));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With