ServiceEndpoint.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. }
  64. public EndpointAddress Address {
  65. get { return address; }
  66. set { address = value; }
  67. }
  68. public Binding Binding {
  69. get { return binding; }
  70. set { binding = value; }
  71. }
  72. public Uri ListenUri {
  73. get { return listen_uri ?? (Address != null ? Address.Uri : null); }
  74. set { listen_uri = value; }
  75. }
  76. public ListenUriMode ListenUriMode {
  77. get { return listen_mode; }
  78. set { listen_mode = value; }
  79. }
  80. public string Name {
  81. get {
  82. if (name == null)
  83. name = Binding.Name + "_" + Contract.Name;
  84. return name;
  85. }
  86. set { name = value; }
  87. }
  88. internal void Validate () {
  89. #if !NET_2_1
  90. foreach (IContractBehavior b in Contract.Behaviors)
  91. b.Validate (Contract, this);
  92. foreach (IEndpointBehavior b in Behaviors)
  93. b.Validate (this);
  94. foreach (OperationDescription operation in Contract.Operations) {
  95. foreach (IOperationBehavior b in operation.Behaviors)
  96. b.Validate (operation);
  97. }
  98. #endif
  99. }
  100. internal ClientRuntime CreateRuntime ()
  101. {
  102. ServiceEndpoint se = this;
  103. var proxy = se.Contract.CreateClientRuntime ();
  104. #if !NET_2_1
  105. foreach (IEndpointBehavior b in se.Behaviors)
  106. b.ApplyClientBehavior (se, proxy);
  107. foreach (IContractBehavior b in se.Contract.Behaviors)
  108. b.ApplyClientBehavior (se.Contract, se, proxy);
  109. #endif
  110. return proxy;
  111. }
  112. }
  113. }