Implement a ranking server
This commit is contained in:
parent
d3e98b0dbe
commit
e01cbdb5ac
8 changed files with 184 additions and 0 deletions
14
Tasks/Lab7/RankingServer/Competitor.cs
Normal file
14
Tasks/Lab7/RankingServer/Competitor.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System.Runtime.Serialization;
|
||||
|
||||
namespace RankingServer
|
||||
{
|
||||
[DataContract]
|
||||
public class Competitor
|
||||
{
|
||||
[DataMember]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string? Time { get; set; }
|
||||
}
|
||||
}
|
11
Tasks/Lab7/RankingServer/IRankingService.cs
Normal file
11
Tasks/Lab7/RankingServer/IRankingService.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using CoreWCF;
|
||||
|
||||
namespace RankingServer
|
||||
{
|
||||
[ServiceContract]
|
||||
public interface IRankingService
|
||||
{
|
||||
[OperationContract]
|
||||
List<Competitor> RankingList();
|
||||
}
|
||||
}
|
49
Tasks/Lab7/RankingServer/Program.cs
Normal file
49
Tasks/Lab7/RankingServer/Program.cs
Normal file
|
@ -0,0 +1,49 @@
|
|||
// See https://aka.ms/new-console-template for more information
|
||||
using RankingServer;
|
||||
using CoreWCF.Configuration;
|
||||
using CoreWCF.Description;
|
||||
using CoreWCF;
|
||||
using System.Net;
|
||||
|
||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.WebHost
|
||||
.ConfigureKestrel(
|
||||
(context, options) =>
|
||||
{
|
||||
options.AllowSynchronousIO = true;
|
||||
})
|
||||
.UseKestrel(
|
||||
(context, options) =>
|
||||
{
|
||||
options.Listen(IPAddress.Loopback, 5000);
|
||||
options.Listen(
|
||||
IPAddress.Loopback,
|
||||
5001,
|
||||
listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps();
|
||||
});
|
||||
});
|
||||
|
||||
// Add support
|
||||
builder.Services.AddServiceModelServices().AddServiceModelMetadata();
|
||||
builder.Services.AddSingleton<IServiceBehavior, UseRequestHeadersForMetadataAddressBehavior>();
|
||||
builder.Services.AddAuthorization();
|
||||
builder.Services.AddAuthentication();
|
||||
|
||||
WebApplication app = builder.Build();
|
||||
|
||||
app.UseServiceModel(
|
||||
builder =>
|
||||
{
|
||||
builder
|
||||
.AddService<RankingService>((serviceOptions) => { })
|
||||
.AddServiceEndpoint<RankingService, IRankingService>(new BasicHttpBinding(), "/RankingService/basichttp")
|
||||
.AddServiceEndpoint<RankingService, IRankingService>(new WSHttpBinding(SecurityMode.Transport), "/RankingService/WSHttps");
|
||||
});
|
||||
|
||||
ServiceMetadataBehavior serviceMetadataBehavior = app.Services.GetRequiredService<ServiceMetadataBehavior>();
|
||||
serviceMetadataBehavior.HttpGetEnabled = true;
|
||||
app.Logger.LogInformation("Starting Ranking Service…");
|
||||
app.Run();
|
10
Tasks/Lab7/RankingServer/Properties/appsettings.json
Normal file
10
Tasks/Lab7/RankingServer/Properties/appsettings.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"CoreWCF.Channels": "Warning",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
12
Tasks/Lab7/RankingServer/Properties/launchSettings.json
Normal file
12
Tasks/Lab7/RankingServer/Properties/launchSettings.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"profiles": {
|
||||
"RankingServer": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "https://localhost:59129;http://localhost:59130"
|
||||
}
|
||||
}
|
||||
}
|
15
Tasks/Lab7/RankingServer/RankingServer.csproj
Normal file
15
Tasks/Lab7/RankingServer/RankingServer.csproj
Normal file
|
@ -0,0 +1,15 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CoreWCF.Http" Version="1.5.2" />
|
||||
<PackageReference Include="CoreWCF.Primitives" Version="1.5.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
25
Tasks/Lab7/RankingServer/RankingServer.sln
Normal file
25
Tasks/Lab7/RankingServer/RankingServer.sln
Normal file
|
@ -0,0 +1,25 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.10.34928.147
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RankingServer", "RankingServer.csproj", "{81FE59F3-371E-4E80-A2C8-C93E03774EE9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{81FE59F3-371E-4E80-A2C8-C93E03774EE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{81FE59F3-371E-4E80-A2C8-C93E03774EE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{81FE59F3-371E-4E80-A2C8-C93E03774EE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{81FE59F3-371E-4E80-A2C8-C93E03774EE9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {3B55BFCE-E49B-4594-B364-4CF5D7D70E92}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
48
Tasks/Lab7/RankingServer/RankingService.cs
Normal file
48
Tasks/Lab7/RankingServer/RankingService.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
|
||||
namespace RankingServer
|
||||
{
|
||||
public class RankingService : IRankingService
|
||||
{
|
||||
private string[] ranks = {
|
||||
"Mueller Stefan,02:31:14",
|
||||
"Marti Adrian,2:30:09",
|
||||
"Kiptum Daniel,2:11:31",
|
||||
"Ancay Tarcis,2:20:02",
|
||||
"Kreibuhl Christian,2:21:47",
|
||||
"Ott Michael,2:33:48",
|
||||
"Menzi Christoph,2:27:26",
|
||||
"Oliver Ruben,2:32:12",
|
||||
"Elmer Beat,2:33:53",
|
||||
"Kuehni Martin,2:33:36"
|
||||
};
|
||||
|
||||
private Lazy<List<Competitor>> competitors;
|
||||
|
||||
public RankingService()
|
||||
{
|
||||
competitors = new Lazy<List<Competitor>>(
|
||||
() =>
|
||||
{
|
||||
List<Competitor> ranklingList = new List<Competitor>();
|
||||
foreach (string rank in ranks)
|
||||
{
|
||||
string[] fields = rank.Split(',');
|
||||
|
||||
Competitor competitor = new()
|
||||
{
|
||||
Name = fields[0],
|
||||
Time = fields[1]
|
||||
};
|
||||
|
||||
ranklingList.Add(competitor);
|
||||
};
|
||||
return ranklingList;
|
||||
});
|
||||
}
|
||||
|
||||
public List<Competitor> RankingList()
|
||||
{
|
||||
return competitors.Value;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue