Skip to content

Commit 7953522

Browse files
authored
Refact(touchsocket): Upgrade framework and dependent versions (#10171)
* 重构(project): 升级框架和依赖版本 升级目标框架至 net9.0,更新 TouchSocket 和 Hosting 相关依赖版本 调整 Program.cs 中变量声明为隐式类型,优化 Web API 配置方式 移除调试模式下的 Swagger 和浏览器启动功能 更新 Dockerfile 基础镜像至 .NET 9.0 * New (Project Configuration): Add TouchSocketHttp31 and TouchSocketWebAni31 Add TouchSocketHttp31 and TouchSocketWebAni31 projects to the solution -Update Benchmarks.sln to support new projects and upgrade VS version to 18 -Add new configuration items to benchmark∝json and config. toml -Add Dockerfiles for TouchSocketHttp31 and TouchSocketWebApp i31 -TouchSocketHttp project adds HTTP service program, supporting/plaintext and/json routing -TouchSocketWebApi project adds Web API service program, supporting/plaintext and/json routing -Add the configuration files' appsets.json 'and' appsettings. Development. json ' -The target frameworks for TouchSocketHttp31 and TouchSocketWebApp i31 projects are NET 8.0 -Add NuGet. Config to specify the unique package source as the official source of VNet * fix(touchsocket):build error * fix(touchsocket):build error x2 * update(touchsocket):nuget version to 4.0.0-beta.120
1 parent f343eb6 commit 7953522

19 files changed

+384
-43
lines changed

frameworks/CSharp/touchsocket/Benchmarks.sln

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 17
4-
VisualStudioVersion = 17.0.31717.71
3+
# Visual Studio Version 18
4+
VisualStudioVersion = 18.0.11109.219 d18.0-oob
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchSocketWebApi", "src\TouchSocketWebApi\TouchSocketWebApi.csproj", "{6BD9363A-D77F-5D90-8444-2BC37495C920}"
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchSocketHttp", "src\TouchSocketHttp\TouchSocketHttp.csproj", "{A7FB43AB-672B-8854-68D7-C2B383B0BC04}"
99
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchSocketHttp31", "src\TouchSocketHttp31\TouchSocketHttp31.csproj", "{DE261A06-A254-FD54-4ACF-EE4D4352BA77}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchSocketWebApi31", "src\TouchSocketWebApi31\TouchSocketWebApi31.csproj", "{6B6A57CE-1F69-FA6E-7458-0A4B6AB60683}"
13+
EndProject
1014
Global
1115
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1216
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +25,14 @@ Global
2125
{A7FB43AB-672B-8854-68D7-C2B383B0BC04}.Debug|Any CPU.Build.0 = Debug|Any CPU
2226
{A7FB43AB-672B-8854-68D7-C2B383B0BC04}.Release|Any CPU.ActiveCfg = Release|Any CPU
2327
{A7FB43AB-672B-8854-68D7-C2B383B0BC04}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{DE261A06-A254-FD54-4ACF-EE4D4352BA77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{DE261A06-A254-FD54-4ACF-EE4D4352BA77}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{DE261A06-A254-FD54-4ACF-EE4D4352BA77}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{DE261A06-A254-FD54-4ACF-EE4D4352BA77}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{6B6A57CE-1F69-FA6E-7458-0A4B6AB60683}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{6B6A57CE-1F69-FA6E-7458-0A4B6AB60683}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{6B6A57CE-1F69-FA6E-7458-0A4B6AB60683}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{6B6A57CE-1F69-FA6E-7458-0A4B6AB60683}.Release|Any CPU.Build.0 = Release|Any CPU
2436
EndGlobalSection
2537
GlobalSection(SolutionProperties) = preSolution
2638
HideSolutionNode = FALSE

frameworks/CSharp/touchsocket/benchmark_config.json

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"port": 8080,
99
"approach": "Realistic",
1010
"classification": "Fullstack",
11+
"database": "Postgres",
1112
"framework": "touchsocket.webapi",
1213
"language": "C#",
1314
"orm": "Raw",
@@ -38,7 +39,45 @@
3839
"display_name": "touchsocket.http",
3940
"notes": "",
4041
"versus": "aspnetcore"
42+
},
43+
"http31": {
44+
"plaintext_url": "/plaintext",
45+
"json_url": "/json",
46+
"port": 8080,
47+
"approach": "Realistic",
48+
"classification": "Micro",
49+
"database": "Postgres",
50+
"framework": "touchsocket.http31",
51+
"language": "C#",
52+
"orm": "Micro",
53+
"platform": ".NET",
54+
"flavor": "CoreCLR",
55+
"webserver": "touchsocket",
56+
"os": "Linux",
57+
"database_os": "Linux",
58+
"display_name": "touchsocket.http31",
59+
"notes": "",
60+
"versus": "aspnetcore"
61+
},
62+
"webapi31": {
63+
"plaintext_url": "/plaintext",
64+
"json_url": "/json",
65+
"port": 8080,
66+
"approach": "Realistic",
67+
"classification": "Fullstack",
68+
"database": "Postgres",
69+
"framework": "touchsocket.webapi31",
70+
"language": "C#",
71+
"orm": "Raw",
72+
"platform": ".NET",
73+
"flavor": "CoreCLR",
74+
"webserver": "touchsocket",
75+
"os": "Linux",
76+
"database_os": "Linux",
77+
"display_name": "touchsocket.webapi31",
78+
"notes": "",
79+
"versus": "aspnetcore-mvc"
4180
}
4281
}
4382
]
44-
}
83+
}

