b27cc867c805109a056d3f1d32f4b73fb0be8027
[mono.git] / mcs / class / referencesource / System.ServiceModel / System / ServiceModel / Dispatcher / InputChannelBinder.cs
1 //-----------------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //-----------------------------------------------------------------------------
4
5 namespace System.ServiceModel.Dispatcher
6 {
7     using System;
8     using System.Runtime;
9     using System.ServiceModel;
10     using System.ServiceModel.Channels;
11     using System.ServiceModel.Diagnostics;
12
13     class InputChannelBinder : IChannelBinder
14     {
15         IInputChannel channel;
16         Uri listenUri;
17
18         internal InputChannelBinder(IInputChannel channel, Uri listenUri)
19         {
20             if (!((channel != null)))
21             {
22                 Fx.Assert("InputChannelBinder.InputChannelBinder: (channel != null)");
23                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("channel");
24             }
25             this.channel = channel;
26             this.listenUri = listenUri;
27         }
28
29         public IChannel Channel
30         {
31             get { return this.channel; }
32         }
33
34         public bool HasSession
35         {
36             get { return this.channel is ISessionChannel<IInputSession>; }
37         }
38
39         public Uri ListenUri
40         {
41             get { return this.listenUri; }
42         }
43
44         public EndpointAddress LocalAddress
45         {
46             get { return this.channel.LocalAddress; }
47         }
48
49         public EndpointAddress RemoteAddress
50         {
51             get
52             {
53 #pragma warning suppress 56503 // Microsoft, the property is really not implemented, cannot lie, API not public
54                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException()); 
55             }
56         }
57
58         public void Abort()
59         {
60             this.channel.Abort();
61         }
62
63         public void CloseAfterFault(TimeSpan timeout)
64         {
65             this.channel.Close(timeout);
66         }
67
68         public IAsyncResult BeginTryReceive(TimeSpan timeout, AsyncCallback callback, object state)
69         {
70             return this.channel.BeginTryReceive(timeout, callback, state);
71         }
72
73         public bool EndTryReceive(IAsyncResult result, out RequestContext requestContext)
74         {
75             Message message;
76             if (this.channel.EndTryReceive(result, out message))
77             {
78                 requestContext = this.WrapMessage(message);
79                 return true;
80             }
81             else
82             {
83                 requestContext = null;
84                 return false;
85             }
86         }
87
88         public RequestContext CreateRequestContext(Message message)
89         {
90             return this.WrapMessage(message);
91         }
92
93         public IAsyncResult BeginSend(Message message, TimeSpan timeout, AsyncCallback callback, object state)
94         {
95             throw TraceUtility.ThrowHelperError(new NotImplementedException(), message);
96         }
97
98         public void EndSend(IAsyncResult result)
99         {
100             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException());
101         }
102
103         public void Send(Message message, TimeSpan timeout)
104         {
105             throw TraceUtility.ThrowHelperError(new NotImplementedException(), message);
106         }
107
108         public bool TryReceive(TimeSpan timeout, out RequestContext requestContext)
109         {
110             Message message;
111             if (this.channel.TryReceive(timeout, out message))
112             {
113                 requestContext = this.WrapMessage(message);
114                 return true;
115             }
116             else
117             {
118                 requestContext = null;
119                 return false;
120             }
121         }
122
123         public IAsyncResult BeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, object state)
124         {
125             throw TraceUtility.ThrowHelperError(new NotImplementedException(), message);
126         }
127
128         public Message EndRequest(IAsyncResult result)
129         {
130             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException());
131         }
132
133         public Message Request(Message message, TimeSpan timeout)
134         {
135             throw TraceUtility.ThrowHelperError(new NotImplementedException(), message);
136         }
137
138         public bool WaitForMessage(TimeSpan timeout)
139         {
140             return this.channel.WaitForMessage(timeout);
141         }
142
143         public IAsyncResult BeginWaitForMessage(TimeSpan timeout, AsyncCallback callback, object state)
144         {
145             return this.channel.BeginWaitForMessage(timeout, callback, state);
146         }
147
148         public bool EndWaitForMessage(IAsyncResult result)
149         {
150             return this.channel.EndWaitForMessage(result);
151         }
152
153         RequestContext WrapMessage(Message message)
154         {
155             if (message == null)
156             {
157                 return null;
158             }
159             else
160             {
161                 return new InputRequestContext(message, this);
162             }
163         }
164
165         class InputRequestContext : RequestContextBase
166         {
167             InputChannelBinder binder;
168
169             internal InputRequestContext(Message request, InputChannelBinder binder)
170                 : base(request, TimeSpan.Zero, TimeSpan.Zero)
171             {
172                 this.binder = binder;
173             }
174
175             protected override void OnAbort()
176             {
177             }
178
179             protected override void OnClose(TimeSpan timeout)
180             {
181             }
182
183             protected override void OnReply(Message message, TimeSpan timeout)
184             {
185             }
186
187             protected override IAsyncResult OnBeginReply(Message message, TimeSpan timeout, AsyncCallback callback, object state)
188             {
189                 return new CompletedAsyncResult(callback, state);
190             }
191
192             protected override void OnEndReply(IAsyncResult result)
193             {
194                 CompletedAsyncResult.End(result);
195             }
196         }
197     }
198 }