How to configure MessagePack on SignalR with Owin and WebApi 2? - asp.net-web-api2

We have a SignalR service that runs as a self-hosted OWIN app with Web API 2. It is configured like
resolver.Register(typeof(JsonSerializer), () => JsonSerializer.Create(serializerSettings));
app.MapSignalR(new HubConfiguration { EnableDetailedErrors = true, Resolver = resolver});
We want to replace our JsonSerializer with MessagePack. The obvious examples all configure it from a AspNet.Core web application context. I can't seem to find any examples with Owin self hosting.
EDIT: It looks like MessagePack is a new ASP.NET Core feature. We are running the older ASP.NET version and so I guess the real question is how to do binary formatting over ASP.NET SignalR.

It's not possible. I am migrating my solution to the AspNetCore version of SignalR.

Related

OWIN Authentication, Authorization code migration from .net framework to .net 6 (Token based Authentication)

We have implemented OWIN Authorization to our Web Api's in .Net framework project. Now we are migrating this to .Net6. It seems in .net6/.net core owin authentication is not supported.
I don't find any documentation around this.
It seems Microsoft.Owin.OwinMiddleware is not exits in .net core.Also I don't find any Microsoft.Owin.Security.Infrastructure.AuthenticationTokenProvider corresponding nuget packages in .net core.
How can we use OWIN Authorization in .Net core(.net6)? If it is not supported what is alternative to this in .net core
ASP.NET Core using a new authentication middleware which could work like OWIN.
So you could directly using this middleware instead of using owin inside the asp.net core.
For example, if you want to include the MSFT, Goolge, facebook or else, you could refer to this article.

How to use Service Fabric service with AspNet Core WebApi and Autofac and run TestServer

I can't figure out how to use an AspNet Core 3.1 Web Api with Service Fabric and Autofac, and also how to have it ready for a TestServer to run for integration/functional testing.
The documentation is very incomplete.
Autofac documentation shows how to modify Program.cs to build autofac container, but it does not mention anything about the Startup.cs class that all the web api have:
https://autofaccn.readthedocs.io/en/latest/integration/servicefabric.html
Also the only example that Autofac has for service fabric is not a web api: https://github.com/autofac/Examples/tree/master/src/ServiceFabricDemo
There are other questions without valid answers:
Service Fabric AspNet Core 3.1 Autofac WebHostBuilder
Does anybody have any example on how to achieve this?
I can achieve the following (please see my GitHub repository with the sample)
Service fabric with stateless AspNet Core WebApi project (dotnet core 3.1)
Using Microsoft Dependency Injection to register services
Using TestServer to run integration tests on the http endpoint, and able to overwrite dependency injection registrations in a clean way without having to create another Startup class
I want the exact same, but using Autofac as DI container.
UPDATE 1:
I can't add Autofac to a WebHostBuilder and the ConfigureServices(IServiceCollection services) must be void as per AspNet Core 3.1+, so this is where I'm stuck. How to replace MS Dependency Injection in my sample
Event after the bounty there is not an answer to this. Maybe it's not possible as service fabric requires WebHost and not generic host.
In any case, I managed to have it working with older versions. Here's my repository where I show a sample on how to run AspNetCore2.1 with DotNetCore2.1 (LTS) and Autofac under Service Fabric. I use the webhost builder, not the generic one.
https://gitlab.com/sunnyatticsoftware/training/sasw-aspnetcore-testing/-/tree/master/aspnetcore2_1_autofac_servicefabric
Still, it'd be nice to eventually have a valid answer to the question.
I have NO idea if this works for the TestServer. It does however work fine with during ordinary hosting.
The exact thing you are looking for would be this line: services.Replace(ServiceDescriptor.Singleton<IServiceProviderFactory<ContainerBuilder>>(new AutofacServiceProviderFactory(null)));
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new[]
{
new ServiceInstanceListener(
serviceContext => new KestrelCommunicationListener(
serviceContext,
(url, listener) =>
{
return WebHost
.CreateDefaultBuilder()
.ConfigureServices(services =>
{
services.Replace(ServiceDescriptor.Singleton<IServiceProviderFactory<ContainerBuilder>>(new AutofacServiceProviderFactory(null)));
services.AddSingleton(serviceContext)
})
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.UseUniqueServiceUrl | ServiceFabricIntegrationOptions.UseReverseProxyIntegration)
.UseStartup<TStartupType>()
.Build();
}))
};
}
Hope it helps, it took me quite a while to arrive at this solution.