frameworks/CSharp/touchsocket/config.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,29 @@ orm = "Raw"
2626
platform = ".NET"
2727
webserver = "touchsocket.http"
2828
versus = "aspcore"
29+
30+
[http31]
31+
urls.plaintext = "/plaintext"
32+
urls.json = "/json"
33+
approach = "Realistic"
34+
classification = "Micro"
35+
database = "Postgres"
36+
database_os = "Linux"
37+
os = "Linux"
38+
orm = "Raw"
39+
platform = ".NET"
40+
webserver = "touchsocket.http31"
41+
versus = "aspcore"
42+
43+
[webapi31]
44+
urls.plaintext = "/plaintext"
45+
urls.json = "/json"
46+
approach = "Realistic"
47+
classification = "Fullstack"
48+
database = "Postgres"
49+
database_os = "Linux"
50+
os = "Linux"
51+
orm = "Raw"
52+
platform = ".NET"
53+
webserver = "touchsocket.webapi31"
54+
versus = "aspcore-mvc"

frameworks/CSharp/touchsocket/src/TouchSocketHttp/Program.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public class Program
1010
{
1111
private static async Task Main(string[] args)
1212
{
13-
int port = 8080;
14-
MyHttpService service = new MyHttpService();
13+
var port = 8080;
14+
var service = new MyHttpService();
1515

1616
await service.SetupAsync(new TouchSocketConfig()
1717
.SetListenIPHosts(port)
@@ -22,7 +22,6 @@ await service.SetupAsync(new TouchSocketConfig()
2222
options.SendPipeOptions = TransportOption.CreateSchedulerOptimizedPipeOptions();
2323
})
2424
.SetMaxCount(1000000)
25-
.SetBacklog(1000)
2625
.ConfigureContainer(a =>
2726
{
2827
a.AddConsoleLogger();
@@ -52,8 +51,8 @@ internal sealed class MyHttpSessionClient : HttpSessionClient
5251

5352
protected override async Task OnReceivedHttpRequest(HttpContext httpContext)
5453
{
55-
HttpRequest request = httpContext.Request;
56-
HttpResponse response = httpContext.Response;
54+
var request = httpContext.Request;
55+
var response = httpContext.Response;
5756

5857
switch (request.RelativeURL)
5958
{
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk.Worker">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<OutputType>Exe</OutputType>
77
<ImplicitUsings>enable</ImplicitUsings>
8-
<InvariantGlobalization>true</InvariantGlobalization>
9-
<!--<PublishAot>true</PublishAot>-->
108
<UserSecretsId>dotnet-TouchSocketWebApi-987c185f-10b1-452b-beb6-47d798a5a131</UserSecretsId>
11-
<ServerGarbageCollection>true</ServerGarbageCollection>
129
</PropertyGroup>
1310

1411
<ItemGroup>
15-
<PackageReference Include="TouchSocket.Http" Version="4.0.0-beta.80" />
12+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
13+
<PackageReference Include="TouchSocket.Hosting" Version="4.0.0-beta.120" />
14+
<PackageReference Include="TouchSocket.WebApi" Version="4.0.0-beta.120" />
1615
</ItemGroup>
1716
</Project>
17+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<clear />
5+
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
6+
</packageSources>
7+
</configuration>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using System.Text;
2+
using TouchSocket.Core;
3+
using TouchSocket.Http;
4+
using TouchSocket.Sockets;
5+
using static System.Net.Mime.MediaTypeNames;
6+
using HttpContent = TouchSocket.Http.HttpContent;
7+
8+
namespace TouchSocketHttp;
9+
10+
public class Program
11+
{
12+
static async Task Main(string[] args)
13+
{
14+
int port = 8080;
15+
16+
Console.WriteLine(DateHelper.DateString);
17+
var service = new MyHttpService();
18+
19+
await service.SetupAsync(new TouchSocketConfig()
20+
.SetListenIPHosts(port)
21+
.SetNoDelay(true)
22+
.SetMaxCount(1000000)
23+
.ConfigureContainer(a =>
24+
{
25+
a.AddConsoleLogger();
26+
}));
27+
28+
await service.StartAsync();
29+
service.Logger.Info($"server is started,port:{port}");
30+
while (true)
31+
{
32+
Console.ReadLine();
33+
}
34+
}
35+
}
36+
37+
sealed class MyHttpService : HttpService<MyHttpSessionClient>
38+
{
39+
protected override MyHttpSessionClient NewClient()
40+
{
41+
return new MyHttpSessionClient();
42+
}
43+
}
44+
45+
sealed class MyHttpSessionClient : HttpSessionClient
46+
{
47+
private readonly HttpContent m_contentPlaintext = new StringHttpContent("Hello, World!", Encoding.UTF8, $"text/plain");
48+
private readonly HttpContent m_contentJson = new StringHttpContent("{\"message\":\"Hello, World!\"}", Encoding.UTF8, $"application/json");
49+
50+
protected override async Task OnReceivedHttpRequest(HttpContext httpContext)
51+
{
52+
var request = httpContext.Request;
53+
var response = httpContext.Response;
54+
55+
switch (request.RelativeURL)
56+
{
57+
case "/plaintext":
58+
{
59+
response.StatusCode = 200;
60+
response.StatusMessage = "success";
61+
response.Headers.Add(HttpHeaders.Server, "T");
62+
response.Headers.Add(HttpHeaders.Date, DateHelper.DateString);
63+
response.Content = m_contentPlaintext;
64+
await response.AnswerAsync().ConfigureAwait(false);
65+
}
66+
break;
67+
case "/json":
68+
{
69+
response.StatusCode = 200;
70+
response.StatusMessage = "success";
71+
response.Headers.Add(HttpHeaders.Server, "T");
72+
response.Headers.Add(HttpHeaders.Date, DateHelper.DateString);
73+
response.Content = m_contentJson;
74+
await response.AnswerAsync().ConfigureAwait(false);
75+
}
76+
break;
77+
default:
78+
response.SetStatus(404, "not find");
79+
await response.AnswerAsync().ConfigureAwait(false);
80+
break;
81+
}
82+
}
83+
}
84+
85+
static class DateHelper
86+
{
87+
static Timer m_timer;
88+
static DateHelper()
89+
{
90+
DateString = DateTime.UtcNow.ToGMTString();
91+
m_timer = new Timer((state) =>
92+
{
93+
DateString = DateTime.UtcNow.ToGMTString();
94+
}, null, 0, 1000);
95+
}
96+
97+
public static string DateString { get; private set; }
98+
}
99+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<OutputType>Exe</OutputType>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<InvariantGlobalization>true</InvariantGlobalization>
9+
<!--<PublishAot>true</PublishAot>-->
10+
<UserSecretsId>dotnet-TouchSocketWebApi-987c185f-10b1-455b-beb6-47d798a5a131</UserSecretsId>
11+
<ServerGarbageCollection>true</ServerGarbageCollection>
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="TouchSocket.Http" Version="3.1.0" />
16+
</ItemGroup>
17+
</Project>

frameworks/CSharp/touchsocket/src/TouchSocketWebApi/Program.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public static void Main(string[] args)
2525
options.SendPipeOptions = TransportOption.CreateSchedulerOptimizedPipeOptions();
2626
})
2727
.SetMaxCount(1000000)
28-
.SetBacklog(1000)
2928
.ConfigureContainer(a =>
3029
{
3130
a.AddConsoleLogger();
@@ -36,28 +35,23 @@ public static void Main(string[] args)
3635
})
3736
.ConfigurePlugins(a =>
3837
{
39-
a.UseTcpSessionCheckClear();
40-
41-
a.UseWebApi()
42-
.ConfigureConverter(converter =>
38+
a.UseWebApi(options =>
4339
{
44-
converter.Clear();
45-
converter.AddSystemTextJsonSerializerFormatter(options =>
40+
options.ConfigureConverter(converter =>
4641
{
47-
options.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
42+
converter.Clear();
43+
converter.AddSystemTextJsonSerializerFormatter(jsonOptions =>
44+
{
45+
jsonOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
46+
});
4847
});
4948
});
5049

51-
#if DEBUG
52-
a.UseSwagger()
53-
.UseLaunchBrowser();
54-
#endif
55-
5650
a.UseDefaultHttpServicePlugin();
5751
});
5852
});
5953

60-
IHost host = builder.Build();
54+
var host = builder.Build();
6155
host.Run();
6256
}
6357
}
@@ -72,7 +66,7 @@ public partial class ApiServer : SingletonRpcServer
7266
[WebApi(Method = HttpMethodType.Get)]
7367
public async Task Plaintext(IWebApiCallContext callContext)
7468
{
75-
HttpResponse response = callContext.HttpContext.Response;
69+
var response = callContext.HttpContext.Response;
7670
response.SetStatus(200, "ok");
7771
response.Content = m_contentPlaintext;
7872
await response.AnswerAsync().ConfigureAwait(false);
@@ -86,7 +80,7 @@ public MyJson Json()
8680
}
8781
}
8882

89-
[JsonSerializable(typeof(MyJson))]//ʵ¼ÊÀàÐÍ1
83+
[JsonSerializable(typeof(MyJson))]
9084
internal partial class AppJsonSerializerContext : JsonSerializerContext
9185
{
9286

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
<Project Sdk="Microsoft.NET.Sdk.Worker">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
7-
<InvariantGlobalization>true</InvariantGlobalization>
8-
<!--<PublishAot>true</PublishAot>-->
9-
<UserSecretsId>dotnet-TouchSocketWebApi-987c185f-10b1-452b-beb6-47d798a5a131</UserSecretsId>
10-
<ServerGarbageCollection>true</ServerGarbageCollection>
7+
<UserSecretsId>dotnet-WorkerService1-19b37b17-6043-4334-ad9a-9e0e3c670da3</UserSecretsId>
118
</PropertyGroup>
129

1310
<ItemGroup>
14-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
15-
<PackageReference Include="TouchSocket.Hosting" Version="4.0.0-beta.80" />
16-
<PackageReference Include="TouchSocket.WebApi" Version="4.0.0-beta.80" />
17-
<PackageReference Include="TouchSocket.WebApi.Swagger" Version="4.0.0-beta.80" />
11+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
12+
<PackageReference Include="TouchSocket.Hosting" Version="4.0.0-beta.120" />
13+
<PackageReference Include="TouchSocket.WebApi" Version="4.0.0-beta.120" />
1814
</ItemGroup>
1915
</Project>

0 commit comments

Comments
 (0)