From 74fa8e263fd64af0623f351d17bdd55397d40f37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=BE=E8=8D=A3=E5=9B=BD?= Date: Thu, 13 Jan 2022 09:21:48 +0800 Subject: [PATCH] =?UTF-8?q?[add]=20=E8=AE=BF=E9=97=AERemoteService?= =?UTF-8?q?=E6=97=B6=E6=94=AF=E6=8C=81Bearer=20Authentication?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebApiService/.gitignore | 1 + .../Controllers/WeatherForecastController.cs | 39 ---- WebApiService/src/TestHost/Program.cs | 26 --- .../TestHost/Properties/launchSettings.json | 31 ---- WebApiService/src/TestHost/Startup.cs | 29 --- WebApiService/src/TestHost/TestHost.csproj | 17 -- WebApiService/src/TestHost/TestModule.cs | 47 ----- WebApiService/src/TestHost/WeatherForecast.cs | 15 -- WebApiService/src/TestHost/appsettings.json | 10 - .../appsettings.json | 2 +- .../BaererToken.cs | 11 ++ .../Controllers/PartController.cs | 9 +- .../GlobalCache.cs | 7 + .../HttpClientInvoker.cs | 23 ++- .../IHttpClientInvoker.cs | 2 +- .../ITokenService.cs | 9 + .../Logs/logs.txt | 171 ++++++++++++++++++ .../Win_in.Sfs.Scp.WebApi.Xml.Host/Startup.cs | 4 +- .../TokenService.cs | 59 ++++++ .../Win_in.Sfs.Scp.WebApi.Xml.Host.csproj | 1 - .../appsettings.Production.Development.json} | 0 .../appsettings.Production.json | 20 ++ .../appsettings.json | 13 +- 23 files changed, 317 insertions(+), 229 deletions(-) delete mode 100644 WebApiService/src/TestHost/Controllers/WeatherForecastController.cs delete mode 100644 WebApiService/src/TestHost/Program.cs delete mode 100644 WebApiService/src/TestHost/Properties/launchSettings.json delete mode 100644 WebApiService/src/TestHost/Startup.cs delete mode 100644 WebApiService/src/TestHost/TestHost.csproj delete mode 100644 WebApiService/src/TestHost/TestModule.cs delete mode 100644 WebApiService/src/TestHost/WeatherForecast.cs delete mode 100644 WebApiService/src/TestHost/appsettings.json create mode 100644 WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/BaererToken.cs create mode 100644 WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/GlobalCache.cs create mode 100644 WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/ITokenService.cs create mode 100644 WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/TokenService.cs rename WebApiService/src/{TestHost/appsettings.Development.json => Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.Production.Development.json} (100%) create mode 100644 WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.Production.json diff --git a/WebApiService/.gitignore b/WebApiService/.gitignore index 50f3bef..c1b8e8d 100644 --- a/WebApiService/.gitignore +++ b/WebApiService/.gitignore @@ -21,6 +21,7 @@ bld/ [Bb]in/ [Oo]bj/ [Ll]og/ +[Ll]ogs/ # Visual Studio 2015 cache/options directory .vs/ diff --git a/WebApiService/src/TestHost/Controllers/WeatherForecastController.cs b/WebApiService/src/TestHost/Controllers/WeatherForecastController.cs deleted file mode 100644 index 6ccd283..0000000 --- a/WebApiService/src/TestHost/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace TestHost.Controllers -{ - [ApiController] - [Route("[controller]")] - public class WeatherForecastController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet] - public IEnumerable Get() - { - var rng = new Random(); - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateTime.Now.AddDays(index), - TemperatureC = rng.Next(-20, 55), - Summary = Summaries[rng.Next(Summaries.Length)] - }) - .ToArray(); - } - } -} diff --git a/WebApiService/src/TestHost/Program.cs b/WebApiService/src/TestHost/Program.cs deleted file mode 100644 index 131e53f..0000000 --- a/WebApiService/src/TestHost/Program.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace TestHost -{ - public class Program - { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }).UseAutofac(); - } -} diff --git a/WebApiService/src/TestHost/Properties/launchSettings.json b/WebApiService/src/TestHost/Properties/launchSettings.json deleted file mode 100644 index 88ec8e0..0000000 --- a/WebApiService/src/TestHost/Properties/launchSettings.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:33955", - "sslPort": 0 - } - }, - "profiles": { - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "launchUrl": "swagger", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "TestHost": { - "commandName": "Project", - "dotnetRunMessages": "true", - "launchBrowser": true, - "launchUrl": "swagger", - "applicationUrl": "http://localhost:5000", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} diff --git a/WebApiService/src/TestHost/Startup.cs b/WebApiService/src/TestHost/Startup.cs deleted file mode 100644 index ccb68a0..0000000 --- a/WebApiService/src/TestHost/Startup.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using Microsoft.OpenApi.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace TestHost -{ - public class Startup - { - - public void ConfigureServices(IServiceCollection services) - { - services.AddApplication(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) - { - app.InitializeApplication(); - } - } -} diff --git a/WebApiService/src/TestHost/TestHost.csproj b/WebApiService/src/TestHost/TestHost.csproj deleted file mode 100644 index 77d1cd4..0000000 --- a/WebApiService/src/TestHost/TestHost.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - net5.0 - - - - - - - - - - - - - diff --git a/WebApiService/src/TestHost/TestModule.cs b/WebApiService/src/TestHost/TestModule.cs deleted file mode 100644 index e8970ac..0000000 --- a/WebApiService/src/TestHost/TestModule.cs +++ /dev/null @@ -1,47 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Microsoft.OpenApi.Models; -using Volo.Abp; -using Volo.Abp.Modularity; - -namespace TestHost -{ - public class TestModule : AbpModule - - { - public override void ConfigureServices(ServiceConfigurationContext context) - { - var services = context.Services; - - services.AddControllers(); - services.AddSwaggerGen(c => - { - c.SwaggerDoc("v1", new OpenApiInfo { Title = "TestHost", Version = "v1" }); - }); - - } - - public override void OnApplicationInitialization(ApplicationInitializationContext context) - { - var app = context.GetApplicationBuilder(); - var env = context.GetEnvironment(); - - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseSwagger(); - app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "TestHost v1")); - } - - app.UseRouting(); - - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - }); - } - } -} \ No newline at end of file diff --git a/WebApiService/src/TestHost/WeatherForecast.cs b/WebApiService/src/TestHost/WeatherForecast.cs deleted file mode 100644 index e352ded..0000000 --- a/WebApiService/src/TestHost/WeatherForecast.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace TestHost -{ - public class WeatherForecast - { - public DateTime Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string Summary { get; set; } - } -} diff --git a/WebApiService/src/TestHost/appsettings.json b/WebApiService/src/TestHost/appsettings.json deleted file mode 100644 index d9d9a9b..0000000 --- a/WebApiService/src/TestHost/appsettings.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - }, - "AllowedHosts": "*" -} diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/appsettings.json b/WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/appsettings.json index 01c49ad..2b03383 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/appsettings.json +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/appsettings.json @@ -38,5 +38,5 @@ } } }, - "AlwaysAllowAuthorization": true + "AlwaysAllowAuthorization": false } \ No newline at end of file diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/BaererToken.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/BaererToken.cs new file mode 100644 index 0000000..3f06de4 --- /dev/null +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/BaererToken.cs @@ -0,0 +1,11 @@ +namespace Win_in.Sfs.Scp.WebApi.XmlHost +{ + public class BaererToken + { + public string access_token { get; set; } + public long expires_in { get; set; } + public string token_type { get; set; } + public string refresh_token { get; set; } + public string scope { get; set; } + } +} \ No newline at end of file diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/PartController.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/PartController.cs index 95c7c14..e9aa820 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/PartController.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/PartController.cs @@ -1,13 +1,7 @@ -using System; -using System.Diagnostics.Eventing.Reader; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Net.Http.Json; -using System.Net.Mime; +using System.Net.Mime; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using RestSharp; namespace Win_in.Sfs.Scp.WebApi.XmlHost.Controllers { @@ -33,6 +27,7 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost.Controllers public virtual async Task> CreateAsync([FromBody]PartCreateDto input) { + var dto = await _httpClientInvoker.InvokeAsync(input, RouteConsts.Part); return Ok(dto); diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/GlobalCache.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/GlobalCache.cs new file mode 100644 index 0000000..a26c640 --- /dev/null +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/GlobalCache.cs @@ -0,0 +1,7 @@ +namespace Win_in.Sfs.Scp.WebApi.XmlHost +{ + public static class GlobalCache + { + public static BaererToken BearerToken { get; set; } + } +} \ No newline at end of file diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/HttpClientInvoker.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/HttpClientInvoker.cs index 1dad908..3d822da 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/HttpClientInvoker.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/HttpClientInvoker.cs @@ -1,4 +1,5 @@ using System; +using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Net.Http.Json; @@ -6,6 +7,7 @@ using System.Runtime.Serialization; using System.Threading.Tasks; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Options; +using Volo.Abp.DependencyInjection; namespace Win_in.Sfs.Scp.WebApi.XmlHost { @@ -13,20 +15,39 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost public class HttpClientInvoker : IHttpClientInvoker { private readonly IConfiguration _configuration; + private readonly ITokenService _tokenService; - public HttpClientInvoker(IConfiguration configuration) + public HttpClientInvoker(IConfiguration configuration,ITokenService tokenService) { _configuration = configuration; + _tokenService = tokenService; } public async Task InvokeAsync(TInput input,string routeString) { var baseUrl = _configuration["RemoteServices:Default:BaseUrl"]; + + if (GlobalCache.BearerToken==null) + { + var token =await _tokenService.GetToken(baseUrl); + GlobalCache.BearerToken = token; + } + var client = new HttpClient(); client.BaseAddress = new Uri(baseUrl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = + new AuthenticationHeaderValue("Bearer", GlobalCache.BearerToken.access_token); var response = await client.PostAsJsonAsync(routeString, input); + if (response.StatusCode == HttpStatusCode.Unauthorized) + { + var token = await _tokenService.GetToken(baseUrl); + GlobalCache.BearerToken = token; + client.DefaultRequestHeaders.Authorization = + new AuthenticationHeaderValue("Bearer", GlobalCache.BearerToken.access_token); + response = await client.PostAsJsonAsync(routeString, input); + } response.EnsureSuccessStatusCode(); var dto = await response.Content.ReadFromJsonAsync(); diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/IHttpClientInvoker.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/IHttpClientInvoker.cs index 998cadc..1134a09 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/IHttpClientInvoker.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/IHttpClientInvoker.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; namespace Win_in.Sfs.Scp.WebApi.XmlHost { - public interface IHttpClientInvoker + public interface IHttpClientInvoker { Task InvokeAsync(TInput input,string routeString); } diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/ITokenService.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/ITokenService.cs new file mode 100644 index 0000000..77d39da --- /dev/null +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/ITokenService.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; + +namespace Win_in.Sfs.Scp.WebApi.XmlHost +{ + public interface ITokenService + { + Task GetToken(string baseUrl); + } +} \ No newline at end of file diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Logs/logs.txt b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Logs/logs.txt index 263a454..de90376 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Logs/logs.txt +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Logs/logs.txt @@ -5422,3 +5422,174 @@ System.Runtime.Serialization.InvalidDataContractException: Type 'Win_in.Sfs.Scp. 2022-01-12 17:38:33.402 +08:00 [INF] Executed action Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PurchaseOrderController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) in 3855.5986ms 2022-01-12 17:38:33.403 +08:00 [INF] Executed endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PurchaseOrderController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)' 2022-01-12 17:38:33.404 +08:00 [INF] Request finished HTTP/2 POST https://localhost:9977/api/scp/po application/xml 964 - 200 1410 application/xml;+charset=utf-8 3922.8488ms +2022-01-13 08:53:44.176 +08:00 [INF] Starting Win_in.Sfs.Scp.WebApi.Xml.Host. +2022-01-13 08:53:45.198 +08:00 [INF] User profile is available. Using 'C:\Users\changketec\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. +2022-01-13 08:53:46.004 +08:00 [INF] Now listening on: https://localhost:9977 +2022-01-13 08:53:46.005 +08:00 [INF] Application started. Press Ctrl+C to shut down. +2022-01-13 08:53:46.005 +08:00 [INF] Hosting environment: Development +2022-01-13 08:53:46.005 +08:00 [INF] Content root path: D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host +2022-01-13 08:53:48.372 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/index.html - - +2022-01-13 08:53:48.995 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/index.html - - - 200 - text/html;charset=utf-8 625.6764ms +2022-01-13 08:53:49.022 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - +2022-01-13 08:53:49.024 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - - 200 11964 application/javascript;+charset=utf-8 2.2176ms +2022-01-13 08:53:49.933 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - +2022-01-13 08:53:50.331 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 397.9020ms +2022-01-13 08:53:58.518 +08:00 [INF] Request starting HTTP/2 POST https://localhost:9977/api/scp/part application/xml 530 +2022-01-13 08:53:58.550 +08:00 [DBG] AuthenticationScheme: BasicAuthentication was successfully authenticated. +2022-01-13 08:53:58.554 +08:00 [INF] Authorization was successful. +2022-01-13 08:53:58.555 +08:00 [INF] Executing endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)' +2022-01-13 08:53:58.578 +08:00 [INF] Route matched with {action = "Create", controller = "Part"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.ActionResult`1[Win_in.Sfs.Scp.WebApi.PartDTO]] CreateAsync(Win_in.Sfs.Scp.WebApi.PartCreateDto) on controller Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController (Win_in.Sfs.Scp.WebApi.Xml.Host). +2022-01-13 08:54:05.184 +08:00 [INF] Executing action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) - Validation state: "Valid" +2022-01-13 08:55:18.395 +08:00 [INF] Executed action Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) in 79813.4276ms +2022-01-13 08:55:18.396 +08:00 [INF] Executed endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)' +2022-01-13 08:55:18.398 +08:00 [ERR] An unhandled exception has occurred while executing the request. +System.Net.Http.HttpRequestException: Response status code does not indicate success: 500 (Internal Server Error). + at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() + at Win_in.Sfs.Scp.WebApi.XmlHost.HttpClientInvoker`2.InvokeAsync(TInput input, String routeString) in D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host\HttpClientInvoker.cs:line 48 + at Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync(PartCreateDto input) in D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host\Controllers\PartController.cs:line 33 + at lambda_method5(Closure , Object ) + at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) + at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Logged|12_1(ControllerActionInvoker invoker) + at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) + at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) + at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) + at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) + at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) + at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context) + at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) + at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) + at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker) + at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) + at Microsoft.AspNetCore.Authorization.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult) + at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) + at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) + at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext) + at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) + at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) +2022-01-13 08:55:18.466 +08:00 [INF] Request finished HTTP/2 POST https://localhost:9977/api/scp/part application/xml 530 - 500 - text/plain 79948.9728ms +2022-01-13 08:56:16.120 +08:00 [INF] Starting Win_in.Sfs.Scp.WebApi.Xml.Host. +2022-01-13 08:56:17.134 +08:00 [INF] User profile is available. Using 'C:\Users\changketec\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. +2022-01-13 08:56:18.106 +08:00 [INF] Now listening on: https://localhost:9977 +2022-01-13 08:56:18.106 +08:00 [INF] Application started. Press Ctrl+C to shut down. +2022-01-13 08:56:18.106 +08:00 [INF] Hosting environment: Development +2022-01-13 08:56:18.106 +08:00 [INF] Content root path: D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host +2022-01-13 08:56:19.982 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/index.html - - +2022-01-13 08:56:20.458 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/index.html - - - 200 - text/html;charset=utf-8 479.1275ms +2022-01-13 08:56:20.488 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - +2022-01-13 08:56:20.499 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - - 200 11964 application/javascript;+charset=utf-8 10.8635ms +2022-01-13 08:56:21.434 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - +2022-01-13 08:56:21.828 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 393.4071ms +2022-01-13 08:56:26.014 +08:00 [INF] Request starting HTTP/2 POST https://localhost:9977/api/scp/part application/xml 530 +2022-01-13 08:56:26.045 +08:00 [DBG] AuthenticationScheme: BasicAuthentication was successfully authenticated. +2022-01-13 08:56:26.050 +08:00 [INF] Authorization was successful. +2022-01-13 08:56:26.051 +08:00 [INF] Executing endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)' +2022-01-13 08:56:26.074 +08:00 [INF] Route matched with {action = "Create", controller = "Part"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.ActionResult`1[Win_in.Sfs.Scp.WebApi.PartDTO]] CreateAsync(Win_in.Sfs.Scp.WebApi.PartCreateDto) on controller Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController (Win_in.Sfs.Scp.WebApi.Xml.Host). +2022-01-13 08:56:26.156 +08:00 [INF] Executing action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) - Validation state: "Valid" +2022-01-13 08:58:36.683 +08:00 [INF] Executed action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host), returned result Microsoft.AspNetCore.Mvc.OkObjectResult in 130523.7861ms. +2022-01-13 08:58:36.689 +08:00 [INF] Executing OkObjectResult, writing value of type 'Win_in.Sfs.Scp.WebApi.PartDTO'. +2022-01-13 08:58:36.700 +08:00 [INF] Executed action Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) in 130623.2582ms +2022-01-13 08:58:36.701 +08:00 [INF] Executed endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)' +2022-01-13 08:58:36.702 +08:00 [INF] Request finished HTTP/2 POST https://localhost:9977/api/scp/part application/xml 530 - 200 1021 application/xml;+charset=utf-8 130687.6750ms +2022-01-13 09:11:40.198 +08:00 [INF] Starting Win_in.Sfs.Scp.WebApi.Xml.Host. +2022-01-13 09:11:41.235 +08:00 [INF] User profile is available. Using 'C:\Users\changketec\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. +2022-01-13 09:11:41.857 +08:00 [INF] Now listening on: https://localhost:9977 +2022-01-13 09:11:41.857 +08:00 [INF] Application started. Press Ctrl+C to shut down. +2022-01-13 09:11:41.857 +08:00 [INF] Hosting environment: Development +2022-01-13 09:11:41.857 +08:00 [INF] Content root path: D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host +2022-01-13 09:11:43.551 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/index.html - - +2022-01-13 09:11:44.091 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/index.html - - - 200 - text/html;charset=utf-8 543.2222ms +2022-01-13 09:11:44.172 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - +2022-01-13 09:11:44.176 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - - 200 11964 application/javascript;+charset=utf-8 4.0994ms +2022-01-13 09:11:45.373 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - +2022-01-13 09:11:45.739 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 365.7910ms +2022-01-13 09:11:50.087 +08:00 [INF] Request starting HTTP/2 POST https://localhost:9977/api/scp/part application/xml 530 +2022-01-13 09:11:50.120 +08:00 [DBG] AuthenticationScheme: BasicAuthentication was successfully authenticated. +2022-01-13 09:11:50.125 +08:00 [INF] Authorization was successful. +2022-01-13 09:11:50.125 +08:00 [INF] Executing endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)' +2022-01-13 09:11:50.154 +08:00 [INF] Route matched with {action = "Create", controller = "Part"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.ActionResult`1[Win_in.Sfs.Scp.WebApi.PartDTO]] CreateAsync(Win_in.Sfs.Scp.WebApi.PartCreateDto) on controller Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController (Win_in.Sfs.Scp.WebApi.Xml.Host). +2022-01-13 09:11:50.237 +08:00 [INF] Executing action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) - Validation state: "Valid" +2022-01-13 09:11:57.235 +08:00 [INF] Executed action Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) in 7077.9874ms +2022-01-13 09:11:57.236 +08:00 [INF] Executed endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)' +2022-01-13 09:11:57.239 +08:00 [ERR] An unhandled exception has occurred while executing the request. +System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request). + at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() + at Win_in.Sfs.Scp.WebApi.XmlHost.TokenService.GetToken(String baseUrl) in D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host\TokenService.cs:line 41 + at Win_in.Sfs.Scp.WebApi.XmlHost.HttpClientInvoker`2.InvokeAsync(TInput input, String routeString) in D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host\HttpClientInvoker.cs:line 32 + at Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync(PartCreateDto input) in D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host\Controllers\PartController.cs:line 33 + at lambda_method5(Closure , Object ) + at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) + at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Logged|12_1(ControllerActionInvoker invoker) + at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) + at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) + at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) + at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) + at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) + at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context) + at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) + at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) + at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker) + at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) + at Microsoft.AspNetCore.Authorization.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult) + at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) + at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) + at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext) + at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) + at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) +2022-01-13 09:11:57.299 +08:00 [INF] Request finished HTTP/2 POST https://localhost:9977/api/scp/part application/xml 530 - 500 - text/plain 7212.5987ms +2022-01-13 09:12:56.964 +08:00 [INF] Starting Win_in.Sfs.Scp.WebApi.Xml.Host. +2022-01-13 09:12:58.076 +08:00 [INF] User profile is available. Using 'C:\Users\changketec\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. +2022-01-13 09:12:58.720 +08:00 [INF] Now listening on: https://localhost:9977 +2022-01-13 09:12:58.720 +08:00 [INF] Application started. Press Ctrl+C to shut down. +2022-01-13 09:12:58.720 +08:00 [INF] Hosting environment: Development +2022-01-13 09:12:58.720 +08:00 [INF] Content root path: D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host +2022-01-13 09:13:00.951 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/index.html - - +2022-01-13 09:13:01.950 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/index.html - - - 200 - text/html;charset=utf-8 1002.3584ms +2022-01-13 09:13:02.003 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - +2022-01-13 09:13:02.006 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - - 200 11964 application/javascript;+charset=utf-8 2.3672ms +2022-01-13 09:13:03.450 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - +2022-01-13 09:13:03.815 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 364.0941ms +2022-01-13 09:13:07.659 +08:00 [INF] Request starting HTTP/2 POST https://localhost:9977/api/scp/part application/xml 530 +2022-01-13 09:13:07.691 +08:00 [DBG] AuthenticationScheme: BasicAuthentication was successfully authenticated. +2022-01-13 09:13:07.696 +08:00 [INF] Authorization was successful. +2022-01-13 09:13:07.697 +08:00 [INF] Executing endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)' +2022-01-13 09:13:07.720 +08:00 [INF] Route matched with {action = "Create", controller = "Part"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.ActionResult`1[Win_in.Sfs.Scp.WebApi.PartDTO]] CreateAsync(Win_in.Sfs.Scp.WebApi.PartCreateDto) on controller Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController (Win_in.Sfs.Scp.WebApi.Xml.Host). +2022-01-13 09:13:07.805 +08:00 [INF] Executing action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) - Validation state: "Valid" +2022-01-13 09:13:20.421 +08:00 [INF] Executed action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host), returned result Microsoft.AspNetCore.Mvc.OkObjectResult in 12613.534ms. +2022-01-13 09:13:20.426 +08:00 [INF] Executing OkObjectResult, writing value of type 'Win_in.Sfs.Scp.WebApi.PartDTO'. +2022-01-13 09:13:20.438 +08:00 [INF] Executed action Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) in 12714.7336ms +2022-01-13 09:13:20.438 +08:00 [INF] Executed endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)' +2022-01-13 09:13:20.439 +08:00 [INF] Request finished HTTP/2 POST https://localhost:9977/api/scp/part application/xml 530 - 200 1021 application/xml;+charset=utf-8 12780.2266ms +2022-01-13 09:13:44.917 +08:00 [INF] Request starting HTTP/2 POST https://localhost:9977/api/scp/part application/xml 521 +2022-01-13 09:13:44.926 +08:00 [DBG] AuthenticationScheme: BasicAuthentication was successfully authenticated. +2022-01-13 09:13:44.926 +08:00 [INF] Authorization was successful. +2022-01-13 09:13:44.926 +08:00 [INF] Executing endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)' +2022-01-13 09:13:44.927 +08:00 [INF] Route matched with {action = "Create", controller = "Part"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.ActionResult`1[Win_in.Sfs.Scp.WebApi.PartDTO]] CreateAsync(Win_in.Sfs.Scp.WebApi.PartCreateDto) on controller Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController (Win_in.Sfs.Scp.WebApi.Xml.Host). +2022-01-13 09:13:44.943 +08:00 [INF] Executing action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) - Validation state: "Valid" +2022-01-13 09:14:07.260 +08:00 [INF] Executed action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host), returned result Microsoft.AspNetCore.Mvc.OkObjectResult in 22316.3022ms. +2022-01-13 09:14:07.260 +08:00 [INF] Executing OkObjectResult, writing value of type 'Win_in.Sfs.Scp.WebApi.PartDTO'. +2022-01-13 09:14:07.261 +08:00 [INF] Executed action Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) in 22334.6268ms +2022-01-13 09:14:07.262 +08:00 [INF] Executed endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)' +2022-01-13 09:14:07.262 +08:00 [INF] Request finished HTTP/2 POST https://localhost:9977/api/scp/part application/xml 521 - 200 1012 application/xml;+charset=utf-8 22344.2843ms +2022-01-13 09:16:27.324 +08:00 [INF] Starting Win_in.Sfs.Scp.WebApi.Xml.Host. +2022-01-13 09:16:28.196 +08:00 [INF] User profile is available. Using 'C:\Users\changketec\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. +2022-01-13 09:16:28.718 +08:00 [INF] Now listening on: https://localhost:9977 +2022-01-13 09:16:28.718 +08:00 [INF] Application started. Press Ctrl+C to shut down. +2022-01-13 09:16:28.718 +08:00 [INF] Hosting environment: Development +2022-01-13 09:16:28.718 +08:00 [INF] Content root path: D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host +2022-01-13 09:16:30.678 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/index.html - - +2022-01-13 09:16:31.284 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/index.html - - - 200 - text/html;charset=utf-8 608.6128ms +2022-01-13 09:16:31.544 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - +2022-01-13 09:16:31.549 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - - 200 11964 application/javascript;+charset=utf-8 5.0737ms +2022-01-13 09:16:32.254 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - +2022-01-13 09:16:32.607 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 353.1926ms +2022-01-13 09:18:00.106 +08:00 [INF] Request starting HTTP/2 POST https://localhost:9977/api/scp/part application/xml 543 +2022-01-13 09:18:00.139 +08:00 [DBG] AuthenticationScheme: BasicAuthentication was successfully authenticated. +2022-01-13 09:18:00.145 +08:00 [INF] Authorization was successful. +2022-01-13 09:18:00.145 +08:00 [INF] Executing endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)' +2022-01-13 09:18:00.168 +08:00 [INF] Route matched with {action = "Create", controller = "Part"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.ActionResult`1[Win_in.Sfs.Scp.WebApi.PartDTO]] CreateAsync(Win_in.Sfs.Scp.WebApi.PartCreateDto) on controller Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController (Win_in.Sfs.Scp.WebApi.Xml.Host). +2022-01-13 09:18:00.257 +08:00 [INF] Executing action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) - Validation state: "Valid" +2022-01-13 09:18:16.251 +08:00 [INF] Executed action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host), returned result Microsoft.AspNetCore.Mvc.OkObjectResult in 15989.5235ms. +2022-01-13 09:18:16.257 +08:00 [INF] Executing OkObjectResult, writing value of type 'Win_in.Sfs.Scp.WebApi.PartDTO'. +2022-01-13 09:18:16.269 +08:00 [INF] Executed action Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) in 16097.5245ms +2022-01-13 09:18:16.269 +08:00 [INF] Executed endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)' +2022-01-13 09:18:16.271 +08:00 [INF] Request finished HTTP/2 POST https://localhost:9977/api/scp/part application/xml 543 - 200 1034 application/xml;+charset=utf-8 16164.5237ms diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Startup.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Startup.cs index 5baa378..4828145 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Startup.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Startup.cs @@ -48,9 +48,11 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost services.Configure(configuration.GetSection("BasicAuthentication")); + services.Configure(configuration.GetSection("RemoteAuthentication")); + services.AddSingleton(typeof(IHttpClientInvoker<,>),typeof(HttpClientInvoker<,>)); + services.AddSingleton(); - } public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/TokenService.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/TokenService.cs new file mode 100644 index 0000000..9d94c16 --- /dev/null +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/TokenService.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Net.Http.Json; +using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; + +namespace Win_in.Sfs.Scp.WebApi.XmlHost +{ + public class TokenService:ITokenService + { + private readonly IConfiguration _configuration; + private readonly RemoteAuthenticationOptions _options; + + public TokenService(IConfiguration configuration,IOptions options) + { + _configuration = configuration; + _options = options.Value; + } + + public async Task GetToken(string baseUrl) + { + const string routeString = "connect/token"; + var client = new HttpClient(); + client.BaseAddress = new Uri(baseUrl); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + + var content = new FormUrlEncodedContent(new[] + { + new KeyValuePair("client_id",_options.client_id), + new KeyValuePair("client_secret",_options.client_secret), + new KeyValuePair("grant_type",_options.grant_type), + new KeyValuePair("username",_options.username), + new KeyValuePair("password",_options.password), + }); + + var response = await client.PostAsync(routeString, content); + response.EnsureSuccessStatusCode(); + + var dto = await response.Content.ReadFromJsonAsync(); + return dto; + + } + + + } + + public class RemoteAuthenticationOptions + { + public string client_id { get; set; } + public string client_secret { get; set; } + public string grant_type { get; set; } + public string username { get; set; } + public string password { get; set; } + } +} \ No newline at end of file diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Win_in.Sfs.Scp.WebApi.Xml.Host.csproj b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Win_in.Sfs.Scp.WebApi.Xml.Host.csproj index 4886366..981ede5 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Win_in.Sfs.Scp.WebApi.Xml.Host.csproj +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Win_in.Sfs.Scp.WebApi.Xml.Host.csproj @@ -8,7 +8,6 @@ - diff --git a/WebApiService/src/TestHost/appsettings.Development.json b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.Production.Development.json similarity index 100% rename from WebApiService/src/TestHost/appsettings.Development.json rename to WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.Production.Development.json diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.Production.json b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.Production.json new file mode 100644 index 0000000..00bd5e5 --- /dev/null +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.Production.json @@ -0,0 +1,20 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*", + + "RemoteServices": { + "Default": { + "BaseUrl": "https://scp.iacchina.net:9988/" + } + }, + "BasicAuthentication": { + "Username": "admin", + "Password": "admin" + } +} diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.json b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.json index 00bd5e5..119e934 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.json +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.json @@ -15,6 +15,13 @@ }, "BasicAuthentication": { "Username": "admin", - "Password": "admin" - } -} + "Password": "admin" + }, + "RemoteAuthentication": { + "client_id": "WebApi_App", + "client_secret": "1q2w3e*", + "grant_type": "password", + "username": "admin", + "password": "1q2w3E*" + } +} \ No newline at end of file