// The demand is not added now (in 4.5), to avoid a breaking change. To be considered in the next version.

        /*
         * // We demand full trust because we call into CoordinationContext and CoordinationStrings, which are defined in a non-APTCA assembly. Also, CoordinationStrings.Version(..)
         * // does an Environment.FailFast if the argument is invalid. It's recommended to not let partially trusted callers to bring down the process.
         * // WSATs are not supported in partial trust, so customers should not be broken by this demand.
         * [PermissionSet(SecurityAction.Demand, Unrestricted = true)]
         */
        public static CoordinationContext GetCoordinationContext(Message message, ProtocolVersion protocolVersion)
        {
            CoordinationStrings coordinationStrings = CoordinationStrings.Version(protocolVersion);
            string locWsatHeaderElement             = coordinationStrings.CoordinationContext;
            string locWsatNamespace = coordinationStrings.Namespace;

            int index;

            try
            {
                index = message.Headers.FindHeader(locWsatHeaderElement, locWsatNamespace);
            }
            catch (MessageHeaderException e)
            {
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning);
                return(null);
            }
            if (index < 0)
            {
                return(null);
            }

            CoordinationContext context;
            XmlDictionaryReader reader = message.Headers.GetReaderAtHeader(index);

            using (reader)
            {
                context = GetCoordinationContext(reader, protocolVersion);
            }

            MessageHeaderInfo header = message.Headers[index];

            if (!message.Headers.UnderstoodHeaders.Contains(header))
            {
                message.Headers.UnderstoodHeaders.Add(header);
            }

            return(context);
        }