InputChannelBinder.cs 5.8 KB

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