private static Messaging CreateMessagingHeader(AS4Message message)
        {
            object ToGeneralMessageUnit(MessageUnit u)
            {
                switch (u)
                {
                case UserMessage um: return(UserMessageMap.Convert(um));

                case Receipt r: return(ReceiptMap.Convert(r));

                case Error e: return(ErrorMap.Convert(e));

                case PullRequest pr: return(PullRequestMap.Convert(pr));

                default:
                    throw new NotSupportedException(
                              $"AS4Message contains unkown MessageUnit of type: {u.GetType()}");
                }
            }

            var messagingHeader = new Messaging
            {
                SecurityId   = message.SigningId.HeaderSecurityId,
                MessageUnits = message.MessageUnits.Select(ToGeneralMessageUnit).ToArray()
            };

            if (message.IsMultiHopMessage)
            {
                messagingHeader.role                     = Constants.Namespaces.EbmsNextMsh;
                messagingHeader.mustUnderstand1          = true;
                messagingHeader.mustUnderstand1Specified = true;
            }

            return(messagingHeader);
        }
        private static SignalMessage ConvertSignalMessageFromXml(Xml.SignalMessage signalMessage, Maybe <RoutingInputUserMessage> routing)
        {
            if (signalMessage.Error != null)
            {
                return(ErrorMap.Convert(signalMessage, routing));
            }

            if (signalMessage.PullRequest != null)
            {
                return(PullRequestMap.Convert(signalMessage));
            }

            if (signalMessage.Receipt != null)
            {
                return(ReceiptMap.Convert(signalMessage, routing));
            }

            throw new NotSupportedException("Unable to map Xml.SignalMessage to SignalMessage");
        }