TcpChannelFactory.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // TcpChannelFactory.cs
  3. //
  4. // Author:
  5. // Marcos Cobena ([email protected])
  6. //
  7. // Copyright 2007 Marcos Cobena (http://www.youcannoteatbits.org/)
  8. //
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Net;
  12. using System.Net.Security;
  13. using System.ServiceModel;
  14. using System.ServiceModel.Description;
  15. using System.ServiceModel.Security;
  16. using System.Text;
  17. using System.Xml;
  18. namespace System.ServiceModel.Channels
  19. {
  20. internal class TcpChannelInfo
  21. {
  22. public TcpChannelInfo (TransportBindingElement element, MessageEncoder encoder, XmlDictionaryReaderQuotas readerQuotas)
  23. {
  24. this.BindingElement = element;
  25. this.MessageEncoder = encoder;
  26. this.ReaderQuotas = readerQuotas ?? new XmlDictionaryReaderQuotas ();
  27. }
  28. public TransportBindingElement BindingElement { get; private set; }
  29. public MessageEncoder MessageEncoder { get; private set; }
  30. public XmlDictionaryReaderQuotas ReaderQuotas { get; private set; }
  31. }
  32. internal class TcpChannelFactory<TChannel> : ChannelFactoryBase<TChannel>
  33. {
  34. TcpChannelInfo info;
  35. [MonoTODO]
  36. public TcpChannelFactory (TcpTransportBindingElement source, BindingContext ctx)
  37. {
  38. MessageEncoder encoder = null;
  39. XmlDictionaryReaderQuotas quotas = null;
  40. foreach (BindingElement be in ctx.RemainingBindingElements) {
  41. MessageEncodingBindingElement mbe = be as MessageEncodingBindingElement;
  42. if (mbe != null) {
  43. encoder = CreateEncoder<TChannel> (mbe);
  44. quotas = mbe.GetProperty<XmlDictionaryReaderQuotas> (ctx);
  45. break;
  46. }
  47. }
  48. if (encoder == null)
  49. encoder = new BinaryMessageEncoder ();
  50. info = new TcpChannelInfo (source, encoder, quotas);
  51. }
  52. [MonoTODO]
  53. protected override TChannel OnCreateChannel (
  54. EndpointAddress address, Uri via)
  55. {
  56. ThrowIfDisposedOrNotOpen ();
  57. if (info.BindingElement.Scheme != address.Uri.Scheme)
  58. throw new ArgumentException (String.Format ("Argument EndpointAddress has unsupported URI scheme: {0}", address.Uri.Scheme));
  59. Type t = typeof (TChannel);
  60. if (t == typeof (IDuplexSessionChannel))
  61. return (TChannel) (object) new TcpDuplexSessionChannel (this, info, address, via);
  62. throw new InvalidOperationException (String.Format ("Channel type {0} is not supported.", typeof (TChannel).Name));
  63. }
  64. [MonoTODO]
  65. protected override IAsyncResult OnBeginOpen (TimeSpan timeout,
  66. AsyncCallback callback, object state)
  67. {
  68. throw new NotImplementedException ();
  69. }
  70. [MonoTODO]
  71. protected override void OnEndOpen (IAsyncResult result)
  72. {
  73. throw new NotImplementedException ();
  74. }
  75. [MonoTODO]
  76. protected override void OnOpen (TimeSpan timeout)
  77. {
  78. }
  79. }
  80. }