TcpChannelFactory.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. namespace System.ServiceModel.Channels
  18. {
  19. internal class TcpChannelInfo
  20. {
  21. public TcpChannelInfo (TcpTransportBindingElement element, MessageEncoder encoder)
  22. {
  23. this.element = element;
  24. this.encoder = encoder;
  25. }
  26. TcpTransportBindingElement element;
  27. MessageEncoder encoder;
  28. public TcpTransportBindingElement BindingElement {
  29. get { return element; }
  30. }
  31. public MessageEncoder MessageEncoder {
  32. get { return encoder; }
  33. }
  34. }
  35. internal class TcpChannelFactory<TChannel> : ChannelFactoryBase<TChannel>
  36. {
  37. TcpChannelInfo info;
  38. [MonoTODO]
  39. public TcpChannelFactory (TcpTransportBindingElement source, BindingContext ctx)
  40. {
  41. MessageEncoder encoder = null;
  42. foreach (BindingElement be in ctx.RemainingBindingElements) {
  43. MessageEncodingBindingElement mbe = be as MessageEncodingBindingElement;
  44. if (mbe != null) {
  45. encoder = mbe.CreateMessageEncoderFactory ().Encoder;
  46. break;
  47. }
  48. }
  49. if (encoder == null)
  50. encoder = new BinaryMessageEncoder ();
  51. info = new TcpChannelInfo (source, encoder);
  52. }
  53. [MonoTODO]
  54. protected override TChannel OnCreateChannel (
  55. EndpointAddress address, Uri via)
  56. {
  57. ThrowIfDisposedOrNotOpen ();
  58. if (info.BindingElement.Scheme != address.Uri.Scheme)
  59. throw new ArgumentException (String.Format ("Argument EndpointAddress has unsupported URI scheme: {0}", address.Uri.Scheme));
  60. Type t = typeof (TChannel);
  61. if (t == typeof (IDuplexSessionChannel))
  62. return (TChannel) (object) new TcpDuplexSessionChannel (this, info, address, via);
  63. throw new InvalidOperationException (String.Format ("Channel type {0} is not supported.", typeof (TChannel).Name));
  64. }
  65. [MonoTODO]
  66. protected override IAsyncResult OnBeginOpen (TimeSpan timeout,
  67. AsyncCallback callback, object state)
  68. {
  69. throw new NotImplementedException ();
  70. }
  71. [MonoTODO]
  72. protected override void OnEndOpen (IAsyncResult result)
  73. {
  74. throw new NotImplementedException ();
  75. }
  76. [MonoTODO]
  77. protected override void OnOpen (TimeSpan timeout)
  78. {
  79. }
  80. }
  81. }