UdpTransportBindingElement.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // Author: Atsushi Enomoto <[email protected]>
  3. //
  4. // Copyright (C) 2010 Novell, Inc (http://www.novell.com)
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining
  7. // a copy of this software and associated documentation files (the
  8. // "Software"), to deal in the Software without restriction, including
  9. // without limitation the rights to use, copy, modify, merge, publish,
  10. // distribute, sublicense, and/or sell copies of the Software, and to
  11. // permit persons to whom the Software is furnished to do so, subject to
  12. // the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be
  15. // included in all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. //
  25. using System;
  26. using System.IO;
  27. using System.Net.Sockets;
  28. using System.ServiceModel;
  29. using System.ServiceModel.Channels;
  30. namespace System.ServiceModel.Discovery
  31. {
  32. internal class UdpTransportBindingElement : TransportBindingElement
  33. {
  34. public UdpTransportBindingElement ()
  35. : this (new UdpTransportSettings ())
  36. {
  37. }
  38. public UdpTransportBindingElement (UdpTransportSettings settings)
  39. {
  40. this.settings = settings ?? new UdpTransportSettings ();
  41. }
  42. private UdpTransportBindingElement (UdpTransportBindingElement other)
  43. {
  44. settings = new UdpTransportSettings (other.settings);
  45. }
  46. public override string Scheme {
  47. get { return "soap.udp"; }
  48. }
  49. UdpTransportSettings settings;
  50. public UdpTransportSettings TransportSettings {
  51. get { return settings; }
  52. }
  53. public override BindingElement Clone ()
  54. {
  55. return new UdpTransportBindingElement (this);
  56. }
  57. public override bool CanBuildChannelFactory<TChannel> (BindingContext ctx)
  58. {
  59. return typeof (TChannel) == typeof (IDuplexChannel);
  60. }
  61. public override bool CanBuildChannelListener<TChannel> (BindingContext ctx)
  62. {
  63. return typeof (TChannel) == typeof (IDuplexChannel);
  64. }
  65. public override IChannelFactory<TChannel> BuildChannelFactory<TChannel> (BindingContext ctx)
  66. {
  67. if (!CanBuildChannelFactory<TChannel> (ctx))
  68. throw new InvalidOperationException (String.Format ("Not supported type of channel: {0}", typeof (TChannel)));
  69. return (IChannelFactory<TChannel>) (object) new UdpChannelFactory (this, ctx);
  70. }
  71. public override IChannelListener<TChannel> BuildChannelListener<TChannel> (BindingContext ctx)
  72. {
  73. if (!CanBuildChannelListener<TChannel> (ctx))
  74. throw new InvalidOperationException (String.Format ("Not supported type of channel: {0}", typeof (TChannel)));
  75. return (IChannelListener<TChannel>) (object) new UdpChannelListener (this, ctx);
  76. }
  77. public override T GetProperty<T> (BindingContext ctx)
  78. {
  79. return ctx.GetInnerProperty<T> ();
  80. }
  81. }
  82. }