/// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="next"></param>
        /// <param name="services"></param>
        /// <param name="binding"></param>
        AspNetCoreServiceHostMiddleware(
            RequestDelegate next,
            IServiceProvider services,
            AspNetCoreBinding binding)
        {
            this.next     = next;
            this.services = services ?? throw new ArgumentNullException(nameof(services));
            this.binding  = binding ?? throw new ArgumentNullException(nameof(binding));
            this.router   = new AspNetCoreRequestRouter();
            this.baseUri  = AspNetCoreUri.GetUri("/" + Guid.NewGuid().ToString("N") + "/");

            // register for cleanup when application is stopped
            services.GetRequiredService <IApplicationLifetime>().ApplicationStopping.Register(() => host.Close());
        }
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="next"></param>
 /// <param name="services"></param>
 /// <param name="serviceType"></param>
 /// <param name="binding"></param>
 protected AspNetCoreServiceHostMiddleware(
     RequestDelegate next,
     IServiceProvider services,
     Type serviceType,
     AspNetCoreBinding binding) :
     this(next, services, binding)
 {
     this.host = new ServiceHost(serviceType, baseUri);
     host.Description.Behaviors.Add(new AspNetCoreServiceBehavior(router));
     host.Description.Behaviors.Add(new ServiceThrottlingBehavior()
     {
         MaxConcurrentSessions = 10
     });
 }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="next"></param>
        /// <param name="bindings"></param>
        /// <param name="router"></param>
        /// <param name="messageVersion"></param>
        /// <param name="logger"></param>
        /// <param name="applicationLifetime"></param>
        AspNetCoreServiceHostMiddleware(
            RequestDelegate next,
            AspNetCoreBindingFactory bindings,
            AspNetCoreRequestRouter router,
            MessageVersion messageVersion,
            IApplicationLifetime applicationLifetime,
            ILogger <AspNetCoreServiceHostMiddleware> logger,
            IServiceProvider serviceProvider)
        {
            this.next     = next;
            this.bindings = bindings ?? throw new ArgumentNullException(nameof(bindings));
            this.router   = router ?? throw new ArgumentNullException(nameof(router));

            // bindings for registered services
            httpBinding  = bindings.CreateBinding(serviceProvider, messageVersion, false);
            httpsBinding = bindings.CreateBinding(serviceProvider, messageVersion, true);

            // identifies this registered middleware route
            routeId = Guid.NewGuid();

            // listen on multiple URIs
            httpBaseUri  = new Uri($"http://{routeId:N}/");
            httpsBaseUri = new Uri($"https://{routeId:N}/");

            // register for cleanup when application is stopped
            applicationLifetime.ApplicationStopping.Register(() =>
            {
                try
                {
                    host.Close();
                }
                catch (Exception e)
                {
                    logger.LogError(e, "Exception closing ServiceHost.");
                }
            });
        }