| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Collections.Generic; |
| | | 6 | | using System.Threading.Tasks; |
| | | 7 | | using CoreWCF.Channels; |
| | | 8 | | using CoreWCF.Configuration; |
| | | 9 | | using CoreWCF.Runtime; |
| | | 10 | | |
| | | 11 | | namespace CoreWCF.Dispatcher |
| | | 12 | | { |
| | | 13 | | internal class ServiceDispatcher : IServiceDispatcher |
| | | 14 | | { |
| | | 15 | | private readonly IRequestReplyCorrelator _requestReplyCorrelator; |
| | | 16 | | |
| | 660 | 17 | | public ServiceDispatcher(ChannelDispatcher channelDispatcher) |
| | | 18 | | { |
| | 660 | 19 | | ChannelDispatcher = channelDispatcher; |
| | | 20 | | // TODO: Maybe make lazy |
| | 660 | 21 | | _requestReplyCorrelator = new RequestReplyCorrelator(); |
| | 660 | 22 | | } |
| | | 23 | | |
| | 9961 | 24 | | public Uri BaseAddress => ChannelDispatcher.ListenUri; |
| | | 25 | | |
| | 8599 | 26 | | public Binding Binding => ChannelDispatcher.Binding; |
| | | 27 | | |
| | 27444 | 28 | | public ChannelDispatcher ChannelDispatcher { get; } |
| | | 29 | | |
| | 69 | 30 | | public ServiceHostBase Host { get { return ChannelDispatcher.Host; } } |
| | | 31 | | |
| | 2518 | 32 | | public EndpointDispatcherTable Endpoints => ChannelDispatcher.EndpointDispatcherTable; |
| | | 33 | | |
| | 459 | 34 | | public IList<Type> SupportedChannelTypes => ChannelDispatcher.SupportedChannelTypes; |
| | | 35 | | |
| | 1093 | 36 | | public AsyncLock ThisLock { get; } = new AsyncLock(); |
| | | 37 | | |
| | | 38 | | public async Task<IServiceChannelDispatcher> CreateServiceChannelDispatcherAsync(IChannel channel) |
| | | 39 | | { |
| | 2318 | 40 | | ServiceChannel.SessionIdleManager sessionIdleManager = channel.GetProperty<ServiceChannel.SessionIdleManager |
| | 2318 | 41 | | IChannelBinder binder = null; |
| | 2318 | 42 | | if (channel is IReplyChannel) |
| | | 43 | | { |
| | 525 | 44 | | ReplyChannelBinder rcbinder = channel.GetProperty<ReplyChannelBinder>(); |
| | 525 | 45 | | rcbinder.Init(channel as IReplyChannel, BaseAddress); |
| | 525 | 46 | | binder = rcbinder; |
| | | 47 | | } |
| | 1793 | 48 | | else if (channel is IDuplexSessionChannel) |
| | | 49 | | { |
| | 75 | 50 | | DuplexChannelBinder dcbinder = channel.GetProperty<DuplexChannelBinder>(); |
| | 75 | 51 | | dcbinder.Init(channel as IDuplexSessionChannel, _requestReplyCorrelator, BaseAddress); |
| | 75 | 52 | | binder = dcbinder; |
| | | 53 | | } |
| | 1718 | 54 | | else if (channel is IInputChannel) |
| | | 55 | | { |
| | 1718 | 56 | | InputChannelBinder icbinder = channel.GetProperty<InputChannelBinder>(); |
| | 1718 | 57 | | icbinder.Init(channel as IInputChannel, BaseAddress); |
| | 1718 | 58 | | binder = icbinder; |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | // TODO: Wire up wasChannelThrottled |
| | 2318 | 62 | | var channelHandler = new ChannelHandler(Binding.MessageVersion, binder, channel.GetProperty<ServiceThrottle> |
| | 2318 | 63 | | this, /*wasChannelThrottled*/ false, sessionIdleManager); |
| | | 64 | | |
| | 2318 | 65 | | IServiceChannelDispatcher channelDispatcher = channelHandler.GetDispatcher(); |
| | | 66 | | // channel.ChannelDispatcher = channelDispatcher; |
| | 2318 | 67 | | await channelHandler.OpenAsync(); |
| | 2318 | 68 | | return channelDispatcher; |
| | 2318 | 69 | | } |
| | | 70 | | } |
| | | 71 | | } |