private async Task EnsureChannelAsync(FramingConnection connection) { if (_replyChannel == null) { using (await _lock.TakeLockAsync()) { if (_replyChannel == null) { var be = connection.ServiceDispatcher.Binding.CreateBindingElements(); var tbe = be.Find <TransportBindingElement>(); ITransportFactorySettings settings = new NetFramingTransportSettings { CloseTimeout = connection.ServiceDispatcher.Binding.CloseTimeout, OpenTimeout = connection.ServiceDispatcher.Binding.OpenTimeout, ReceiveTimeout = connection.ServiceDispatcher.Binding.ReceiveTimeout, SendTimeout = connection.ServiceDispatcher.Binding.SendTimeout, ManualAddressing = tbe.ManualAddressing, BufferManager = connection.BufferManager, MaxReceivedMessageSize = tbe.MaxReceivedMessageSize, MessageEncoderFactory = connection.MessageEncoderFactory }; _replyChannel = new ConnectionOrientedTransportReplyChannel(settings, null, _servicesScopeFactory.CreateScope().ServiceProvider); _channelDispatcher = await connection.ServiceDispatcher.CreateServiceChannelDispatcherAsync(_replyChannel); } } } }
public async Task DispatchAsync(Message message) { if (message == null) //0 bytes { //We have already closed all channels, return. (Couldn't use DoneReceivingInCurrentState()) if (_channel.State == CommunicationState.Closed || _channel.State == CommunicationState.Closing || _channel.State == CommunicationState.Closed) { return; } else { await _serviceChannelDispatcher.DispatchAsync(message); return; } } IServiceDispatcher serviceDispatcher = _demuxer.MatchDispatcher(message); if (serviceDispatcher == null) { ErrorBehavior.ThrowAndCatch( new EndpointNotFoundException(SR.Format(SR.UnableToDemuxChannel, message.Headers.Action)), message); await _demuxer.EndpointNotFoundAsync((IDuplexSessionChannel)_channel, message); return; } _serviceChannelDispatcher = await serviceDispatcher.CreateServiceChannelDispatcherAsync(_channel); await _serviceChannelDispatcher.DispatchAsync(message); }
internal async Task HandleRequest(HttpContext context) { if (!context.WebSockets.IsWebSocketRequest) { if (_replyChannelDispatcher == null) { _replyChannelDispatcher = await _replyChannelDispatcherTask; } await _replyChannel.HandleRequest(context); } else { var openTimeoutToken = new TimeoutHelper(((IDefaultCommunicationTimeouts)_httpSettings).OpenTimeout).GetCancellationToken(); var webSocketContext = await AcceptWebSocketAsync(context, openTimeoutToken); if (webSocketContext == null) { return; } var channel = new ServerWebSocketTransportDuplexSessionChannel(context, webSocketContext, _httpSettings, _serviceDispatcher.BaseAddress, _servicesScopeFactory.CreateScope().ServiceProvider); channel.ChannelDispatcher = await _serviceDispatcher.CreateServiceChannelDispatcherAsync(channel); await channel.StartReceivingAsync(); } return; }
public async Task <IServiceChannelDispatcher> CreateServiceChannelDispatcherAsync(IChannel channel) { ServiceChannel.SessionIdleManager sessionIdleManager = channel.GetProperty <ServiceChannel.SessionIdleManager>(); IChannelBinder binder = null; if (channel is IReplyChannel) { ReplyChannelBinder rcbinder = channel.GetProperty <ReplyChannelBinder>(); rcbinder.Init(channel as IReplyChannel, BaseAddress); binder = rcbinder; } else if (channel is IDuplexSessionChannel) { DuplexChannelBinder dcbinder = channel.GetProperty <DuplexChannelBinder>(); dcbinder.Init(channel as IDuplexSessionChannel, _requestReplyCorrelator, BaseAddress); binder = dcbinder; } else if (channel is IInputChannel) { InputChannelBinder icbinder = channel.GetProperty <InputChannelBinder>(); icbinder.Init(channel as IInputChannel, BaseAddress); binder = icbinder; } // TODO: Wire up wasChannelThrottled var channelHandler = new ChannelHandler(Binding.MessageVersion, binder, channel.GetProperty <ServiceThrottle>(), this, /*wasChannelThrottled*/ false, sessionIdleManager); IServiceChannelDispatcher channelDispatcher = channelHandler.GetDispatcher(); // channel.ChannelDispatcher = channelDispatcher; await channelHandler.OpenAsync(); return(channelDispatcher); }
public override async Task DispatchAsync(RequestContext context) { SecurityRequestContext securedMessage = (SecurityRequestContext)ProcessReceivedRequest(context); IServiceChannelDispatcher serviceChannelDispatcher = await SecurityServiceDispatcher.GetAuthChannelDispatcher(this); await serviceChannelDispatcher.DispatchAsync(securedMessage); }
public override async Task DispatchAsync(Message message) { Fx.Assert(State == CommunicationState.Opened, "Expected dispatcher state to be Opened, instead it's " + State.ToString()); message = await ProcessInnerItemAsync(message, ServiceDefaults.SendTimeout); if (_serviceChannelDispatcher == null) { _serviceChannelDispatcher = await SecurityServiceDispatcher. SecurityAuthServiceDispatcher.CreateServiceChannelDispatcherAsync(this); } await _serviceChannelDispatcher.DispatchAsync(message); }
public async Task DispatchAsync(RequestContext context) { // TODO: Find way to avoid instantiating a new ServiceChannelDispatcher each time IServiceDispatcher serviceDispatcher = _demuxer.MatchDispatcher(context.RequestMessage); if (serviceDispatcher == null) { ErrorBehavior.ThrowAndCatch( new EndpointNotFoundException(SR.Format(SR.UnableToDemuxChannel, context.RequestMessage.Headers.Action)), context.RequestMessage); } // TODO: if serviceDispatcher == null, use the EndpointNotFound code path IServiceChannelDispatcher serviceChannelDispatcher = await serviceDispatcher.CreateServiceChannelDispatcherAsync(_channel); await serviceChannelDispatcher.DispatchAsync(context); }
internal async Task <IServiceChannelDispatcher> GetAuthChannelDispatcher(IReplyChannel outerChannel) { if (_securityAuthServiceChannelDispatcher == null) { lock (ThisLock) { if (_channelTask == null) { _channelTask = SecurityAuthServiceDispatcher.CreateServiceChannelDispatcherAsync(outerChannel); } } _securityAuthServiceChannelDispatcher = await _channelTask; Thread.MemoryBarrier(); } return(_securityAuthServiceChannelDispatcher); }
public static void BuildDispatcherWithConfiguration_XmlSerializer() { string serviceAddress = "http://localhost/dummy"; var services = new ServiceCollection(); services.AddLogging(); services.AddServiceModelServices(); IServer server = new MockServer(); services.AddSingleton(server); services.AddSingleton(typeof(ILogger <>), typeof(NullLogger <>)); services.RegisterApplicationLifetime(); ServiceProvider serviceProvider = services.BuildServiceProvider(); IServiceBuilder serviceBuilder = serviceProvider.GetRequiredService <IServiceBuilder>(); serviceBuilder.BaseAddresses.Add(new Uri(serviceAddress)); serviceBuilder.AddService <SimpleXmlSerializerService>(); var binding = new CustomBinding("BindingName", "BindingNS"); binding.Elements.Add(new MockTransportBindingElement()); serviceBuilder.AddServiceEndpoint <SimpleXmlSerializerService, ISimpleXmlSerializerService>(binding, serviceAddress); serviceBuilder.OpenAsync().GetAwaiter().GetResult(); IDispatcherBuilder dispatcherBuilder = serviceProvider.GetRequiredService <IDispatcherBuilder>(); System.Collections.Generic.List <IServiceDispatcher> dispatchers = dispatcherBuilder.BuildDispatchers(typeof(SimpleXmlSerializerService)); Assert.Single(dispatchers); IServiceDispatcher serviceDispatcher = dispatchers[0]; Assert.Equal("foo", serviceDispatcher.Binding.Scheme); Assert.Equal(serviceAddress, serviceDispatcher.BaseAddress.ToString()); IChannel mockChannel = new MockReplyChannel(serviceProvider); IServiceChannelDispatcher dispatcher = serviceDispatcher.CreateServiceChannelDispatcherAsync(mockChannel).Result; var requestContext = XmlSerializerTestRequestContext.Create(serviceAddress); dispatcher.DispatchAsync(requestContext).Wait(); Assert.True(requestContext.WaitForReply(TimeSpan.FromSeconds(5)), "Dispatcher didn't send reply"); requestContext.ValidateReply(); }
public override async Task DispatchAsync(RequestContext context) { SecurityRequestContext securedMessage = (SecurityRequestContext)(await ProcessReceivedRequestAsync(context)); if (SecurityServiceDispatcher.SessionMode) // for SCT, sessiontoken is created so we channel the call to SecurityAuthentication and evevntually SecurityServerSession. { IServiceChannelDispatcher serviceChannelDispatcher = await SecurityServiceDispatcher.GetAuthChannelDispatcher(this); await serviceChannelDispatcher.DispatchAsync(securedMessage); } else { IServiceChannelDispatcher serviceChannelDispatcher = await SecurityServiceDispatcher.GetInnerServiceChannelDispatcher(this); await serviceChannelDispatcher.DispatchAsync(securedMessage); } }
public async Task <IServiceChannelDispatcher> CreateServiceChannelDispatcherAsync(IChannel outerChannel) { //TODO should have better logic //Initialization path start if (outerChannel.ChannelDispatcher == null) { TypedChannelDemuxer typedChannelDemuxer = ChannelBuilder.GetTypedChannelDemuxer <IReplyChannel>(); IServiceChannelDispatcher channelDispatcher = await typedChannelDemuxer.CreateServiceChannelDispatcherAsync(outerChannel); return(channelDispatcher); } //initialization end //Below dispatches all SCT call for first time for all clients else { IServiceChannelDispatcher securityReplyChannelDispatcher = await GetInnerChannelDispatcherAsync(outerChannel); return(securityReplyChannelDispatcher); } }
//Reference OnAcceptChannel/SecurityChannelListner private async Task <IServiceChannelDispatcher> GetInnerChannelDispatcherAsync(IChannel outerChannel) { IServiceChannelDispatcher securityChannelDispatcher = null; SecurityProtocol securityProtocol = SecurityProtocolFactory.CreateSecurityProtocol(null, null, (outerChannel is IReplyChannel || outerChannel is IReplySessionChannel), TimeSpan.Zero); await securityProtocol.OpenAsync(TimeSpan.Zero); /* TODO once we add more features * if (outerChannel is IInputChannel) * { * securityChannel = new SecurityInputChannel(listener, (IInputChannel)innerChannel, securityProtocol, listener.settingsLifetimeManager); * } * else if (outerChannel is IInputSessionChannel)) * { * securityChannel = new SecurityInputSessionChannel(listener, (IInputSessionChannel)innerChannel, securityProtocol, listener.settingsLifetimeManager); * } * else if (outerChannel is IDuplexChannel)) * { * securityChannel = new SecurityDuplexChannel(listener, (IDuplexChannel)innerChannel, securityProtocol, listener.settingsLifetimeManager); * } * else if (outerChannel is IDuplexSessionChannel)) * { * securityChannel = new SecurityDuplexSessionChannel(listener, (IDuplexSessionChannel)innerChannel, securityProtocol, listener.settingsLifetimeManager); * } * else*/ if (outerChannel is IReplyChannel replyChannel) { securityChannelDispatcher = new SecurityReplyChannelDispatcher(this, replyChannel, securityProtocol, _settingsLifetimeManager); } /* else if (listener.SupportsRequestReply && typeof(TChannel) == typeof(IReplySessionChannel)) * { * securityChannel = new SecurityReplySessionChannel(listener, (IReplySessionChannel)innerChannel, securityProtocol, listener.settingsLifetimeManager); * } * else * { * throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.UnsupportedChannelInterfaceType, typeof(TChannel)))); * }*/ return(securityChannelDispatcher); }
private void BuildHandler() { var be = _serviceDispatcher.Binding.CreateBindingElements(); var mebe = be.Find <MessageEncodingBindingElement>(); if (mebe == null) { throw new ArgumentException("Must provide a MessageEncodingBindingElement", nameof(_serviceDispatcher.Binding)); } var tbe = be.Find <HttpTransportBindingElement>(); if (tbe == null) { throw new ArgumentException("Must provide a HttpTransportBindingElement", nameof(_serviceDispatcher.Binding)); } var httpSettings = new HttpTransportSettings(); httpSettings.BufferManager = BufferManager.CreateBufferManager(DefaultMaxBufferPoolSize, tbe.MaxBufferSize); httpSettings.OpenTimeout = _serviceDispatcher.Binding.OpenTimeout; httpSettings.ReceiveTimeout = _serviceDispatcher.Binding.ReceiveTimeout; httpSettings.SendTimeout = _serviceDispatcher.Binding.SendTimeout; httpSettings.CloseTimeout = _serviceDispatcher.Binding.CloseTimeout; httpSettings.MaxBufferSize = tbe.MaxBufferSize; httpSettings.MaxReceivedMessageSize = tbe.MaxReceivedMessageSize; httpSettings.MessageEncoderFactory = mebe.CreateMessageEncoderFactory(); httpSettings.ManualAddressing = tbe.ManualAddressing; httpSettings.TransferMode = tbe.TransferMode; httpSettings.KeepAliveEnabled = tbe.KeepAliveEnabled; httpSettings.AnonymousUriPrefixMatcher = new HttpAnonymousUriPrefixMatcher(); _httpSettings = httpSettings; var scope = _servicesScopeFactory.CreateScope(); _replyChannel = new AspNetCoreReplyChannel(_servicesScopeFactory.CreateScope().ServiceProvider); _channelDispatcher = _serviceDispatcher.CreateServiceChannelDispatcher(_replyChannel); }
private async Task OnCloseAsync(TimeSpan timeout) { IServiceChannelDispatcher serviceChannelDispatch = await Factory.GetServiceChannelDispatcherAsync(this); await serviceChannelDispatch.DispatchAsync((CoreWCF.Channels.RequestContext) null); }
private Task OnCloseAsync(TimeSpan timeout) { IServiceChannelDispatcher serviceChannelDispatch = Factory.GetServiceChannelDispatcher(this); return(serviceChannelDispatch.DispatchAsync(null, CancellationToken.None)); }
protected override void OnOpen(TimeSpan timeout) { _serviceChannelDispatch = Factory.GetServiceChannelDispatcher(this); }
public void SetNextDispatcher(IServiceChannelDispatcher dispatcher) { Fx.Assert(dispatcher is IDefaultCommunicationTimeouts, "Next Dispatcher must implement IDefaultCommunicationTimeouts"); _timeouts = dispatcher as IDefaultCommunicationTimeouts; _next = dispatcher; }
private async Task OnOpenAsync(TimeSpan timeout) { _serviceChannelDispatch = await Factory.GetServiceChannelDispatcherAsync(this); }
public void SetNextDispatcher(IServiceChannelDispatcher dispatcher) { _next = dispatcher; }