| | | 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.Threading; |
| | | 6 | | using System.Threading.Tasks; |
| | | 7 | | using CoreWCF.Channels; |
| | | 8 | | using CoreWCF.Configuration; |
| | | 9 | | using CoreWCF.Diagnostics; |
| | | 10 | | using CoreWCF.Runtime; |
| | | 11 | | |
| | | 12 | | namespace CoreWCF.Dispatcher |
| | | 13 | | { |
| | | 14 | | internal class ReplyChannelBinder : IChannelBinder |
| | | 15 | | { |
| | | 16 | | private IReplyChannel _channel; |
| | | 17 | | private bool _initialized = false; |
| | | 18 | | private IServiceChannelDispatcher _next; |
| | | 19 | | |
| | 998 | 20 | | public ReplyChannelBinder() { } |
| | | 21 | | |
| | | 22 | | internal void Init(IReplyChannel channel, Uri listenUri) |
| | | 23 | | { |
| | 525 | 24 | | if (_initialized) |
| | | 25 | | { |
| | | 26 | | Fx.Assert(_channel == channel, "Wrong channel when calling Init"); |
| | | 27 | | Fx.Assert(ListenUri == listenUri, "Wrong listenUri when calling Init"); |
| | 26 | 28 | | return; |
| | | 29 | | } |
| | | 30 | | |
| | 499 | 31 | | if (channel == null) |
| | | 32 | | { |
| | | 33 | | Fx.Assert("ReplyChannelBinder.ReplyChannelBinder: (channel != null)"); |
| | 0 | 34 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(channel)); |
| | | 35 | | } |
| | 499 | 36 | | _channel = channel; |
| | 499 | 37 | | ListenUri = listenUri; |
| | 499 | 38 | | _initialized = true; |
| | 499 | 39 | | } |
| | | 40 | | |
| | | 41 | | public IChannel Channel |
| | | 42 | | { |
| | 3464 | 43 | | get { return _channel; } |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | public bool HasSession |
| | | 47 | | { |
| | 1846 | 48 | | get { return _channel is ISessionChannel<IInputSession>; } |
| | | 49 | | } |
| | | 50 | | |
| | 499 | 51 | | public Uri ListenUri { get; private set; } |
| | | 52 | | |
| | | 53 | | public EndpointAddress LocalAddress |
| | | 54 | | { |
| | 0 | 55 | | get { return _channel.LocalAddress; } |
| | | 56 | | } |
| | | 57 | | |
| | | 58 | | public EndpointAddress RemoteAddress |
| | | 59 | | { |
| | | 60 | | get |
| | | 61 | | { |
| | 0 | 62 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException()); |
| | | 63 | | } |
| | | 64 | | } |
| | | 65 | | |
| | | 66 | | public void Abort() |
| | | 67 | | { |
| | 0 | 68 | | _channel.Abort(); |
| | 0 | 69 | | } |
| | | 70 | | |
| | | 71 | | public void CloseAfterFault(TimeSpan timeout) |
| | | 72 | | { |
| | 0 | 73 | | var helper = new TimeoutHelper(timeout); |
| | 0 | 74 | | _channel.CloseAsync(helper.GetCancellationToken()).GetAwaiter().GetResult(); |
| | 0 | 75 | | } |
| | | 76 | | |
| | | 77 | | public RequestContext CreateRequestContext(Message message) |
| | | 78 | | { |
| | 0 | 79 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException()); |
| | | 80 | | } |
| | | 81 | | |
| | | 82 | | public Task SendAsync(Message message, CancellationToken token) |
| | | 83 | | { |
| | 0 | 84 | | throw TraceUtility.ThrowHelperError(new NotImplementedException(), message); |
| | | 85 | | } |
| | | 86 | | |
| | | 87 | | public Task<Message> RequestAsync(Message message, CancellationToken token) |
| | | 88 | | { |
| | 0 | 89 | | throw TraceUtility.ThrowHelperError(new NotImplementedException(), message); |
| | | 90 | | } |
| | | 91 | | |
| | | 92 | | public void SetNextDispatcher(IServiceChannelDispatcher dispatcher) |
| | | 93 | | { |
| | 525 | 94 | | _next = dispatcher; |
| | 525 | 95 | | } |
| | | 96 | | |
| | | 97 | | public Task DispatchAsync(RequestContext context) |
| | | 98 | | { |
| | | 99 | | Fx.Assert(_next != null, "SetNextDispatcher wasn't called"); |
| | 810 | 100 | | return _next.DispatchAsync(context); |
| | | 101 | | } |
| | | 102 | | |
| | | 103 | | public Task DispatchAsync(Message message) |
| | | 104 | | { |
| | 0 | 105 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException()); |
| | | 106 | | } |
| | | 107 | | } |
| | | 108 | | } |