1 //-----------------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //-----------------------------------------------------------------------------
5 namespace System.ServiceModel.Dispatcher
9 using System.ServiceModel;
10 using System.ServiceModel.Channels;
11 using System.ServiceModel.Diagnostics;
13 class InputChannelBinder : IChannelBinder
15 IInputChannel channel;
18 internal InputChannelBinder(IInputChannel channel, Uri listenUri)
20 if (!((channel != null)))
22 Fx.Assert("InputChannelBinder.InputChannelBinder: (channel != null)");
23 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("channel");
25 this.channel = channel;
26 this.listenUri = listenUri;
29 public IChannel Channel
31 get { return this.channel; }
34 public bool HasSession
36 get { return this.channel is ISessionChannel<IInputSession>; }
41 get { return this.listenUri; }
44 public EndpointAddress LocalAddress
46 get { return this.channel.LocalAddress; }
49 public EndpointAddress RemoteAddress
53 #pragma warning suppress 56503 // Microsoft, the property is really not implemented, cannot lie, API not public
54 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException());
63 public void CloseAfterFault(TimeSpan timeout)
65 this.channel.Close(timeout);
68 public IAsyncResult BeginTryReceive(TimeSpan timeout, AsyncCallback callback, object state)
70 return this.channel.BeginTryReceive(timeout, callback, state);
73 public bool EndTryReceive(IAsyncResult result, out RequestContext requestContext)
76 if (this.channel.EndTryReceive(result, out message))
78 requestContext = this.WrapMessage(message);
83 requestContext = null;
88 public RequestContext CreateRequestContext(Message message)
90 return this.WrapMessage(message);
93 public IAsyncResult BeginSend(Message message, TimeSpan timeout, AsyncCallback callback, object state)
95 throw TraceUtility.ThrowHelperError(new NotImplementedException(), message);
98 public void EndSend(IAsyncResult result)
100 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException());
103 public void Send(Message message, TimeSpan timeout)
105 throw TraceUtility.ThrowHelperError(new NotImplementedException(), message);
108 public bool TryReceive(TimeSpan timeout, out RequestContext requestContext)
111 if (this.channel.TryReceive(timeout, out message))
113 requestContext = this.WrapMessage(message);
118 requestContext = null;
123 public IAsyncResult BeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, object state)
125 throw TraceUtility.ThrowHelperError(new NotImplementedException(), message);
128 public Message EndRequest(IAsyncResult result)
130 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException());
133 public Message Request(Message message, TimeSpan timeout)
135 throw TraceUtility.ThrowHelperError(new NotImplementedException(), message);
138 public bool WaitForMessage(TimeSpan timeout)
140 return this.channel.WaitForMessage(timeout);
143 public IAsyncResult BeginWaitForMessage(TimeSpan timeout, AsyncCallback callback, object state)
145 return this.channel.BeginWaitForMessage(timeout, callback, state);
148 public bool EndWaitForMessage(IAsyncResult result)
150 return this.channel.EndWaitForMessage(result);
153 RequestContext WrapMessage(Message message)
161 return new InputRequestContext(message, this);
165 class InputRequestContext : RequestContextBase
167 InputChannelBinder binder;
169 internal InputRequestContext(Message request, InputChannelBinder binder)
170 : base(request, TimeSpan.Zero, TimeSpan.Zero)
172 this.binder = binder;
175 protected override void OnAbort()
179 protected override void OnClose(TimeSpan timeout)
183 protected override void OnReply(Message message, TimeSpan timeout)
187 protected override IAsyncResult OnBeginReply(Message message, TimeSpan timeout, AsyncCallback callback, object state)
189 return new CompletedAsyncResult(callback, state);
192 protected override void OnEndReply(IAsyncResult result)
194 CompletedAsyncResult.End(result);