ServiceEndpoint.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // ServiceEndpoint.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.ServiceModel;
  31. using System.ServiceModel.Channels;
  32. using System.ServiceModel.Dispatcher;
  33. namespace System.ServiceModel.Description
  34. {
  35. public class ServiceEndpoint
  36. {
  37. ContractDescription contract;
  38. Binding binding;
  39. EndpointAddress address;
  40. KeyedByTypeCollection<IEndpointBehavior> behaviors;
  41. Uri listen_uri;
  42. ListenUriMode listen_mode;
  43. string name;
  44. public ServiceEndpoint (ContractDescription contract)
  45. : this (contract, null, null)
  46. {
  47. }
  48. public ServiceEndpoint(ContractDescription contract,
  49. Binding binding, EndpointAddress address)
  50. {
  51. if (contract == null)
  52. throw new ArgumentNullException ("contract");
  53. this.contract = contract;
  54. this.binding = binding;
  55. this.address = address;
  56. behaviors = new KeyedByTypeCollection<IEndpointBehavior> ();
  57. }
  58. public KeyedByTypeCollection<IEndpointBehavior> Behaviors {
  59. get { return behaviors; }
  60. }
  61. public ContractDescription Contract {
  62. get { return contract; }
  63. #if NET_4_0
  64. set {
  65. if (value == null)
  66. throw new ArgumentNullException ("value");
  67. contract = value;
  68. }
  69. #endif
  70. }
  71. public EndpointAddress Address {
  72. get { return address; }
  73. set { address = value; }
  74. }
  75. public Binding Binding {
  76. get { return binding; }
  77. set { binding = value; }
  78. }
  79. #if NET_4_0
  80. public
  81. #else
  82. internal
  83. #endif
  84. bool IsSystemEndpoint { get; set; }
  85. public Uri ListenUri {
  86. get { return listen_uri ?? (Address != null ? Address.Uri : null); }
  87. set { listen_uri = value; }
  88. }
  89. public ListenUriMode ListenUriMode {
  90. get { return listen_mode; }
  91. set { listen_mode = value; }
  92. }
  93. public string Name {
  94. get {
  95. if (name == null) {
  96. // do not create cache when either of Binding or Contract is null.
  97. if (Binding == null)
  98. return Contract != null ? Contract.Name : null;
  99. else if (Contract != null)
  100. name = Binding.Name + "_" + Contract.Name;
  101. }
  102. return name;
  103. }
  104. set { name = value; }
  105. }
  106. internal void Validate () {
  107. #if !MOONLIGHT
  108. foreach (IContractBehavior b in Contract.Behaviors)
  109. b.Validate (Contract, this);
  110. foreach (IEndpointBehavior b in Behaviors)
  111. b.Validate (this);
  112. foreach (OperationDescription operation in Contract.Operations) {
  113. foreach (IOperationBehavior b in operation.Behaviors)
  114. b.Validate (operation);
  115. }
  116. #endif
  117. }
  118. internal ClientRuntime CreateClientRuntime (object callbackDispatchRuntime)
  119. {
  120. ServiceEndpoint se = this;
  121. var proxy = se.Contract.CreateClientRuntime (callbackDispatchRuntime);
  122. #if !NET_2_1
  123. foreach (IEndpointBehavior b in se.Behaviors)
  124. b.ApplyClientBehavior (se, proxy);
  125. foreach (IContractBehavior b in se.Contract.Behaviors)
  126. b.ApplyClientBehavior (se.Contract, se, proxy);
  127. #endif
  128. return proxy;
  129. }
  130. }
  131. }