OneWayBindingElement.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. //
  2. // OneWayBindingElement.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2006 Novell, Inc. http://www.novell.com
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Collections.Generic;
  30. using System.ServiceModel.Description;
  31. using System.ServiceModel.Security;
  32. using System.ServiceModel.Channels;
  33. namespace System.ServiceModel.Channels
  34. {
  35. public sealed class OneWayBindingElement : BindingElement
  36. {
  37. public OneWayBindingElement ()
  38. {
  39. pool = new ChannelPoolSettings ();
  40. }
  41. OneWayBindingElement (OneWayBindingElement other)
  42. {
  43. pool = new ChannelPoolSettings (other.pool);
  44. }
  45. ChannelPoolSettings pool;
  46. public ChannelPoolSettings ChannelPoolSettings {
  47. get { return pool; }
  48. }
  49. [MonoTODO ("It generates just pass-thru factory")]
  50. public override IChannelFactory<TChannel>
  51. BuildChannelFactory<TChannel> (BindingContext context)
  52. {
  53. if (typeof (TChannel) == typeof (IOutputSessionChannel) ||
  54. typeof (TChannel) == typeof (IOutputChannel))
  55. return new OneWayChannelFactory<TChannel> (context.BuildInnerChannelFactory<TChannel> ());
  56. throw new ArgumentException (String.Format ("The requested channel type '{0}' is not supported by this binding element", typeof (TChannel)));
  57. }
  58. [MonoTODO ("It generates just pass-thru listener")]
  59. public override IChannelListener<TChannel>
  60. BuildChannelListener<TChannel> (
  61. BindingContext context)
  62. {
  63. if (typeof (TChannel) == typeof (IInputSessionChannel) ||
  64. typeof (TChannel) == typeof (IInputChannel))
  65. return new OneWayChannelListener<TChannel> (context.BuildInnerChannelListener<TChannel> ());
  66. throw new ArgumentException (String.Format ("The requested channel type '{0}' is not supported by this binding element", typeof (TChannel)));
  67. }
  68. public override bool CanBuildChannelFactory<TChannel> (
  69. BindingContext context)
  70. {
  71. return typeof (TChannel) == typeof (IOutputSessionChannel) ||
  72. typeof (TChannel) == typeof (IOutputChannel);
  73. }
  74. public override bool CanBuildChannelListener<TChannel> (
  75. BindingContext context)
  76. {
  77. return typeof (TChannel) == typeof (IInputSessionChannel) ||
  78. typeof (TChannel) == typeof (IInputChannel);
  79. }
  80. public override BindingElement Clone ()
  81. {
  82. return new OneWayBindingElement (this);
  83. }
  84. [MonoTODO]
  85. public override T GetProperty<T> (BindingContext context)
  86. {
  87. throw new NotImplementedException ();
  88. }
  89. }
  90. class OneWayChannelFactory<TChannel> : ChannelFactoryBase<TChannel>
  91. {
  92. IChannelFactory<TChannel> inner;
  93. public OneWayChannelFactory (IChannelFactory<TChannel> inner)
  94. {
  95. this.inner = inner;
  96. }
  97. protected override TChannel OnCreateChannel (EndpointAddress address, Uri via)
  98. {
  99. return inner.CreateChannel (address, via);
  100. }
  101. protected override void OnOpen (TimeSpan timeout)
  102. {
  103. inner.Open (timeout);
  104. }
  105. protected override IAsyncResult OnBeginOpen (TimeSpan timeout, AsyncCallback callback, object state)
  106. {
  107. return inner.BeginOpen (timeout, callback, state);
  108. }
  109. protected override void OnEndOpen (IAsyncResult result)
  110. {
  111. inner.EndOpen (result);
  112. }
  113. protected override void OnClose (TimeSpan timeout)
  114. {
  115. inner.Close (timeout);
  116. }
  117. protected override IAsyncResult OnBeginClose (TimeSpan timeout, AsyncCallback callback, object state)
  118. {
  119. return inner.BeginClose (timeout, callback, state);
  120. }
  121. protected override void OnEndClose (IAsyncResult result)
  122. {
  123. inner.EndClose (result);
  124. }
  125. }
  126. class OneWayChannelListener<TChannel> : ChannelListenerBase<TChannel>
  127. where TChannel : class, IChannel
  128. {
  129. IChannelListener<TChannel> inner;
  130. public OneWayChannelListener (IChannelListener<TChannel> inner)
  131. {
  132. this.inner = inner;
  133. }
  134. public override Uri Uri {
  135. get { return inner.Uri; }
  136. }
  137. protected override void OnAbort ()
  138. {
  139. inner.Abort ();
  140. }
  141. protected override void OnOpen (TimeSpan timeout)
  142. {
  143. inner.Open (timeout);
  144. }
  145. protected override IAsyncResult OnBeginOpen (TimeSpan timeout, AsyncCallback callback, object state)
  146. {
  147. return inner.BeginOpen (timeout, callback, state);
  148. }
  149. protected override void OnEndOpen (IAsyncResult result)
  150. {
  151. inner.EndOpen (result);
  152. }
  153. protected override void OnClose (TimeSpan timeout)
  154. {
  155. inner.Close (timeout);
  156. }
  157. protected override IAsyncResult OnBeginClose (TimeSpan timeout, AsyncCallback callback, object state)
  158. {
  159. return inner.BeginClose (timeout, callback, state);
  160. }
  161. protected override void OnEndClose (IAsyncResult result)
  162. {
  163. inner.EndClose (result);
  164. }
  165. protected override bool OnWaitForChannel (TimeSpan timeout)
  166. {
  167. return inner.WaitForChannel (timeout);
  168. }
  169. protected override IAsyncResult OnBeginWaitForChannel (TimeSpan timeout, AsyncCallback callback, object state)
  170. {
  171. return inner.BeginWaitForChannel (timeout, callback, state);
  172. }
  173. protected override bool OnEndWaitForChannel (IAsyncResult result)
  174. {
  175. return inner.EndWaitForChannel (result);
  176. }
  177. protected override TChannel OnAcceptChannel (TimeSpan timeout)
  178. {
  179. return inner.AcceptChannel (timeout);
  180. }
  181. protected override IAsyncResult OnBeginAcceptChannel (TimeSpan timeout, AsyncCallback callback, object state)
  182. {
  183. return inner.BeginAcceptChannel (timeout, callback, state);
  184. }
  185. protected override TChannel OnEndAcceptChannel (IAsyncResult result)
  186. {
  187. return inner.EndAcceptChannel (result);
  188. }
  189. }
  190. }