/// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="structure">The structure.</param>
        /// <param name="agencyId">The agency id.</param>
        /// <param name="resourceId">The resource id.</param>
        /// <param name="version">The version.</param>
        /// <param name="ctx">The current <see cref="WebOperationContext"/>.</param>
        /// <returns>
        /// The <see cref="Message" />.
        /// </returns>
        /// <exception cref="System.Web.HttpBrowserCapabilitiesBase"></exception>
        /// <exception cref="WebFaultException{String}">
        /// Cannot serve content type
        /// </exception>
        /// <exception cref="WebFaultException{String}">Cannot serve content type</exception>
        private Message ProcessRequest(string structure, string agencyId, string resourceId, string version, WebOperationContext ctx)
        {
            Match match = Regex.Match(resourceId, @"[A-Za-z0-9\-]+$", RegexOptions.IgnoreCase);
            if (!match.Success)
            {
                throw new WebFaultException(HttpStatusCode.BadRequest);
            }

            var defaultMediaType = StructureMediaType.GetFromEnum(StructureMediaEnumType.Structure).MediaTypeName;
            var requestAccept = ctx.IncomingRequest.Accept;
            Logger.Info("Got request Content type= " + requestAccept);

            IList<ContentType> acceptHeaderElements = ctx.IncomingRequest.GetAcceptHeaderElements();
            Func<ContentType, bool> predicate = type => StructureMediaType.GetTypeFromName(type.MediaType) != null;
            var contentType = RestUtils.GetContentType(ctx, predicate, defaultMediaType);

            string requestedVersion = HeaderUtils.GetVersionFromAccept(acceptHeaderElements, contentType.MediaType);

            var selectedStructureMediaType = StructureMediaType.GetTypeFromName(contentType.MediaType);
            var selectedMediaTypeWithVersion = selectedStructureMediaType.GetMediaTypeVersion(requestedVersion);

            if (selectedMediaTypeWithVersion == null)
            {
                Logger.Error("Cannot serve content type: " + requestAccept);
                throw new WebFaultException<string>("Cannot serve content type: " + requestAccept, HttpStatusCode.NotAcceptable);
            }

            Logger.Debug("Select mediatype with version if required: " + selectedMediaTypeWithVersion);

            SdmxSchema schemaVersion = RestUtils.GetVersionFromMediaType(selectedMediaTypeWithVersion);

            Logger.Info("Selected representation info for the controller: format =" + "TODO" + " , smdx_schema=" + version);
            IRestStructureQuery query = BuildRestQueryBean(structure, agencyId, resourceId, version, ctx.IncomingRequest.UriTemplateMatch.QueryParameters);
            var charSetEncoding = RestUtils.GetCharSetEncoding(contentType);
            var streamController = this._structureRequestController.ParseRequest(query, schemaVersion, charSetEncoding);

            var responseContentType = RestUtils.GetContentType(contentType, selectedMediaTypeWithVersion);
            selectedMediaTypeWithVersion.CharSet = charSetEncoding.WebName;

            IMessageFormat messageFormat = new RestFormat(ctx, responseContentType);
            return this._messageBuilderManager.GetResponse<Message, Stream>(messageFormat, streamController);
        }
        /// <summary>
        /// The process request.
        /// </summary>
        /// <param name="flowRef">
        /// The flow ref.
        /// </param>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <param name="providerRef">
        /// The provider ref.
        /// </param>
        /// <param name="ctx">
        /// The ctx.
        /// </param>
        /// <returns>
        /// The <see cref="Message"/>.
        /// </returns>
        /// <exception cref="WebFaultException{T}">
        /// </exception>
        private Message ProcessRequest(string flowRef, string key, string providerRef, WebOperationContext ctx)
        {
            var requestAccept = ctx.IncomingRequest.Accept;

            Logger.Info("Got request Content type= " + requestAccept);

            IList<ContentType> acceptHeaderElements = ctx.IncomingRequest.GetAcceptHeaderElements();

            var defaultMediaType = DataMediaType.GetFromEnum(DataMediaEnumType.GenericData).MediaType;
            var contentType = RestUtils.GetContentType(ctx, h => DataMediaType.GetTypeFromName(h.MediaType) != null, defaultMediaType);

            string requestedVersion = HeaderUtils.GetVersionFromAccept(acceptHeaderElements, contentType.MediaType);

            var datamediaType = DataMediaType.GetTypeFromName(contentType.MediaType);
            var selectedMediaTypeWithVersion = datamediaType.GetMediaTypeVersion(requestedVersion);

            if (selectedMediaTypeWithVersion == null)
            {
                Logger.Error("Cannot serve content type: " + requestAccept);
                throw new WebFaultException<string>("Cannot serve content type: " + requestAccept, HttpStatusCode.NotAcceptable);
            }

            Logger.Debug("Select mediatype with version if required: " + selectedMediaTypeWithVersion);

            BaseDataFormat format = DataMediaType.GetTypeFromName(selectedMediaTypeWithVersion.MediaType).Format;
            SdmxSchema version = GetVersionFromMediaType(selectedMediaTypeWithVersion, format);

            Logger.Info("Selected representation info for the controller: format =" + format + " , smdx_schema=" + version);
            IRestDataQuery query = this.BuildQueryBean(flowRef, key, providerRef, ctx.IncomingRequest.UriTemplateMatch.QueryParameters);
            HttpContext context = HttpContext.Current;

            var charSetEncoding = RestUtils.GetCharSetEncoding(contentType);
            
            var streamController = this._dataRequestController.ParseRequest(query, format.GetDataType(version), charSetEncoding);
            var responseContentType = RestUtils.GetContentType(contentType, selectedMediaTypeWithVersion);
            selectedMediaTypeWithVersion.CharSet = charSetEncoding.WebName;
            
            IMessageFormat messageFormat = new RestFormat(ctx, responseContentType);
            return this._messageBuilderManager.GetResponse<Message, Stream>(messageFormat, streamController);
        }