private string SerializeException(HttpContext context, OwsException exception)
        {
            if (exception == null)
            {
                return("Not supported exception type.");
            }

            var version         = context.Items["version"];
            var exceptionReport = new OwsExceptionReport
            {
                Version    = (version == null) ? configuration.DefaultVersion : version.ToString(),
                Exceptions = new [] { new OwsExceptionReportException
                                      {
                                          ExceptionCode = exception.Code.ToString(),
//                    Locator = (string.IsNullOrEmpty(exception.Locator)) ? context.Request.Host+context.Request.Method : exception.Locator,
                                          Locator           = exception.Locator, // ?? context.Request.Host+context.Request.Path,
                                          ExceptionMessages = exception.Messages
                                      } }
            };

            using (var ms = new MemoryStream())
            {
                using (var sw = new StreamWriter(ms, Encoding.UTF8))
                {
                    var ns = new XmlSerializerNamespaces();
                    ns.Add("ows", Namespaces.Ows);

                    var serializer = new XmlSerializer(typeof(OwsExceptionReport));
                    serializer.Serialize(sw, exceptionReport, ns);
                    return(Encoding.UTF8.GetString(ms.ToArray()));
                }
            }
        }
        private Task WriteOwsExceptionAsync(HttpContext context, OwsException exception)
        {
            if (exception == null)
            {
                throw new Exception("Not supported exception type.");
            }

            var response = context.Response;

            response.ContentType = "application/xml";
            response.StatusCode  = GetStatusCode(exception.Code);
            return(response.WriteAsync(SerializeException(context, exception)));
        }