1 //------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //------------------------------------------------------------
5 namespace System
.ServiceModel
.Channels
7 using System
.ComponentModel
;
8 using System
.ServiceModel
;
9 using System
.ServiceModel
.Configuration
;
10 using System
.ServiceModel
.Description
;
11 using System
.ServiceModel
.Dispatcher
;
12 using System
.ServiceModel
.PeerResolvers
;
14 [ObsoleteAttribute ("PeerChannel feature is obsolete and will be removed in the future.", false)]
15 public sealed class PeerCustomResolverBindingElement
: PeerResolverBindingElement
17 EndpointAddress address
;
19 string bindingSection
, bindingConfiguration
;
20 //this should be PeerCustomResolver?
21 PeerResolver resolver
;
22 ClientCredentials credentials
;
23 PeerReferralPolicy referralPolicy
;
25 public PeerCustomResolverBindingElement() { }
26 public PeerCustomResolverBindingElement(PeerCustomResolverBindingElement other
)
29 this.address
= other
.address
;
30 this.bindingConfiguration
= other
.bindingConfiguration
;
31 this.bindingSection
= other
.bindingSection
;
32 this.binding
= other
.binding
;
33 this.resolver
= other
.resolver
;
34 this.credentials
= other
.credentials
;
37 public PeerCustomResolverBindingElement(PeerCustomResolverSettings settings
)
41 this.address
= settings
.Address
;
42 this.binding
= settings
.Binding
;
43 this.resolver
= settings
.Resolver
;
44 this.bindingConfiguration
= settings
.BindingConfiguration
;
45 this.bindingSection
= settings
.BindingSection
;
49 public PeerCustomResolverBindingElement(BindingContext context
, PeerCustomResolverSettings settings
)
53 throw DiagnosticUtility
.ExceptionUtility
.ThrowHelperError(new ArgumentNullException("context"));
55 #pragma warning suppress 56506 // Microsoft, context.BindingParameters is never null
56 credentials
= context
.BindingParameters
.Find
<ClientCredentials
>();
58 public override T GetProperty
<T
>(System
.ServiceModel
.Channels
.BindingContext context
)
60 #pragma warning suppress 56506 // context could be null. Pre-4.0 behaviour, won't fix in Dev10.
61 return context
.GetInnerProperty
<T
>();
63 public EndpointAddress Address
75 public Binding Binding
87 public override PeerReferralPolicy ReferralPolicy
91 return referralPolicy
;
95 if (!PeerReferralPolicyHelper
.IsDefined(value))
97 throw DiagnosticUtility
.ExceptionUtility
.ThrowHelperError(new InvalidEnumArgumentException("value", (int)value, typeof(PeerReferralPolicy
)));
99 referralPolicy
= value;
103 public override BindingElement
Clone()
105 return new PeerCustomResolverBindingElement(this);
108 public override IChannelFactory
<TChannel
> BuildChannelFactory
<TChannel
>(BindingContext context
)
111 throw DiagnosticUtility
.ExceptionUtility
.ThrowHelperError(new ArgumentNullException("context"));
113 #pragma warning suppress 56506 // Microsoft, context.BindingParameters is never null
114 context
.BindingParameters
.Add(this);
115 credentials
= context
.BindingParameters
.Find
<ClientCredentials
>();
116 return context
.BuildInnerChannelFactory
<TChannel
>();
119 public override bool CanBuildChannelFactory
<TChannel
>(BindingContext context
)
122 throw DiagnosticUtility
.ExceptionUtility
.ThrowHelperError(new ArgumentNullException("context"));
123 #pragma warning suppress 56506 // Microsoft, context.BindingParameters is never null
124 this.credentials
= context
.BindingParameters
.Find
<ClientCredentials
>();
125 context
.BindingParameters
.Add(this);
126 return context
.CanBuildInnerChannelFactory
<TChannel
>();
129 public override IChannelListener
<TChannel
> BuildChannelListener
<TChannel
>(BindingContext context
)
132 throw DiagnosticUtility
.ExceptionUtility
.ThrowHelperError(new ArgumentNullException("context"));
134 #pragma warning suppress 56506 // Microsoft, context.BindingParameters is never null
135 context
.BindingParameters
.Add(this);
136 this.credentials
= context
.BindingParameters
.Find
<ClientCredentials
>();
137 return context
.BuildInnerChannelListener
<TChannel
>();
140 public override bool CanBuildChannelListener
<TChannel
>(BindingContext context
)
143 throw DiagnosticUtility
.ExceptionUtility
.ThrowHelperError(new ArgumentNullException("context"));
144 #pragma warning suppress 56506 // Microsoft, context.BindingParameters is never null
145 this.credentials
= context
.BindingParameters
.Find
<ClientCredentials
>();
146 context
.BindingParameters
.Add(this);
147 return context
.CanBuildInnerChannelListener
<TChannel
>();
150 public override PeerResolver
CreatePeerResolver()
152 if (resolver
== null)
154 if (address
== null || ((binding
== null) && (String
.IsNullOrEmpty(this.bindingSection
) || String
.IsNullOrEmpty(this.bindingConfiguration
))))
155 PeerExceptionHelper
.ThrowArgument_InsufficientResolverSettings();
158 this.binding
= ConfigLoader
.LookupBinding(this.bindingSection
, this.bindingConfiguration
);
160 PeerExceptionHelper
.ThrowArgument_InsufficientResolverSettings();
162 resolver
= new PeerDefaultCustomResolverClient();
164 if (resolver
!= null)
166 resolver
.Initialize(address
, binding
, credentials
, this.referralPolicy
);
167 if (resolver
is PeerDefaultCustomResolverClient
)
169 (resolver
as PeerDefaultCustomResolverClient
).BindingName
= this.bindingSection
;
170 (resolver
as PeerDefaultCustomResolverClient
).BindingConfigurationName
= this.bindingConfiguration
;