[英]Porting service host (over TCP, non Web) from .NET Framework 4.8 to .NET Core 3.1
I'm porting this service host (over TCP, non Web) from .NET Framework 4.8 to .NET Core 3.1:我正在将此服务主机(通过 TCP,非 Web)从 .NET Framework 4.8 移植到 .NET Core 3.1:
using (this._host = new ServiceHost(_receiver, new Uri("net.tcp://localhost:8065")))
{
this._host.OpenTimeout = TimeSpan.FromMinutes(5);
this._host.CloseTimeout = TimeSpan.FromMinutes(5);
var binding = new NetTcpBinding
{
CloseTimeout = TimeSpan.FromSeconds(15),
OpenTimeout = TimeSpan.FromSeconds(15),
SendTimeout = TimeSpan.FromSeconds(15),
ReceiveTimeout = TimeSpan.FromSeconds(15);
};
this._host.AddServiceEndpoint(typeof(IMessageReceiver), binding, "ISubscribe");
}
But there are not channel to get in this point (old code in .NET Framework 4.8):但是此时没有渠道可以进入(.NET Framework 4.8中的旧代码):
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single, InstanceContextMode = InstanceContextMode.Single,
IncludeExceptionDetailInFaults = true)]
public class MessageReceiver : IMessageReceiver
{
...
public bool Subscribe()
{
try
{
IMessageSender callback = OperationContext.Current.GetCallbackChannel<IMessageSender>();
if (!_subscribers.Contains(callback))
{
_subscribers.Add(callback);
Console.WriteLine("Subscriber");
}
return true;
}
catch (Exception e)
{
Console.WriteLine("Subscribe Exception" + e.ToString());
return false;
}
}
...
}
And i can't port this configuration in .NET Core:而且我无法在 .NET Core 中移植此配置:
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single, InstanceContextMode = InstanceContextMode.Single,
IncludeExceptionDetailInFaults = true)]
I'm trying with this:我正在尝试这个:
public static IWebHostBuilder CreateHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddMessageReceiverFramework(new IPEndPoint(IPAddress.Any, 8065));
})
.UseUrls("net.tcp://localhost:8065/ISubscribe")
.UseStartup<Startup>();
public static class MessageReceiverExtensionsAux
{
public static IServiceCollection AddMessageReceiverFramework(this IServiceCollection services,
IPEndPoint endPoint)
{
services.TryAddEnumerable(ServiceDescriptor.Singleton<IConfigureOptions<KestrelServerOptions>,
MessageReceiverOptionsSetup>());
services.Configure<MessageReceiverOptions>(o =>
{
o.EndPoint = endPoint;
});
services.TryAddSingleton<IMessageReceiver, MessageReceiver>();
return services;
}
}
I looking for best strategy for mantening same behavior on client side (.NET Framework 4.8).我正在寻找在客户端(.NET Framework 4.8)上维护相同行为的最佳策略。
Any suggestion?有什么建议吗?
Very thanks.很感谢。
I got CoreWCF.Http package: https://github.com/CoreWCF/CoreWCF我得到了 CoreWCF.Http package: https://github.com/CoreWCF/CoreWCF
using CoreWCF;
using CoreWCF.Configuration;
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
...
}).UseKestrel(options => {
options.ListenLocalhost(8080);
}).UseNetTcp(8808)
.UseStartup<Startup>();
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddServiceModelServices();
}
public void Configure(IApplicationBuilder app, IHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseServiceModel(builder =>
{
var bind = new NetTcpBinding();
builder
.AddService<MessageReceiver>()
.AddServiceEndpoint<MessageReceiver>(typeof(IMessageReceiver),bind, "/nettcp");
});
}
}
Not implement duplex channel.不实现双工通道。 But is good to me, whith new code for this inconvenience.
但对我来说很好,为这种不便添加了新代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.