/// <summary>
        /// Handle incoming request.
        /// </summary>
        public virtual void ProcessRequest(HttpContext httpContext)
        {
            using (var context = new XRoadContext(httpContext))
            {
                try
                {
                    context.MessageFormatter = XRoadHelper.GetMessageFormatter(httpContext.Request.ContentType);

                    httpContext.Request.InputStream.Position = 0;
                    httpContext.Response.ContentType         = XRoadHelper.GetContentTypeHeader(context.MessageFormatter.ContentType);

                    HandleRequest(context);
                }
                catch (Exception exception)
                {
                    if (context.MessageFormatter == null)
                    {
                        context.MessageFormatter = new SoapMessageFormatter();
                    }

                    httpContext.Response.ContentType = XRoadHelper.GetContentTypeHeader(context.MessageFormatter.ContentType);

                    if (httpContext.Response.OutputStream.CanSeek)
                    {
                        httpContext.Response.OutputStream.Seek(0, SeekOrigin.Begin);
                        httpContext.Response.OutputStream.SetLength(0);
                    }

                    var fault = context.MessageFormatter.CreateFault(exception);

                    OnExceptionOccurred(context, exception, fault);
                }
            }
        }
        public static async Task Invoke(HttpContext httpContext, IWebServiceHandler handler)
        {
            var options  = httpContext.RequestServices.GetRequiredService <XRoadLibOptions>();
            var accessor = httpContext.RequestServices.GetRequiredService <IWebServiceContextAccessor>();

            if (handler is WebServiceRequestHandler requestHandler)
            {
                requestHandler.StoragePath = options.StoragePath;
            }

            using (var context = new WebServiceContext(httpContext))
            {
                if (accessor is WebServiceContextAccessor webServiceContextAccessor)
                {
                    webServiceContextAccessor.WebServiceContext = context;
                }

                try
                {
                    context.MessageFormatter = XRoadHelper.GetMessageFormatter(context.HttpContext.Request.ContentType);

                    if (httpContext.Request.Body.CanSeek)
                    {
                        httpContext.Request.Body.Position = 0;
                    }

                    httpContext.Response.ContentType = XRoadHelper.GetContentTypeHeader(context.MessageFormatter.ContentType);

                    await handler.HandleRequestAsync(context);
                }
                catch (Exception exception)
                {
                    if (context.MessageFormatter == null)
                    {
                        context.MessageFormatter = new SoapMessageFormatter();
                    }

                    httpContext.Response.ContentType = XRoadHelper.GetContentTypeHeader(context.MessageFormatter.ContentType);

                    if (httpContext.Response.Body.CanSeek)
                    {
                        httpContext.Response.Body.Seek(0, SeekOrigin.Begin);
                        httpContext.Response.Body.SetLength(0);
                    }

                    var fault = context.MessageFormatter.CreateFault(exception);

                    await handler.HandleExceptionAsync(context, exception, fault);
                }
            }
        }