-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathProgram.cs
More file actions
42 lines (34 loc) · 1.4 KB
/
Program.cs
File metadata and controls
42 lines (34 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
const int HttpPort = 5000;
const int NetTcpPort = 8089;
var builder = WebApplication.CreateBuilder();
builder.WebHost
.UseKestrel(options =>
{
options.ListenAnyIP(HttpPort);
})
.UseNetTcp(NetTcpPort);
//Enable CoreWCF Services, with metadata (WSDL) support
builder.Services.AddServiceModelServices()
.AddServiceModelMetadata()
.AddSingleton<IServiceBehavior, UseRequestHeadersForMetadataAddressBehavior>()
.AddSingleton<CalculatorService>();
var app = builder.Build();
app.UseServiceModel(builder =>
{
// Add the Calculator Service
builder.AddService<CalculatorService>(serviceOptions =>
{
serviceOptions.BaseAddresses.Clear();
// Set the default host name:port in generated WSDL and the base path for the address
serviceOptions.BaseAddresses.Add(new Uri("http://localhost/CalculatorService"));
serviceOptions.BaseAddresses.Add(new Uri($"net.tcp://localhost:{NetTcpPort}/CalculatorService"));
})
// Add NetTcpBinding endpoint
.AddServiceEndpoint<CalculatorService, ICalculatorService>(new NetTcpBinding(), "netTcp");
// Configure WSDL to be available
var serviceMetadataBehavior = app.Services.GetRequiredService<ServiceMetadataBehavior>();
serviceMetadataBehavior.HttpGetEnabled = true;
});
app.Run();