From a83c0d879d9f6bc9f1f80dac6b8ebb9017b36fd0 Mon Sep 17 00:00:00 2001 From: GyroGearl00se Date: Sat, 20 Jul 2024 23:35:15 +0200 Subject: [PATCH] handle message without payload --- Services/SolaceSubscribeService.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Services/SolaceSubscribeService.cs b/Services/SolaceSubscribeService.cs index 6259d93..cec8f9e 100644 --- a/Services/SolaceSubscribeService.cs +++ b/Services/SolaceSubscribeService.cs @@ -67,8 +67,17 @@ public void HandleMessage(object source, MessageEventArgs args, Action m { using (IMessage message = args.Message) { - string messageContent = Encoding.ASCII.GetString(message.BinaryAttachment); - messageHandler(messageContent); + string messageContent; + + byte[] binaryAttachment = message.BinaryAttachment; + if (binaryAttachment != null && binaryAttachment.Length > 0) + { + messageContent = Encoding.UTF8.GetString(binaryAttachment); + messageHandler(messageContent); + } else + { + messageHandler("Message without payload"); + } } } catch (OperationErrorException ex)