예제 #1
0
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="next"></param>
 /// <param name="router"></param>
 /// <param name="options"></param>
 /// <param name="applicationLifetime"></param>
 /// <param name="serviceProvider"></param>
 public AspNetCoreServiceHostMiddleware(
     RequestDelegate next,
     AspNetCoreRequestRouter router,
     AspNetCoreServiceHostOptions options,
     IApplicationLifetime applicationLifetime,
     ILogger <AspNetCoreServiceHostMiddleware> logger,
     IServiceProvider serviceProvider) :
     this(next, options.ServiceType, CreateBindingFactory(serviceProvider, options.BindingFactoryType), router, options.MessageVersion, applicationLifetime, logger, serviceProvider)
 {
     options.Configure?.Invoke(new AspNetCoreServiceHostConfigurator(this));
 }
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="router"></param>
 /// <param name="transportElement"></param>
 /// <param name="context"></param>
 public AspNetCoreReplyChannelListener(
     AspNetCoreRequestRouter router,
     AspNetCoreTransportBindingElement transportElement,
     BindingContext context) :
     base(context.Binding)
 {
     this.router         = router ?? throw new ArgumentNullException(nameof(router));
     this.bufferManager  = BufferManager.CreateBufferManager(transportElement.MaxBufferPoolSize, (int)transportElement.MaxReceivedMessageSize);
     this.encoderFactory = context.BindingParameters.Remove <MessageEncodingBindingElement>().CreateMessageEncoderFactory();
     this.uri            = AspNetCoreUri.GetUri(context.ListenUriBaseAddress.AbsolutePath + context.ListenUriRelativeAddress);
     this.sync           = new SemaphoreSlim(5);
 }
        /// <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());
        }
예제 #4
0
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="router"></param>
        /// <param name="transportElement"></param>
        /// <param name="context"></param>
        public AspNetCoreReplyChannelListener(
            AspNetCoreRequestRouter router,
            AspNetCoreTransportBindingElement transportElement,
            BindingContext context) :
            base(context.Binding)
        {
            this.router = router ?? throw new ArgumentNullException(nameof(router));

            bufferManager  = BufferManager.CreateBufferManager(transportElement.MaxBufferPoolSize, (int)transportElement.MaxReceivedMessageSize);
            encoderFactory = context.BindingParameters.Remove <MessageEncodingBindingElement>().CreateMessageEncoderFactory();
            uri            = new Uri(context.ListenUriBaseAddress, context.ListenUriRelativeAddress);
            secure         = transportElement.Secure;
            method         = transportElement.Method;
        }
예제 #5
0
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="next"></param>
        /// <param name="serviceType"></param>
        /// <param name="bindings"></param>
        /// <param name="router"></param>
        /// <param name="applicationLifetime"></param>
        /// <param name="logger"></param>
        /// <param name="serviceProvider"></param>
        protected AspNetCoreServiceHostMiddleware(
            RequestDelegate next,
            Type serviceType,
            AspNetCoreBindingFactory bindings,
            AspNetCoreRequestRouter router,
            MessageVersion messageVersion,
            IApplicationLifetime applicationLifetime,
            ILogger <AspNetCoreServiceHostMiddleware> logger,
            IServiceProvider serviceProvider) :
            this(next, bindings, router, messageVersion, applicationLifetime, logger, serviceProvider)
        {
            host = new AspNetCoreServiceHost(serviceType, AddDefaultServiceEndpoint, httpBaseUri, httpsBaseUri);
            host.AddDependencyInjectionBehavior(serviceType, serviceProvider);
            host.Description.Behaviors.Add(new TextOrMtomEncoderInspector());
            host.Description.Behaviors.Add(new AspNetCoreRequestRouterBehavior(router));
            host.Description.Behaviors.Add(new AspNetCoreServiceMetadataBehavior());

            var sdb = host.Description.Behaviors.Find <ServiceDebugBehavior>();

            if (sdb == null)
            {
                host.Description.Behaviors.Add(sdb = new ServiceDebugBehavior());
            }

            var httpGetBinding  = bindings.CreateBinding(serviceProvider, MessageVersion.None, false, HttpMethods.Get);
            var httpsGetBinding = bindings.CreateBinding(serviceProvider, MessageVersion.None, true, HttpMethods.Get);

            sdb.HttpHelpPageEnabled  = true;
            sdb.HttpHelpPageBinding  = httpGetBinding;
            sdb.HttpHelpPageUrl      = new Uri("", UriKind.Relative);
            sdb.HttpsHelpPageEnabled = true;
            sdb.HttpsHelpPageBinding = httpsGetBinding;
            sdb.HttpsHelpPageUrl     = new Uri("", UriKind.Relative);

            var smb = host.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (smb == null)
            {
                host.Description.Behaviors.Add(smb = new ServiceMetadataBehavior());
            }

            smb.HttpGetEnabled  = true;
            smb.HttpGetBinding  = httpGetBinding;
            smb.HttpsGetEnabled = true;
            smb.HttpsGetBinding = httpsGetBinding;
        }
예제 #6
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.");
                }
            });
        }
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="router"></param>
 public AspNetCoreServiceBehavior(AspNetCoreRequestRouter router)
 {
     this.router = router ?? throw new ArgumentNullException(nameof(router));
 }