I have a blazor server application to which I want to add a WCF NetTcp listening port. The regular Blazor Server Program.cs file is as follows:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
builder.Services.AddServerSizeBlazor();
builder.Services.AddSingleton<WeatherForecastService>();
builder.Services.AddServiceModelServices();
var app builder.Build()
This works as far as it starts the default web page in the browser. Now I want to add a WCF .Net Core "ServiceHost" that listens on address 'net.tcp://localhost:port'. I followed the advice in these two documents (one & two) and changed the above code to the following:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
builder.Services.AddServerSizeBlazor();
builder.Services.AddSingleton<WeatherForecastService>();
builder.Services.AddServiceModelServices()
.AddTransient<IContractExchange, ContractExchange>();
var app builder.Build();
app.UseServiceModel(serviceBuilder =>
{
serviceBuilder.AddService<ContractExchange>(serviceOptions => serviceOptions.DebugBehavior.IncludeExceptionDetailInFaults = true);
serviceBuilder.AddServiceEndpoint<ContractExchange, IContractExchange>(new NetTcpBinding(), "net.tcp://127.0.0.1:21701/Endpoint");
//serviceBuilder.OpenAsync();
});
and now when I start the app, the browser opens, the web page is served, but the server is not listening on the net.tcp port specified? If I try to open the port (commented out line above), I get a System.InvalidOperationException: "The communication object, CoreWCF.Configuration.ServiceBuilder, cannot be modified while it is in the Opened state" error.