gRPC and ASP.NET Core: serverside reflection

I've been trying to implement the concepts of serverside reflection described in https://github.com/grpc/grpc/blob/master/doc/server-reflection.md and for C# https://github.com/grpc/grpc/blob/master/doc/csharp/server_reflection.md in the implementation of ASP.NET Core. You have to somehow configure Kestrel to enable Reflection first. I just don't succeed and have to give up. This is the tricky part that somehow has to be implemented in ASP.NET Core.
// the reflection service will be aware of "Greeter" and "ServerReflection" services.
var reflectionServiceImpl = new ReflectionServiceImpl(Greeter.Descriptor, ServerReflection.Descriptor);
server = new Server()
{
Services =
{
// the server will serve 2 services, the Greeter and the ServerReflection
ServerReflection.BindService(new GreeterImpl()),
ServerReflection.BindService(reflectionServiceImpl)
},
Ports = { { "localhost", 50051, ServerCredentials.Insecure } }
};
server.Start();
Does somebody know how to enable serverside reflection in ASP.NET Core with Kestrel? Or even better has a complete working example of serverside reflection in C# ASP.NET Core?
Update
It seems that the default implementation of .NET Core 3.1 doesn't support the reflection yet. The NuGet https://github.com/grpc/grpc-dotnet/ does work and seamlessly integrates in ASP.NET Core. The example covers discovering services on a server. I can't find concrete descriptions how to iterate through all methods on a service and all fields in a message. Maybe JamesNK can help?

ASP.NET Core middleware or OWIN middleware?

As I understand it, ASP.NET Core has support for OWIN middleware (via app.UseOwin()) in addition to its own native middleware.
What is the difference between ASP.NET Core middleware and OWIN middleware?
When designing a new middleware, how do I know if I should design it as a ASP.NET Core middleware or a OWIN middleware?
Your question made me curious and I would like to share, what I have learned so far.
Katana is the implementation of the OWIN spec. After version 3.0 of Katana this technology has been fully integration in the web stack we know as ASP.NET Core today.
While this transition much has stayed similar to the OWIN specifications. Although some changes have been made. In order to use existing OWIN middleware in ASP.NET Core the supports OWIN by an optional feature ("app.UseOwin()").
If you want to target with your middleware ASP.NET apps and ASP.NET core apps, then I would use OWIN middleware. If you want to give ASP.NET Core developers a first class citizen experience, then a ASP.NET Core middleware would be recognized as more "fitting".
Some information about the relationship between ASP.NET Core middleware and OWIN middleware can be found here:
Katana, ASP.NET 5, and bridging the gap
Katana Project
https://docs.asp.net/en/latest/fundamentals/owin.html
I have come to understand it as this; ASP.NET Core middleware is on a higher level than OWIN middleware which is on a lower level.
ASP.NET Core middleware has the advantage that it is much easier to develop a middleware in as you get passed in the HttpContext which you can use. The disadvantage is that the middleware you develop depends on ASP.NET Core.
OWIN is on a lower level and you get a OWIN environment which is a IDictionary<string, object>. The advantage is that is it not tied to ASP.NET hence can run on any OWIN server (such as Nowin). The disadvantage is that it takes more effort to code since you have to build your own context from the OWIN environment or use the OWIN environment dictionary directly and keep track of all OWIN keys and objects.
Edit: You don't have to keep track of OWIN keys yourself, you can use the OwinEnvironment class to get a strongly typed environment.
var environment = new OwinEnvironment(HttpContext);
var features = new OwinFeatureCollection(environment);

ASP.NET Core 1 app migrate to custom OWIN server

I know that asp.net core 1 application supports OWIN specification.So how can i migrate an application to my own custom web server where i will implement catching of http requests and creation of OWIN dictionary manually ?
you should implement owin pipeline beside asp.net core, it's not as an alternative
these two architecture can work beside together properly.
implementation of owin pipeline let you to use tools have not released in asp.net core such as OData, Thinktecture Identity server, ...
you can read this article to implement Owin pipeline
Implement Owin pipeline using Asp.net core
and you can download codes using Github