private async Task ProcessMetaFromFile(Microsoft.AspNetCore.Http.HttpContext httpContext) { Meta.MetaFromFile meta = new Meta.MetaFromFile(); if (!string.IsNullOrEmpty(_options.WsdlFileOptions.VirtualPath)) { meta.CurrentWebServer = _options.WsdlFileOptions.VirtualPath + "/"; } meta.CurrentWebService = httpContext.Request.Path.Value.Replace("/", string.Empty); WebServiceWSDLMapping mapping = _options.WsdlFileOptions.WebServiceWSDLMapping[meta.CurrentWebService]; meta.XsdFolder = mapping.SchemaFolder; meta.WSDLFolder = mapping.WSDLFolder; if (_options.WsdlFileOptions.UrlOverride != string.Empty) { meta.ServerUrl = _options.WsdlFileOptions.UrlOverride; } else { meta.ServerUrl = httpContext.Request.Scheme + "://" + httpContext.Request.Host + "/"; } string wsdlfile = mapping.WsdlFile; string path = _options.WsdlFileOptions.AppPath; string wsdl = meta.ReadLocalFile(path + Path.AltDirectorySeparatorChar + meta.WSDLFolder + Path.AltDirectorySeparatorChar + wsdlfile); string modifiedWsdl = meta.ModifyWSDLAddRightSchemaPath(wsdl); //we should use text/xml in wsdl page for browser compability. httpContext.Response.ContentType = "text/xml;charset=UTF-8"; byte[] data = System.Text.Encoding.UTF8.GetBytes(modifiedWsdl); await httpContext.Response.Body.WriteAsync(data, 0, data.Length); }
private async Task ProcessXSD(Microsoft.AspNetCore.Http.HttpContext httpContext) { Meta.MetaFromFile meta = new Meta.MetaFromFile(); if (!string.IsNullOrEmpty(_options.WsdlFileOptions.VirtualPath)) { meta.CurrentWebServer = _options.WsdlFileOptions.VirtualPath + "/"; } meta.CurrentWebService = httpContext.Request.Path.Value.Replace("/", string.Empty); var mapping = _options.WsdlFileOptions.WebServiceWSDLMapping[meta.CurrentWebService]; meta.XsdFolder = mapping.SchemaFolder; if (_options.WsdlFileOptions.UrlOverride != string.Empty) { meta.ServerUrl = _options.WsdlFileOptions.UrlOverride; } else { meta.ServerUrl = httpContext.Request.Scheme + "://" + httpContext.Request.Host + "/"; } string xsdfile = httpContext.Request.Query["name"]; //Check to prevent path traversal if (string.IsNullOrEmpty(xsdfile) || Path.GetFileName(xsdfile) != xsdfile) { throw new ArgumentNullException("xsd parameter contains illeagal values"); } if (!xsdfile.Contains(".xsd")) { throw new Exception("xsd request must contain .xsd"); } string path = _options.WsdlFileOptions.AppPath; string safePath = path + Path.AltDirectorySeparatorChar + meta.XsdFolder + Path.AltDirectorySeparatorChar + xsdfile; string xsd = meta.ReadLocalFile(safePath); string modifiedxsd = meta.ModifyXSDAddRightSchemaPath(xsd); //we should use text/xml in wsdl page for browser compability. httpContext.Response.ContentType = "text/xml;charset=UTF-8"; byte[] data = System.Text.Encoding.UTF8.GetBytes(modifiedxsd); await httpContext.Response.Body.WriteAsync(data, 0, data.Length); }