diff --git a/Counter/Counter.csproj b/Counter/Counter.csproj new file mode 100644 index 0000000..d88e446 --- /dev/null +++ b/Counter/Counter.csproj @@ -0,0 +1,19 @@ + + + net461 + win7-x64 + + + True + + + + + + + + + + + + \ No newline at end of file diff --git a/Counter/Counter.xproj b/Counter/Counter.xproj deleted file mode 100644 index 70ce0bb..0000000 --- a/Counter/Counter.xproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 58123bb4-8f73-43a2-9892-dfb465809e3d - Counter - .\obj - .\bin\ - v4.5.2 - - - 2.0 - - - diff --git a/Counter/Program.cs b/Counter/Program.cs index 53a7934..a58bb6a 100644 --- a/Counter/Program.cs +++ b/Counter/Program.cs @@ -2,23 +2,31 @@ using Microsoft.ServiceFabric.AspNetCore.Hosting; using Microsoft.ServiceFabric.Services.Runtime; using System.IO; +using System.Threading.Tasks; namespace Counter { public static class Program { public static void Main(string[] args) + { + MainAsync(args).GetAwaiter().GetResult(); + } + + private static async Task MainAsync(string[] args) { var communicationContext = CreateAspNetCoreCommunicationContext(); - ServiceRuntime.RegisterServiceAsync("CounterType", serviceContext => new CounterService(serviceContext, communicationContext)).GetAwaiter().GetResult(); + await communicationContext.WebHost.StartAsync(); + + await ServiceRuntime.RegisterServiceAsync("CounterType", serviceContext => new CounterService(serviceContext, communicationContext)); - communicationContext.WebHost.Run(); + await communicationContext.WebHost.WaitForShutdownAsync(); } private static AspNetCoreCommunicationContext CreateAspNetCoreCommunicationContext() { - var webHost = new WebHostBuilder().UseWebListener() + var webHost = new WebHostBuilder().UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup() .UseServiceFabricEndpoint("CounterTypeEndpoint") diff --git a/Counter/Properties/launchSettings.json b/Counter/Properties/launchSettings.json index ffe702e..dbf6848 100644 --- a/Counter/Properties/launchSettings.json +++ b/Counter/Properties/launchSettings.json @@ -1,9 +1,9 @@ -{ +{ "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:4003/", + "applicationUrl": "http://localhost:62539/", "sslPort": 0 } }, @@ -11,9 +11,19 @@ "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, + "launchUrl": "api/values", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } + }, + "Counter": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api/values", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "http://localhost:62540" } } -} \ No newline at end of file +} diff --git a/Counter/app.config b/Counter/app.config index b4252a4..49aadfa 100644 --- a/Counter/app.config +++ b/Counter/app.config @@ -1,5 +1,5 @@  - - - + + + diff --git a/Counter/appsettings.Development.json b/Counter/appsettings.Development.json new file mode 100644 index 0000000..fa8ce71 --- /dev/null +++ b/Counter/appsettings.Development.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/Counter/appsettings.json b/Counter/appsettings.json index cc127a8..5fff67b 100644 --- a/Counter/appsettings.json +++ b/Counter/appsettings.json @@ -2,9 +2,7 @@ "Logging": { "IncludeScopes": false, "LogLevel": { - "Default": "Verbose", - "System": "Information", - "Microsoft": "Information" + "Default": "Warning" } } } diff --git a/Counter/project.json b/Counter/project.json deleted file mode 100644 index 4dd3725..0000000 --- a/Counter/project.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "version": "1.0.0-*", - "buildOptions": { - "emitEntryPoint": true, - "preserveCompilationContext": true, - "compile": { - "exclude": [ - "PackageRoot" - ] - } - }, - "publishOptions": { - "include": [ - "appsettings.json" - ] - }, - "dependencies": { - "Microsoft.AspNetCore.Mvc.Core": "1.0.0", - "Microsoft.AspNetCore.Mvc.Formatters.Json": "1.0.0", - "Microsoft.AspNetCore.Server.WebListener": "0.1.0", - "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", - "Microsoft.Extensions.Configuration.Json": "1.0.0" - }, - "frameworks": { - "net452": { - "dependencies": { - "Microsoft.ServiceFabric": "5.2.207", - "Microsoft.ServiceFabric.AspNetCore.Hosting": "1.0.0-*", - "Microsoft.ServiceFabric.Services": "2.2.207" - } - } - }, - "runtimes": { - "win7-x64": {} - } -} diff --git a/Gateway/Gateway.csproj b/Gateway/Gateway.csproj new file mode 100644 index 0000000..c93441e --- /dev/null +++ b/Gateway/Gateway.csproj @@ -0,0 +1,20 @@ + + + net461 + win7-x64 + + + True + + + + + + + + + + + + + \ No newline at end of file diff --git a/Gateway/Gateway.xproj b/Gateway/Gateway.xproj deleted file mode 100644 index 27a9d75..0000000 --- a/Gateway/Gateway.xproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - ddedc25a-a4f1-413c-8ff3-8143768124e3 - Gateway - .\obj - .\bin\ - v4.5.2 - - - 2.0 - - - diff --git a/Gateway/Program.cs b/Gateway/Program.cs index dc483d2..6852469 100644 --- a/Gateway/Program.cs +++ b/Gateway/Program.cs @@ -2,18 +2,26 @@ using Microsoft.ServiceFabric.AspNetCore.Hosting; using Microsoft.ServiceFabric.Services.Runtime; using System.IO; +using System.Threading.Tasks; namespace Gateway { public static class Program { public static void Main(string[] args) + { + MainAsync(args).GetAwaiter().GetResult(); + } + + private static async Task MainAsync(string[] args) { var communicationContext = CreateAspNetCoreCommunicationContext(); - ServiceRuntime.RegisterServiceAsync("GatewayType", serviceContext => new GatewayService(serviceContext, communicationContext)).GetAwaiter().GetResult(); + await communicationContext.WebHost.StartAsync(); + + await ServiceRuntime.RegisterServiceAsync("GatewayType", serviceContext => new GatewayService(serviceContext, communicationContext)); - communicationContext.WebHost.Run(); + await communicationContext.WebHost.WaitForShutdownAsync(); } private static AspNetCoreCommunicationContext CreateAspNetCoreCommunicationContext() diff --git a/Gateway/Properties/launchSettings.json b/Gateway/Properties/launchSettings.json index 47e0e56..6abda8b 100644 --- a/Gateway/Properties/launchSettings.json +++ b/Gateway/Properties/launchSettings.json @@ -1,9 +1,9 @@ -{ +{ "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:12172/", + "applicationUrl": "http://localhost:62213/", "sslPort": 0 } }, @@ -11,9 +11,19 @@ "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, + "launchUrl": "api/values", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } + }, + "Gateway": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api/values", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "http://localhost:62214" } } -} \ No newline at end of file +} diff --git a/Gateway/Startup.cs b/Gateway/Startup.cs index ecbf310..b501d30 100644 --- a/Gateway/Startup.cs +++ b/Gateway/Startup.cs @@ -95,9 +95,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF app.MapWhen( context => { - StringValues serviceUri; - - return context.Request.Headers.TryGetValue("SF-ServiceUri", out serviceUri) && + return context.Request.Headers.TryGetValue("SF-ServiceUri", out StringValues serviceUri) && serviceUri.Count == 1 && serviceUri[0] == "fabric:/Hosting/CounterService"; }, diff --git a/Gateway/app.config b/Gateway/app.config index b4252a4..49aadfa 100644 --- a/Gateway/app.config +++ b/Gateway/app.config @@ -1,5 +1,5 @@  - - - + + + diff --git a/Gateway/appsettings.Development.json b/Gateway/appsettings.Development.json new file mode 100644 index 0000000..fa8ce71 --- /dev/null +++ b/Gateway/appsettings.Development.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/Gateway/appsettings.json b/Gateway/appsettings.json index cc127a8..5fff67b 100644 --- a/Gateway/appsettings.json +++ b/Gateway/appsettings.json @@ -2,9 +2,7 @@ "Logging": { "IncludeScopes": false, "LogLevel": { - "Default": "Verbose", - "System": "Information", - "Microsoft": "Information" + "Default": "Warning" } } } diff --git a/Gateway/project.json b/Gateway/project.json deleted file mode 100644 index cd49632..0000000 --- a/Gateway/project.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "version": "1.0.0-*", - "buildOptions": { - "emitEntryPoint": true, - "preserveCompilationContext": true, - "compile": { - "exclude": [ - "PackageRoot" - ] - } - }, - "publishOptions": { - "include": [ - "appsettings.json" - ] - }, - "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", - "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", - "Microsoft.Extensions.Configuration.Json": "1.0.0" - }, - "frameworks": { - "net452": { - "dependencies": { - "Microsoft.ServiceFabric": "5.2.207", - "Microsoft.ServiceFabric.AspNetCore.Gateway": "1.0.0-*", - "Microsoft.ServiceFabric.AspNetCore.Hosting": "1.0.0-*", - "Microsoft.ServiceFabric.Services": "2.2.207" - } - } - }, - "runtimes": { - "win7-x64": {} - } -} diff --git a/Hosting.TestClient/Hosting.TestClient.csproj b/Hosting.TestClient/Hosting.TestClient.csproj new file mode 100644 index 0000000..f94b956 --- /dev/null +++ b/Hosting.TestClient/Hosting.TestClient.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.0 + + + \ No newline at end of file diff --git a/Hosting.TestClient/Hosting.TestClient.xproj b/Hosting.TestClient/Hosting.TestClient.xproj deleted file mode 100644 index 175cb1e..0000000 --- a/Hosting.TestClient/Hosting.TestClient.xproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 659a8f69-543c-444e-8fa1-0814c021a80c - Hosting.TestClient - .\obj - .\bin\ - v4.5.2 - - - 2.0 - - - diff --git a/Hosting.TestClient/Program.cs b/Hosting.TestClient/Program.cs index 414018a..93cfea6 100644 --- a/Hosting.TestClient/Program.cs +++ b/Hosting.TestClient/Program.cs @@ -50,6 +50,9 @@ private static async Task RunTestsAsync(HttpClient client, CancellationToken can { try { + // WebApp + await client.GetAsync("/webapp", cancellationToken); + // SMS await client.PostAsync("/sms/api/sms/unicorn", new StringContent($"\"hello world! ({DateTimeOffset.UtcNow.ToString("u")})\"", Encoding.UTF8, "application/json"), cancellationToken); @@ -65,9 +68,6 @@ private static async Task RunTestsAsync(HttpClient client, CancellationToken can var request = new HttpRequestMessage(HttpMethod.Get, "/api/counter"); request.Headers.Add("SF-ServiceUri", "fabric:/Hosting/CounterService"); await client.SendAsync(request, cancellationToken); - - // WebApp - await client.GetAsync("/webapp", cancellationToken); } catch (Exception ex) { diff --git a/Hosting.TestClient/Properties/AssemblyInfo.cs b/Hosting.TestClient/Properties/AssemblyInfo.cs deleted file mode 100644 index 1b7c435..0000000 --- a/Hosting.TestClient/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Hosting.TestClient")] -[assembly: AssemblyTrademark("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("659a8f69-543c-444e-8fa1-0814c021a80c")] diff --git a/Hosting.TestClient/Properties/launchSettings.json b/Hosting.TestClient/Properties/launchSettings.json deleted file mode 100644 index 59600b3..0000000 --- a/Hosting.TestClient/Properties/launchSettings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "profiles": { - "Console": { - "executablePath": ".\\bin\\Debug\\net452\\win7-x64\\Hosting.TestClient.exe" - } - } -} \ No newline at end of file diff --git a/Hosting.TestClient/project.json b/Hosting.TestClient/project.json deleted file mode 100644 index 0b0a635..0000000 --- a/Hosting.TestClient/project.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": "1.0.0-*", - "buildOptions": { - "emitEntryPoint": true - }, - "dependencies": { - }, - "frameworks": { - "net452": { - "frameworkAssemblies": { - "System.Net.Http": "4.0.0.0" - } - } - }, - "runtimes": { - "win7-x64": {} - } -} diff --git a/Hosting.sln b/Hosting.sln index c19e3f0..fd401f8 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -1,23 +1,23 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio 15 +VisualStudioVersion = 15.0.26228.4 MinimumVisualStudioVersion = 10.0.40219.1 Project("{A07B5EB6-E848-4116-A8D0-A826331D98C6}") = "Hosting", "Hosting\Hosting.sfproj", "{89F3D30C-116E-4B3F-B362-0480A0E449A6}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Counter", "Counter\Counter.xproj", "{58123BB4-8F73-43A2-9892-DFB465809E3D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ServiceFabric.AspNetCore.Hosting", "Microsoft.ServiceFabric.AspNetCore.Hosting\Microsoft.ServiceFabric.AspNetCore.Hosting.csproj", "{0A68E3CE-9F8E-4BFF-A32E-88C1AE7DA360}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Gateway", "Gateway\Gateway.xproj", "{DDEDC25A-A4F1-413C-8FF3-8143768124E3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ServiceFabric.AspNetCore.Gateway", "Microsoft.ServiceFabric.AspNetCore.Gateway\Microsoft.ServiceFabric.AspNetCore.Gateway.csproj", "{C04AEEA4-228B-4E1E-8568-C62C1A4E3E81}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Sms", "Sms\Sms.xproj", "{998EBA46-CBBE-4712-929B-603E633EC48F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gateway", "Gateway\Gateway.csproj", "{68F0BB68-79D3-4E8F-A0A5-3B48C1E24933}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.ServiceFabric.AspNetCore.Hosting", "Microsoft.ServiceFabric.AspNetCore.Hosting\Microsoft.ServiceFabric.AspNetCore.Hosting.xproj", "{6EFAACB6-2CF0-42C6-AFC4-FFC1AEDB60A3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Counter", "Counter\Counter.csproj", "{BF6045E9-70B1-4572-AC94-D505F5CDD918}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.ServiceFabric.AspNetCore.Gateway", "Microsoft.ServiceFabric.AspNetCore.Gateway\Microsoft.ServiceFabric.AspNetCore.Gateway.xproj", "{E5D8CE99-9A88-49AA-8948-0E3C90C83257}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sms", "Sms\Sms.csproj", "{642B476B-D091-4D10-B794-8922F3191017}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Hosting.TestClient", "Hosting.TestClient\Hosting.TestClient.xproj", "{659A8F69-543C-444E-8FA1-0814C021A80C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApp", "WebApp\WebApp.csproj", "{AA4EA6E2-D39A-401F-8174-0394A208CC26}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "WebApp", "WebApp\WebApp.xproj", "{36B2D57D-3128-4575-AE02-626932AEB7A4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hosting.TestClient", "Hosting.TestClient\Hosting.TestClient.csproj", "{AE9C2F3C-4FAB-45F4-A6F6-09AB589EFC9E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -31,34 +31,34 @@ Global {89F3D30C-116E-4B3F-B362-0480A0E449A6}.Release|x64.ActiveCfg = Release|x64 {89F3D30C-116E-4B3F-B362-0480A0E449A6}.Release|x64.Build.0 = Release|x64 {89F3D30C-116E-4B3F-B362-0480A0E449A6}.Release|x64.Deploy.0 = Release|x64 - {58123BB4-8F73-43A2-9892-DFB465809E3D}.Debug|x64.ActiveCfg = Debug|Any CPU - {58123BB4-8F73-43A2-9892-DFB465809E3D}.Debug|x64.Build.0 = Debug|Any CPU - {58123BB4-8F73-43A2-9892-DFB465809E3D}.Release|x64.ActiveCfg = Release|Any CPU - {58123BB4-8F73-43A2-9892-DFB465809E3D}.Release|x64.Build.0 = Release|Any CPU - {DDEDC25A-A4F1-413C-8FF3-8143768124E3}.Debug|x64.ActiveCfg = Debug|Any CPU - {DDEDC25A-A4F1-413C-8FF3-8143768124E3}.Debug|x64.Build.0 = Debug|Any CPU - {DDEDC25A-A4F1-413C-8FF3-8143768124E3}.Release|x64.ActiveCfg = Release|Any CPU - {DDEDC25A-A4F1-413C-8FF3-8143768124E3}.Release|x64.Build.0 = Release|Any CPU - {998EBA46-CBBE-4712-929B-603E633EC48F}.Debug|x64.ActiveCfg = Debug|Any CPU - {998EBA46-CBBE-4712-929B-603E633EC48F}.Debug|x64.Build.0 = Debug|Any CPU - {998EBA46-CBBE-4712-929B-603E633EC48F}.Release|x64.ActiveCfg = Release|Any CPU - {998EBA46-CBBE-4712-929B-603E633EC48F}.Release|x64.Build.0 = Release|Any CPU - {6EFAACB6-2CF0-42C6-AFC4-FFC1AEDB60A3}.Debug|x64.ActiveCfg = Debug|Any CPU - {6EFAACB6-2CF0-42C6-AFC4-FFC1AEDB60A3}.Debug|x64.Build.0 = Debug|Any CPU - {6EFAACB6-2CF0-42C6-AFC4-FFC1AEDB60A3}.Release|x64.ActiveCfg = Release|Any CPU - {6EFAACB6-2CF0-42C6-AFC4-FFC1AEDB60A3}.Release|x64.Build.0 = Release|Any CPU - {E5D8CE99-9A88-49AA-8948-0E3C90C83257}.Debug|x64.ActiveCfg = Debug|Any CPU - {E5D8CE99-9A88-49AA-8948-0E3C90C83257}.Debug|x64.Build.0 = Debug|Any CPU - {E5D8CE99-9A88-49AA-8948-0E3C90C83257}.Release|x64.ActiveCfg = Release|Any CPU - {E5D8CE99-9A88-49AA-8948-0E3C90C83257}.Release|x64.Build.0 = Release|Any CPU - {659A8F69-543C-444E-8FA1-0814C021A80C}.Debug|x64.ActiveCfg = Debug|Any CPU - {659A8F69-543C-444E-8FA1-0814C021A80C}.Debug|x64.Build.0 = Debug|Any CPU - {659A8F69-543C-444E-8FA1-0814C021A80C}.Release|x64.ActiveCfg = Release|Any CPU - {659A8F69-543C-444E-8FA1-0814C021A80C}.Release|x64.Build.0 = Release|Any CPU - {36B2D57D-3128-4575-AE02-626932AEB7A4}.Debug|x64.ActiveCfg = Debug|Any CPU - {36B2D57D-3128-4575-AE02-626932AEB7A4}.Debug|x64.Build.0 = Debug|Any CPU - {36B2D57D-3128-4575-AE02-626932AEB7A4}.Release|x64.ActiveCfg = Release|Any CPU - {36B2D57D-3128-4575-AE02-626932AEB7A4}.Release|x64.Build.0 = Release|Any CPU + {0A68E3CE-9F8E-4BFF-A32E-88C1AE7DA360}.Debug|x64.ActiveCfg = Debug|Any CPU + {0A68E3CE-9F8E-4BFF-A32E-88C1AE7DA360}.Debug|x64.Build.0 = Debug|Any CPU + {0A68E3CE-9F8E-4BFF-A32E-88C1AE7DA360}.Release|x64.ActiveCfg = Release|Any CPU + {0A68E3CE-9F8E-4BFF-A32E-88C1AE7DA360}.Release|x64.Build.0 = Release|Any CPU + {C04AEEA4-228B-4E1E-8568-C62C1A4E3E81}.Debug|x64.ActiveCfg = Debug|Any CPU + {C04AEEA4-228B-4E1E-8568-C62C1A4E3E81}.Debug|x64.Build.0 = Debug|Any CPU + {C04AEEA4-228B-4E1E-8568-C62C1A4E3E81}.Release|x64.ActiveCfg = Release|Any CPU + {C04AEEA4-228B-4E1E-8568-C62C1A4E3E81}.Release|x64.Build.0 = Release|Any CPU + {68F0BB68-79D3-4E8F-A0A5-3B48C1E24933}.Debug|x64.ActiveCfg = Debug|Any CPU + {68F0BB68-79D3-4E8F-A0A5-3B48C1E24933}.Debug|x64.Build.0 = Debug|Any CPU + {68F0BB68-79D3-4E8F-A0A5-3B48C1E24933}.Release|x64.ActiveCfg = Release|Any CPU + {68F0BB68-79D3-4E8F-A0A5-3B48C1E24933}.Release|x64.Build.0 = Release|Any CPU + {BF6045E9-70B1-4572-AC94-D505F5CDD918}.Debug|x64.ActiveCfg = Debug|Any CPU + {BF6045E9-70B1-4572-AC94-D505F5CDD918}.Debug|x64.Build.0 = Debug|Any CPU + {BF6045E9-70B1-4572-AC94-D505F5CDD918}.Release|x64.ActiveCfg = Release|Any CPU + {BF6045E9-70B1-4572-AC94-D505F5CDD918}.Release|x64.Build.0 = Release|Any CPU + {642B476B-D091-4D10-B794-8922F3191017}.Debug|x64.ActiveCfg = Debug|Any CPU + {642B476B-D091-4D10-B794-8922F3191017}.Debug|x64.Build.0 = Debug|Any CPU + {642B476B-D091-4D10-B794-8922F3191017}.Release|x64.ActiveCfg = Release|Any CPU + {642B476B-D091-4D10-B794-8922F3191017}.Release|x64.Build.0 = Release|Any CPU + {AA4EA6E2-D39A-401F-8174-0394A208CC26}.Debug|x64.ActiveCfg = Debug|Any CPU + {AA4EA6E2-D39A-401F-8174-0394A208CC26}.Debug|x64.Build.0 = Debug|Any CPU + {AA4EA6E2-D39A-401F-8174-0394A208CC26}.Release|x64.ActiveCfg = Release|Any CPU + {AA4EA6E2-D39A-401F-8174-0394A208CC26}.Release|x64.Build.0 = Release|Any CPU + {AE9C2F3C-4FAB-45F4-A6F6-09AB589EFC9E}.Debug|x64.ActiveCfg = Debug|Any CPU + {AE9C2F3C-4FAB-45F4-A6F6-09AB589EFC9E}.Debug|x64.Build.0 = Debug|Any CPU + {AE9C2F3C-4FAB-45F4-A6F6-09AB589EFC9E}.Release|x64.ActiveCfg = Release|Any CPU + {AE9C2F3C-4FAB-45F4-A6F6-09AB589EFC9E}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Hosting/Hosting.sfproj b/Hosting/Hosting.sfproj index 0bd6743..7c0c0da 100644 --- a/Hosting/Hosting.sfproj +++ b/Hosting/Hosting.sfproj @@ -1,9 +1,10 @@  - - + + 89f3d30c-116e-4b3f-b362-0480a0e449a6 - 1.2 + 1.6 + 1.5 http://localhost:8000 @@ -29,10 +30,10 @@ - - - - + + + + @@ -42,5 +43,9 @@ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Service Fabric Tools\Microsoft.VisualStudio.Azure.Fabric.ApplicationProject.targets - + + + + + \ No newline at end of file diff --git a/Hosting/Scripts/Deploy-FabricApplication.ps1 b/Hosting/Scripts/Deploy-FabricApplication.ps1 index f3954db..2897b10 100644 --- a/Hosting/Scripts/Deploy-FabricApplication.ps1 +++ b/Hosting/Scripts/Deploy-FabricApplication.ps1 @@ -14,7 +14,7 @@ Path to the file containing the publish profile. .PARAMETER ApplicationPackagePath Path to the folder of the packaged Service Fabric application. -.PARAMETER DeloyOnly +.PARAMETER DeployOnly Indicates that the Service Fabric application should not be created or upgraded after registering the application type. .PARAMETER ApplicationParameter @@ -25,7 +25,7 @@ Indicates whether to unregister any unused application versions that exist after .PARAMETER OverrideUpgradeBehavior Indicates the behavior used to override the upgrade settings specified by the publish profile. -'None' indicates that the upgrade settings will not be overriden. +'None' indicates that the upgrade settings will not be overridden. 'ForceUpgrade' indicates that an upgrade will occur with default settings, regardless of what is specified in the publish profile. 'VetoUpgrade' indicates that an upgrade will not occur, regardless of what is specified in the publish profile. @@ -44,6 +44,9 @@ Switch signaling whether the package should be validated or not before deploymen .PARAMETER SecurityToken A security token for authentication to cluster management endpoints. Used for silent authentication to clusters that are protected by Azure Active Directory. +.PARAMETER CopyPackageTimeoutSec +Timeout in seconds for copying application package to image store. + .EXAMPLE . Scripts\Deploy-FabricApplication.ps1 -ApplicationPackagePath 'pkg\Debug' @@ -92,7 +95,10 @@ Param $SkipPackageValidation, [String] - $SecurityToken + $SecurityToken, + + [int] + $CopyPackageTimeoutSec ) function Read-XmlElementAsHashtable @@ -133,6 +139,7 @@ function Read-PublishProfile $publishProfile.ClusterConnectionParameters = Read-XmlElementAsHashtable $publishProfileXml.PublishProfile.Item("ClusterConnectionParameters") $publishProfile.UpgradeDeployment = Read-XmlElementAsHashtable $publishProfileXml.PublishProfile.Item("UpgradeDeployment") + $publishProfile.CopyPackageParameters = Read-XmlElementAsHashtable $publishProfileXml.PublishProfile.Item("CopyPackageParameters") if ($publishProfileXml.PublishProfile.Item("UpgradeDeployment")) { @@ -190,6 +197,29 @@ Import-Module "$ModuleFolderPath\ServiceFabricSDK.psm1" $IsUpgrade = ($publishProfile.UpgradeDeployment -and $publishProfile.UpgradeDeployment.Enabled -and $OverrideUpgradeBehavior -ne 'VetoUpgrade') -or $OverrideUpgradeBehavior -eq 'ForceUpgrade' +$PublishParameters = @{ + 'ApplicationPackagePath' = $ApplicationPackagePath + 'ApplicationParameterFilePath' = $publishProfile.ApplicationParameterFile + 'ApplicationParameter' = $ApplicationParameter + 'ErrorAction' = 'Stop' +} + +if ($publishProfile.CopyPackageParameters.CopyPackageTimeoutSec) +{ + $PublishParameters['CopyPackageTimeoutSec'] = $publishProfile.CopyPackageParameters.CopyPackageTimeoutSec +} + +if ($publishProfile.CopyPackageParameters.CompressPackage) +{ + $PublishParameters['CompressPackage'] = $publishProfile.CopyPackageParameters.CompressPackage +} + +# CopyPackageTimeoutSec parameter overrides the value from the publish profile +if ($CopyPackageTimeoutSec) +{ + $PublishParameters['CopyPackageTimeoutSec'] = $CopyPackageTimeoutSec +} + if ($IsUpgrade) { $Action = "RegisterAndUpgrade" @@ -206,7 +236,11 @@ if ($IsUpgrade) $UpgradeParameters = @{ UnmonitoredAuto = $true; Force = $true } } - Publish-UpgradedServiceFabricApplication -ApplicationPackagePath $ApplicationPackagePath -ApplicationParameterFilePath $publishProfile.ApplicationParameterFile -Action $Action -UpgradeParameters $UpgradeParameters -ApplicationParameter $ApplicationParameter -UnregisterUnusedVersions:$UnregisterUnusedApplicationVersionsAfterUpgrade -ErrorAction Stop + $PublishParameters['Action'] = $Action + $PublishParameters['UpgradeParameters'] = $UpgradeParameters + $PublishParameters['UnregisterUnusedVersions'] = $UnregisterUnusedApplicationVersionsAfterUpgrade + + Publish-UpgradedServiceFabricApplication @PublishParameters } else { @@ -215,6 +249,10 @@ else { $Action = "Register" } + + $PublishParameters['Action'] = $Action + $PublishParameters['OverwriteBehavior'] = $OverwriteBehavior + $PublishParameters['SkipPackageValidation'] = $SkipPackageValidation - Publish-NewServiceFabricApplication -ApplicationPackagePath $ApplicationPackagePath -ApplicationParameterFilePath $publishProfile.ApplicationParameterFile -Action $Action -ApplicationParameter $ApplicationParameter -OverwriteBehavior $OverwriteBehavior -SkipPackageValidation:$SkipPackageValidation -ErrorAction Stop + Publish-NewServiceFabricApplication @PublishParameters } \ No newline at end of file diff --git a/Hosting/packages.config b/Hosting/packages.config index 4e78606..ac0a51f 100644 --- a/Hosting/packages.config +++ b/Hosting/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/Microsoft.ServiceFabric.AspNetCore.Gateway/GatewayMiddleware.cs b/Microsoft.ServiceFabric.AspNetCore.Gateway/GatewayMiddleware.cs index b94e93e..35c3900 100644 --- a/Microsoft.ServiceFabric.AspNetCore.Gateway/GatewayMiddleware.cs +++ b/Microsoft.ServiceFabric.AspNetCore.Gateway/GatewayMiddleware.cs @@ -16,17 +16,12 @@ public class GatewayMiddleware public GatewayMiddleware(RequestDelegate next, HttpRequestDispatcherProvider dispatcherProvider, IOptions options) { - if (dispatcherProvider == null) - { - throw new ArgumentNullException(nameof(dispatcherProvider)); - } - if (options == null) { throw new ArgumentNullException(nameof(options)); } - _dispatcherProvider = dispatcherProvider; + _dispatcherProvider = dispatcherProvider ?? throw new ArgumentNullException(nameof(dispatcherProvider)); _options = options.Value; } @@ -76,7 +71,7 @@ await servicePartitionClient.InvokeWithRetryAsync(async dispatcher => { if (!requestMessage.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray()) && requestMessage.Content != null) { - requestMessage.Content.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray()); + requestMessage.Content?.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray()); } } diff --git a/Microsoft.ServiceFabric.AspNetCore.Gateway/HttpRequestDispatcherProvider.cs b/Microsoft.ServiceFabric.AspNetCore.Gateway/HttpRequestDispatcherProvider.cs index ab5b03b..9ab8db3 100644 --- a/Microsoft.ServiceFabric.AspNetCore.Gateway/HttpRequestDispatcherProvider.cs +++ b/Microsoft.ServiceFabric.AspNetCore.Gateway/HttpRequestDispatcherProvider.cs @@ -19,12 +19,7 @@ public HttpRequestDispatcherProvider(IServicePartitionResolver servicePartitionR public HttpRequestDispatcherProvider(Func innerDispatcherProvider, IServicePartitionResolver servicePartitionResolver = null, IEnumerable exceptionHandlers = null, string traceId = null) : base(servicePartitionResolver, exceptionHandlers, traceId) { - if (innerDispatcherProvider == null) - { - throw new ArgumentNullException(nameof(innerDispatcherProvider)); - } - - _innerDispatcherProvider = innerDispatcherProvider; + _innerDispatcherProvider = innerDispatcherProvider ?? throw new ArgumentNullException(nameof(innerDispatcherProvider)); } protected override void AbortClient(HttpRequestDispatcher dispatcher) diff --git a/Microsoft.ServiceFabric.AspNetCore.Gateway/Microsoft.ServiceFabric.AspNetCore.Gateway.csproj b/Microsoft.ServiceFabric.AspNetCore.Gateway/Microsoft.ServiceFabric.AspNetCore.Gateway.csproj new file mode 100644 index 0000000..6cd5c4b --- /dev/null +++ b/Microsoft.ServiceFabric.AspNetCore.Gateway/Microsoft.ServiceFabric.AspNetCore.Gateway.csproj @@ -0,0 +1,12 @@ + + + net461 + win7-x64 + + + + + + + + \ No newline at end of file diff --git a/Microsoft.ServiceFabric.AspNetCore.Gateway/Microsoft.ServiceFabric.AspNetCore.Gateway.xproj b/Microsoft.ServiceFabric.AspNetCore.Gateway/Microsoft.ServiceFabric.AspNetCore.Gateway.xproj deleted file mode 100644 index 1d79534..0000000 --- a/Microsoft.ServiceFabric.AspNetCore.Gateway/Microsoft.ServiceFabric.AspNetCore.Gateway.xproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - e5d8ce99-9a88-49aa-8948-0e3c90c83257 - Microsoft.ServiceFabric.AspNetCore.Gateway - .\obj - .\bin\ - v4.5.2 - - - 2.0 - - - diff --git a/Microsoft.ServiceFabric.AspNetCore.Gateway/Properties/AssemblyInfo.cs b/Microsoft.ServiceFabric.AspNetCore.Gateway/Properties/AssemblyInfo.cs deleted file mode 100644 index d50e2bf..0000000 --- a/Microsoft.ServiceFabric.AspNetCore.Gateway/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Microsoft.ServiceFabric.AspNetCore.Gateway")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft Corporation")] -[assembly: AssemblyProduct("Microsoft.ServiceFabric.AspNetCore.Gateway")] -[assembly: AssemblyCopyright("Copyright © Microsoft Corporation 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("e5d8ce99-9a88-49aa-8948-0e3c90c83257")] diff --git a/Microsoft.ServiceFabric.AspNetCore.Gateway/project.json b/Microsoft.ServiceFabric.AspNetCore.Gateway/project.json deleted file mode 100644 index 056adb0..0000000 --- a/Microsoft.ServiceFabric.AspNetCore.Gateway/project.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "version": "1.0.0-*", - "dependencies": { - "Microsoft.AspNetCore.Http.Abstractions": "1.0.0", - "Microsoft.Extensions.Options": "1.0.0" - }, - "frameworks": { - "net452": { - "dependencies": { - "Microsoft.ServiceFabric": "5.2.207", - "Microsoft.ServiceFabric.Services": "2.2.207" - }, - "frameworkAssemblies": { - "System.Net.Http": "4.0.0.0" - } - } - }, - "runtimes": { - "win7-x64": {} - } -} diff --git a/Microsoft.ServiceFabric.AspNetCore.Hosting/AspNetCoreCommunicationContext.cs b/Microsoft.ServiceFabric.AspNetCore.Hosting/AspNetCoreCommunicationContext.cs index b16fc2e..93f218d 100644 --- a/Microsoft.ServiceFabric.AspNetCore.Hosting/AspNetCoreCommunicationContext.cs +++ b/Microsoft.ServiceFabric.AspNetCore.Hosting/AspNetCoreCommunicationContext.cs @@ -10,12 +10,7 @@ public class AspNetCoreCommunicationContext { public AspNetCoreCommunicationContext(IWebHost webHost) { - if (webHost == null) - { - throw new ArgumentNullException(nameof(webHost)); - } - - WebHost = webHost; + WebHost = webHost ?? throw new ArgumentNullException(nameof(webHost)); } public IWebHost WebHost { get; } diff --git a/Microsoft.ServiceFabric.AspNetCore.Hosting/Internal/AspNetCoreCommunicationListener.cs b/Microsoft.ServiceFabric.AspNetCore.Hosting/Internal/AspNetCoreCommunicationListener.cs index f0b88f7..f9d76e5 100644 --- a/Microsoft.ServiceFabric.AspNetCore.Hosting/Internal/AspNetCoreCommunicationListener.cs +++ b/Microsoft.ServiceFabric.AspNetCore.Hosting/Internal/AspNetCoreCommunicationListener.cs @@ -4,7 +4,6 @@ using Microsoft.ServiceFabric.Services.Communication.Runtime; using Microsoft.ServiceFabric.Services.Runtime; using System; -using System.Collections.Generic; using System.Fabric; using System.Linq; using System.Threading; @@ -22,35 +21,15 @@ public class AspNetCoreCommunicationListener : ICommunicationListener public AspNetCoreCommunicationListener(AspNetCoreCommunicationContext context, StatelessService service) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - - if (service == null) - { - throw new ArgumentNullException(nameof(service)); - } - - _context = context; - _service = service; + _context = context ?? throw new ArgumentNullException(nameof(context)); + _service = service ?? throw new ArgumentNullException(nameof(service)); _registry = _context.WebHost.Services.GetService(); } public AspNetCoreCommunicationListener(AspNetCoreCommunicationContext context, StatefulService service) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - - if (service == null) - { - throw new ArgumentNullException(nameof(service)); - } - - _context = context; - _service = service; + _context = context ?? throw new ArgumentNullException(nameof(context)); + _service = service ?? throw new ArgumentNullException(nameof(service)); _registry = _context.WebHost.Services.GetService(); } @@ -60,8 +39,7 @@ public void Abort() { if (_registry != null) { - object service; - if (!_registry.TryRemove(_servicePathBase, out service)) + if (!_registry.TryRemove(_servicePathBase, out object service)) { throw new InvalidOperationException(); } @@ -72,8 +50,7 @@ public Task CloseAsync(CancellationToken cancellationToken) { if (_registry != null) { - object service; - if (!_registry.TryRemove(_servicePathBase, out service)) + if (!_registry.TryRemove(_servicePathBase, out object service)) { throw new InvalidOperationException(); } @@ -88,7 +65,8 @@ public Task OpenAsync(CancellationToken cancellationToken) var serverAddressesFeature = _context.WebHost.ServerFeatures.Get(); - IEnumerable addresses = serverAddressesFeature.Addresses.Select(address => address.Replace("+", ipAddressOrFQDN)); + var addresses = serverAddressesFeature.Addresses.Select(address => address.Replace("+", ipAddressOrFQDN) + .Replace("[::]", ipAddressOrFQDN)); // IPAddress.IPv6Any if (_registry != null) { diff --git a/Microsoft.ServiceFabric.AspNetCore.Hosting/Internal/ServiceFabricMiddleware.cs b/Microsoft.ServiceFabric.AspNetCore.Hosting/Internal/ServiceFabricMiddleware.cs index 40530da..7efbae4 100644 --- a/Microsoft.ServiceFabric.AspNetCore.Hosting/Internal/ServiceFabricMiddleware.cs +++ b/Microsoft.ServiceFabric.AspNetCore.Hosting/Internal/ServiceFabricMiddleware.cs @@ -12,12 +12,7 @@ public class ServiceFabricMiddleware public ServiceFabricMiddleware(RequestDelegate next) { - if (next == null) - { - throw new ArgumentNullException(nameof(next)); - } - - _next = next; + _next = next ?? throw new ArgumentNullException(nameof(next)); } public async Task Invoke(HttpContext context, ServiceFabricServiceRegistry registry, ServiceFabricServiceScope scope) @@ -37,18 +32,14 @@ public async Task Invoke(HttpContext context, ServiceFabricServiceRegistry regis throw new ArgumentNullException(nameof(scope)); } - PathString servicePathBase; - PathString remainingPath; - object service; - if (!registry.TryGet(context.Request.Path, out servicePathBase, out remainingPath, out service)) + if (!registry.TryGet(context.Request.Path, out PathString servicePathBase, out PathString remainingPath, out object service)) { context.Response.StatusCode = 503; return; } - StringValues pathBase; - if (context.Request.Headers.TryGetValue("X-ServiceFabric-PathBase", out pathBase)) + if (context.Request.Headers.TryGetValue("X-ServiceFabric-PathBase", out StringValues pathBase)) { servicePathBase = pathBase.FirstOrDefault(); } diff --git a/Microsoft.ServiceFabric.AspNetCore.Hosting/Microsoft.ServiceFabric.AspNetCore.Hosting.csproj b/Microsoft.ServiceFabric.AspNetCore.Hosting/Microsoft.ServiceFabric.AspNetCore.Hosting.csproj new file mode 100644 index 0000000..b4c75e7 --- /dev/null +++ b/Microsoft.ServiceFabric.AspNetCore.Hosting/Microsoft.ServiceFabric.AspNetCore.Hosting.csproj @@ -0,0 +1,11 @@ + + + net461 + win7-x64 + + + + + + + \ No newline at end of file diff --git a/Microsoft.ServiceFabric.AspNetCore.Hosting/Microsoft.ServiceFabric.AspNetCore.Hosting.xproj b/Microsoft.ServiceFabric.AspNetCore.Hosting/Microsoft.ServiceFabric.AspNetCore.Hosting.xproj deleted file mode 100644 index 838ffaf..0000000 --- a/Microsoft.ServiceFabric.AspNetCore.Hosting/Microsoft.ServiceFabric.AspNetCore.Hosting.xproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 6efaacb6-2cf0-42c6-afc4-ffc1aedb60a3 - Microsoft.ServiceFabric.AspNetCore.Hosting - .\obj - .\bin\ - v4.5.2 - - - 2.0 - - - diff --git a/Microsoft.ServiceFabric.AspNetCore.Hosting/Properties/AssemblyInfo.cs b/Microsoft.ServiceFabric.AspNetCore.Hosting/Properties/AssemblyInfo.cs deleted file mode 100644 index ee9adec..0000000 --- a/Microsoft.ServiceFabric.AspNetCore.Hosting/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Microsoft.ServiceFabric.AspNetCore.Hosting")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft Corporation")] -[assembly: AssemblyProduct("Microsoft.ServiceFabric.AspNetCore.Hosting")] -[assembly: AssemblyCopyright("Copyright © Microsoft Corporation 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("6efaacb6-2cf0-42c6-afc4-ffc1aedb60a3")] diff --git a/Microsoft.ServiceFabric.AspNetCore.Hosting/project.json b/Microsoft.ServiceFabric.AspNetCore.Hosting/project.json deleted file mode 100644 index dbd53f0..0000000 --- a/Microsoft.ServiceFabric.AspNetCore.Hosting/project.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": "1.0.0-*", - "dependencies": { - "Microsoft.AspNetCore.Hosting": "1.0.0", - "System.Collections.Immutable": "1.2.0" - }, - "frameworks": { - "net452": { - "dependencies": { - "Microsoft.ServiceFabric": "5.2.207", - "Microsoft.ServiceFabric.Services": "2.2.207" - } - } - }, - "runtimes": { - "win7-x64": {} - } -} diff --git a/README.md b/README.md index b41abbb..8a9cd08 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,10 @@ Please share your feedback to help us improve the experience in the future relea # How to Build & Run The Sample -1. Install Service Fabric runtime, SDK and tools for Visual Studio 2015 - 2.1.150: https://azure.microsoft.com/en-us/documentation/articles/service-fabric-get-started/ -2. Install .NET Core Tooling Preview 2 for Visual Studio 2015: https://www.microsoft.com/net/core#windows -3. Clone the repo. -4. Open Hosting.sln in Visual Studio 2015 as admin, and F5. -5. After the application is deployed to local dev cluster, right click Hosting.TestClient -> Debug -> Start new instance. +1. Prepare your development environment: https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-get-started. Note: The master branch only works with Visual Studio 2017. +2. Clone the repo. +3. Open Hosting.sln in Visual Studio 2017 as admin, and F5. +4. After the application is deployed to local dev cluster, right click Hosting.TestClient -> Debug -> Start new instance. # Key Code Snippets diff --git a/Sms/Program.cs b/Sms/Program.cs index 954ac99..ce6867c 100644 --- a/Sms/Program.cs +++ b/Sms/Program.cs @@ -2,18 +2,26 @@ using Microsoft.ServiceFabric.AspNetCore.Hosting; using Microsoft.ServiceFabric.Services.Runtime; using System.IO; +using System.Threading.Tasks; namespace Sms { public static class Program { public static void Main(string[] args) + { + MainAsync(args).GetAwaiter().GetResult(); + } + + private static async Task MainAsync(string[] args) { var communicationContext = CreateAspNetCoreCommunicationContext(); - ServiceRuntime.RegisterServiceAsync("SmsType", serviceContext => new SmsService(serviceContext, communicationContext)).GetAwaiter().GetResult(); + await communicationContext.WebHost.StartAsync(); + + await ServiceRuntime.RegisterServiceAsync("SmsType", serviceContext => new SmsService(serviceContext, communicationContext)); - communicationContext.WebHost.Run(); + await communicationContext.WebHost.WaitForShutdownAsync(); } private static AspNetCoreCommunicationContext CreateAspNetCoreCommunicationContext() diff --git a/Sms/Properties/launchSettings.json b/Sms/Properties/launchSettings.json index 0980b04..de22d50 100644 --- a/Sms/Properties/launchSettings.json +++ b/Sms/Properties/launchSettings.json @@ -1,9 +1,9 @@ -{ +{ "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:3210/", + "applicationUrl": "http://localhost:62681/", "sslPort": 0 } }, @@ -11,9 +11,19 @@ "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, + "launchUrl": "api/values", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } + }, + "Sms": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api/values", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "http://localhost:62682" } } -} \ No newline at end of file +} diff --git a/Sms/Sms.csproj b/Sms/Sms.csproj new file mode 100644 index 0000000..d88e446 --- /dev/null +++ b/Sms/Sms.csproj @@ -0,0 +1,19 @@ + + + net461 + win7-x64 + + + True + + + + + + + + + + + + \ No newline at end of file diff --git a/Sms/Sms.xproj b/Sms/Sms.xproj deleted file mode 100644 index ff367ff..0000000 --- a/Sms/Sms.xproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 998eba46-cbbe-4712-929b-603e633ec48f - Sms - .\obj - .\bin\ - v4.5.2 - - - 2.0 - - - diff --git a/Sms/app.config b/Sms/app.config index b4252a4..49aadfa 100644 --- a/Sms/app.config +++ b/Sms/app.config @@ -1,5 +1,5 @@  - - - + + + diff --git a/Sms/appsettings.Development.json b/Sms/appsettings.Development.json new file mode 100644 index 0000000..fa8ce71 --- /dev/null +++ b/Sms/appsettings.Development.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/Sms/appsettings.json b/Sms/appsettings.json index cc127a8..5fff67b 100644 --- a/Sms/appsettings.json +++ b/Sms/appsettings.json @@ -2,9 +2,7 @@ "Logging": { "IncludeScopes": false, "LogLevel": { - "Default": "Verbose", - "System": "Information", - "Microsoft": "Information" + "Default": "Warning" } } } diff --git a/Sms/project.json b/Sms/project.json deleted file mode 100644 index 5c0e81b..0000000 --- a/Sms/project.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "version": "1.0.0-*", - "buildOptions": { - "emitEntryPoint": true, - "preserveCompilationContext": true, - "compile": { - "exclude": [ - "PackageRoot" - ] - } - }, - "publishOptions": { - "include": [ - "appsettings.json" - ] - }, - "dependencies": { - "Microsoft.AspNetCore.Mvc.Core": "1.0.0", - "Microsoft.AspNetCore.Mvc.Formatters.Json": "1.0.0", - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", - "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", - "Microsoft.Extensions.Configuration.Json": "1.0.0" - }, - "frameworks": { - "net452": { - "dependencies": { - "Microsoft.ServiceFabric": "5.2.207", - "Microsoft.ServiceFabric.AspNetCore.Hosting": "1.0.0-*", - "Microsoft.ServiceFabric.Services": "2.2.207" - } - } - }, - "runtimes": { - "win7-x64": {} - } -} diff --git a/WebApp/Program.cs b/WebApp/Program.cs index 07200f8..c3c7b6b 100644 --- a/WebApp/Program.cs +++ b/WebApp/Program.cs @@ -2,18 +2,26 @@ using Microsoft.ServiceFabric.AspNetCore.Hosting; using Microsoft.ServiceFabric.Services.Runtime; using System.IO; +using System.Threading.Tasks; namespace WebApp { public class Program { public static void Main(string[] args) + { + MainAsync(args).GetAwaiter().GetResult(); + } + + private static async Task MainAsync(string[] args) { var communicationContext = CreateAspNetCoreCommunicationContext(); - ServiceRuntime.RegisterServiceAsync("WebAppType", serviceContext => new WebAppService(serviceContext, communicationContext)).GetAwaiter().GetResult(); + await communicationContext.WebHost.StartAsync(); + + await ServiceRuntime.RegisterServiceAsync("WebAppType", serviceContext => new WebAppService(serviceContext, communicationContext)); - communicationContext.WebHost.Run(); + await communicationContext.WebHost.WaitForShutdownAsync(); } private static AspNetCoreCommunicationContext CreateAspNetCoreCommunicationContext() diff --git a/WebApp/Properties/launchSettings.json b/WebApp/Properties/launchSettings.json index 1992985..0d0df98 100644 --- a/WebApp/Properties/launchSettings.json +++ b/WebApp/Properties/launchSettings.json @@ -1,9 +1,9 @@ -{ +{ "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:18701/", + "applicationUrl": "http://localhost:63026/", "sslPort": 0 } }, @@ -18,10 +18,10 @@ "WebApp": { "commandName": "Project", "launchBrowser": true, - "launchUrl": "http://localhost:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - } + }, + "applicationUrl": "http://localhost:63027" } } -} \ No newline at end of file +} diff --git a/WebApp/Views/Home/Index.cshtml b/WebApp/Views/Home/Index.cshtml index 3cd243d..e3f313d 100644 --- a/WebApp/Views/Home/Index.cshtml +++ b/WebApp/Views/Home/Index.cshtml @@ -15,7 +15,7 @@