ChannelFactoryBase.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // ChannelFactoryBase.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2005 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.Collections.ObjectModel;
  31. using System.ServiceModel;
  32. using System.ServiceModel.Dispatcher;
  33. namespace System.ServiceModel.Channels
  34. {
  35. public abstract class ChannelFactoryBase<TChannel>
  36. : ChannelFactoryBase, IChannelFactory<TChannel>
  37. {
  38. [MonoTODO]
  39. protected ChannelFactoryBase ()
  40. : this (DefaultCommunicationTimeouts.Instance)
  41. {
  42. }
  43. protected ChannelFactoryBase (
  44. IDefaultCommunicationTimeouts timeouts)
  45. : base (timeouts)
  46. {
  47. }
  48. public TChannel CreateChannel (
  49. EndpointAddress remoteAddress)
  50. {
  51. return CreateChannel (remoteAddress, null);
  52. }
  53. public TChannel CreateChannel (
  54. EndpointAddress remoteAddress, Uri via)
  55. {
  56. ValidateCreateChannel ();
  57. return OnCreateChannel (remoteAddress, via);
  58. }
  59. protected abstract TChannel OnCreateChannel (
  60. EndpointAddress remoteAddress, Uri via);
  61. [MonoTODO ("find out what to do here.")]
  62. protected override void OnAbort ()
  63. {
  64. base.OnAbort ();
  65. }
  66. [MonoTODO ("find out what to do here.")]
  67. protected override void OnClose (TimeSpan timeout)
  68. {
  69. base.OnClose (timeout);
  70. }
  71. [MonoTODO ("find out what to do here.")]
  72. protected override IAsyncResult OnBeginClose (TimeSpan timeout, AsyncCallback callback, object state)
  73. {
  74. return base.OnBeginClose (timeout, callback, state);
  75. }
  76. [MonoTODO ("find out what to do here.")]
  77. protected override void OnEndClose (IAsyncResult result)
  78. {
  79. base.OnEndClose (result);
  80. }
  81. protected void ValidateCreateChannel ()
  82. {
  83. ThrowIfDisposedOrNotOpen ();
  84. if (State == CommunicationState.Faulted)
  85. throw new CommunicationObjectFaultedException ();
  86. }
  87. }
  88. public abstract class ChannelFactoryBase
  89. : ChannelManagerBase, IChannelFactory, ICommunicationObject
  90. {
  91. TimeSpan open_timeout, close_timeout, receive_timeout, send_timeout;
  92. [MonoTODO]
  93. protected ChannelFactoryBase ()
  94. : this (DefaultCommunicationTimeouts.Instance)
  95. {
  96. }
  97. protected ChannelFactoryBase (
  98. IDefaultCommunicationTimeouts timeouts)
  99. {
  100. open_timeout = timeouts.OpenTimeout;
  101. close_timeout = timeouts.CloseTimeout;
  102. send_timeout = timeouts.SendTimeout;
  103. receive_timeout = timeouts.ReceiveTimeout;
  104. }
  105. protected internal override TimeSpan DefaultCloseTimeout {
  106. get { return close_timeout; }
  107. }
  108. protected internal override TimeSpan DefaultOpenTimeout {
  109. get { return open_timeout; }
  110. }
  111. protected internal override TimeSpan DefaultReceiveTimeout {
  112. get { return receive_timeout; }
  113. }
  114. protected internal override TimeSpan DefaultSendTimeout {
  115. get { return send_timeout; }
  116. }
  117. [MonoTODO]
  118. public virtual T GetProperty<T> () where T : class
  119. {
  120. throw new NotImplementedException ();
  121. }
  122. [MonoTODO ("find out what to do here.")]
  123. protected override void OnAbort ()
  124. {
  125. }
  126. [MonoTODO]
  127. protected override IAsyncResult OnBeginClose (TimeSpan timeout,
  128. AsyncCallback callback, object state)
  129. {
  130. throw new NotImplementedException ();
  131. }
  132. [MonoTODO]
  133. protected override void OnEndClose (IAsyncResult result)
  134. {
  135. throw new NotImplementedException ();
  136. }
  137. [MonoTODO]
  138. protected override void OnClose (TimeSpan timeout)
  139. {
  140. }
  141. }
  142. }