| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Collections.Generic; |
| | | 6 | | using System.Collections.ObjectModel; |
| | | 7 | | using System.ComponentModel; |
| | | 8 | | using System.Linq; |
| | | 9 | | using System.Text; |
| | | 10 | | using System.Xml; |
| | | 11 | | using CoreWCF.Channels; |
| | | 12 | | using CoreWCF.Collections.Generic; |
| | | 13 | | using CoreWCF.Dispatcher; |
| | | 14 | | using CoreWCF.Runtime; |
| | | 15 | | using CoreWCF.Security; |
| | | 16 | | |
| | | 17 | | namespace CoreWCF.Description |
| | | 18 | | { |
| | | 19 | | public class ServiceMetadataBehavior : IServiceBehavior |
| | | 20 | | { |
| | | 21 | | public const string MexContractName = "IMetadataExchange"; |
| | | 22 | | internal const string MexContractNamespace = "http://schemas.microsoft.com/2006/04/mex"; |
| | | 23 | | private Uri _httpGetUrl; |
| | | 24 | | private Uri _httpsGetUrl; |
| | | 25 | | private Uri _externalMetadataLocation = null; |
| | | 26 | | private MetadataExporter _metadataExporter = null; |
| | 0 | 27 | | private static ContractDescription s_mexContract = null; |
| | 0 | 28 | | private static readonly object s_thisLock = new object(); |
| | | 29 | | |
| | 45 | 30 | | public bool HttpGetEnabled { get; set; } = false; |
| | | 31 | | |
| | | 32 | | [TypeConverter(typeof(UriTypeConverter))] |
| | | 33 | | public Uri HttpGetUrl |
| | | 34 | | { |
| | 0 | 35 | | get { return _httpGetUrl; } |
| | | 36 | | set |
| | | 37 | | { |
| | 1 | 38 | | if (value != null && value.IsAbsoluteUri && value.Scheme != Uri.UriSchemeHttp) |
| | | 39 | | { |
| | 0 | 40 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.Format(SR.SFxServiceMetadataBehavior |
| | 0 | 41 | | nameof(HttpGetUrl), Uri.UriSchemeHttp, value.ToString(), value.Scheme)); |
| | | 42 | | } |
| | | 43 | | |
| | 1 | 44 | | _httpGetUrl = value; |
| | 1 | 45 | | } |
| | | 46 | | } |
| | | 47 | | |
| | 31 | 48 | | public bool HttpsGetEnabled { get; set; } = false; |
| | | 49 | | |
| | | 50 | | [TypeConverter(typeof(UriTypeConverter))] |
| | | 51 | | public Uri HttpsGetUrl |
| | | 52 | | { |
| | 0 | 53 | | get { return _httpsGetUrl; } |
| | | 54 | | set |
| | | 55 | | { |
| | 0 | 56 | | if (value != null && value.IsAbsoluteUri && value.Scheme != Uri.UriSchemeHttps) |
| | | 57 | | { |
| | 0 | 58 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.Format(SR.SFxServiceMetadataBehavior |
| | 0 | 59 | | nameof(HttpsGetUrl), Uri.UriSchemeHttps, value.ToString(), value.Scheme)); |
| | | 60 | | } |
| | | 61 | | |
| | 0 | 62 | | _httpsGetUrl = value; |
| | 0 | 63 | | } |
| | | 64 | | } |
| | | 65 | | |
| | | 66 | | [TypeConverter(typeof(UriTypeConverter))] |
| | | 67 | | public Uri ExternalMetadataLocation |
| | | 68 | | { |
| | 49 | 69 | | get { return _externalMetadataLocation; } |
| | | 70 | | set |
| | | 71 | | { |
| | 0 | 72 | | if (value != null && value.IsAbsoluteUri && !(value.Scheme == Uri.UriSchemeHttp || value.Scheme == Uri.U |
| | | 73 | | { |
| | 0 | 74 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(ExternalMetadataLocation), SR.Fo |
| | | 75 | | } |
| | | 76 | | |
| | 0 | 77 | | _externalMetadataLocation = value; |
| | 0 | 78 | | } |
| | | 79 | | } |
| | | 80 | | |
| | | 81 | | public MetadataExporter MetadataExporter |
| | | 82 | | { |
| | | 83 | | get |
| | | 84 | | { |
| | 24 | 85 | | if (_metadataExporter == null) |
| | | 86 | | { |
| | 23 | 87 | | _metadataExporter = new WsdlExporter(); |
| | | 88 | | } |
| | | 89 | | |
| | 24 | 90 | | return _metadataExporter; |
| | | 91 | | } |
| | | 92 | | set |
| | | 93 | | { |
| | 0 | 94 | | _metadataExporter = value; |
| | 0 | 95 | | } |
| | | 96 | | } |
| | | 97 | | |
| | | 98 | | internal static ContractDescription MexContract |
| | | 99 | | { |
| | | 100 | | get |
| | | 101 | | { |
| | 0 | 102 | | EnsureMexContractDescription(); |
| | 0 | 103 | | return s_mexContract; |
| | | 104 | | } |
| | | 105 | | } |
| | | 106 | | |
| | 25 | 107 | | void IServiceBehavior.Validate(ServiceDescription description, ServiceHostBase serviceHostBase) { } |
| | | 108 | | |
| | 57 | 109 | | void IServiceBehavior.AddBindingParameters(ServiceDescription description, ServiceHostBase serviceHostBase, Coll |
| | | 110 | | |
| | | 111 | | void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase) |
| | | 112 | | { |
| | 25 | 113 | | if (description == null) |
| | | 114 | | { |
| | 0 | 115 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(description)); |
| | | 116 | | } |
| | | 117 | | |
| | 25 | 118 | | if (serviceHostBase == null) |
| | | 119 | | { |
| | 0 | 120 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(serviceHostBase)); |
| | | 121 | | } |
| | | 122 | | |
| | 25 | 123 | | ApplyBehavior(description, serviceHostBase); |
| | 25 | 124 | | } |
| | | 125 | | |
| | | 126 | | private void ApplyBehavior(ServiceDescription description, ServiceHostBase host) |
| | | 127 | | { |
| | 25 | 128 | | ServiceMetadataExtension mex = ServiceMetadataExtension.EnsureServiceMetadataExtension(host); |
| | 25 | 129 | | SetExtensionProperties(description, host, mex); |
| | 25 | 130 | | } |
| | | 131 | | |
| | | 132 | | private void SetExtensionProperties(ServiceDescription description, ServiceHostBase host, ServiceMetadataExtensi |
| | | 133 | | { |
| | 25 | 134 | | mex.ExternalMetadataLocation = ExternalMetadataLocation; |
| | 25 | 135 | | mex.Initializer = new MetadataExtensionInitializer(this, description, host); |
| | 25 | 136 | | mex.HttpGetEnabled = HttpGetEnabled; |
| | 25 | 137 | | mex.HttpsGetEnabled = HttpsGetEnabled; |
| | | 138 | | |
| | 25 | 139 | | mex.HttpGetUrl = host.GetVia(Uri.UriSchemeHttp, GetFirstEndpointUriForScheme(Uri.UriSchemeHttp, _httpGetUrl, |
| | 25 | 140 | | mex.HttpsGetUrl = host.GetVia(Uri.UriSchemeHttps, GetFirstEndpointUriForScheme(Uri.UriSchemeHttps, _httpsGet |
| | | 141 | | |
| | 116 | 142 | | foreach (ChannelDispatcherBase dispatcherBase in host.ChannelDispatchers) |
| | | 143 | | { |
| | 33 | 144 | | if (dispatcherBase is ChannelDispatcher dispatcher && IsMetadataTransferDispatcher(description, dispatch |
| | | 145 | | { |
| | 0 | 146 | | mex.MexEnabled = true; |
| | 0 | 147 | | throw new NotImplementedException(); |
| | | 148 | | //mex.MexUrl = dispatcher.Listener.Uri; |
| | | 149 | | |
| | | 150 | | //if (dynamicUpdateBehavior != null) |
| | | 151 | | //{ |
| | | 152 | | // foreach (EndpointDispatcher endpointDispatcher in dispatcher.Endpoints) |
| | | 153 | | // { |
| | | 154 | | // if (!endpointDispatcher.AddressFilterSetExplicit) |
| | | 155 | | // { |
| | | 156 | | // endpointDispatcher.AddressFilter = new MatchAllMessageFilter(); |
| | | 157 | | // } |
| | | 158 | | // } |
| | | 159 | | //} |
| | | 160 | | //break; |
| | | 161 | | } |
| | | 162 | | } |
| | 25 | 163 | | } |
| | | 164 | | |
| | | 165 | | private static Uri GetFirstEndpointUriForScheme(string uriScheme, Uri configuredGetUrl, ServiceDescription descr |
| | 50 | 166 | | => configuredGetUrl |
| | 50 | 167 | | ?? description?.Endpoints?.FirstOrDefault(endpoint => |
| | 57 | 168 | | string.Equals(endpoint?.Address?.Uri?.Scheme, uriScheme, StringComparison.Ordinal)) |
| | 50 | 169 | | ?.Address?.Uri |
| | 50 | 170 | | ?? new Uri(string.Empty, UriKind.Relative); |
| | | 171 | | |
| | | 172 | | private static EndpointDispatcher GetListenerByID(SynchronizedCollection<ChannelDispatcherBase> channelDispatche |
| | | 173 | | { |
| | 102 | 174 | | for (int i = 0; i < channelDispatchers.Count; ++i) |
| | | 175 | | { |
| | 51 | 176 | | if (channelDispatchers[i] is ChannelDispatcher channelDispatcher) |
| | | 177 | | { |
| | 140 | 178 | | for (int j = 0; j < channelDispatcher.Endpoints.Count; ++j) |
| | | 179 | | { |
| | 51 | 180 | | EndpointDispatcher endpointDispatcher = channelDispatcher.Endpoints[j]; |
| | 51 | 181 | | if (endpointDispatcher.Id == id) |
| | | 182 | | { |
| | 32 | 183 | | return endpointDispatcher; |
| | | 184 | | } |
| | | 185 | | } |
| | | 186 | | } |
| | | 187 | | } |
| | | 188 | | |
| | 0 | 189 | | return null; |
| | | 190 | | } |
| | | 191 | | |
| | | 192 | | private static bool IsMetadataTransferDispatcher(ServiceDescription description, ChannelDispatcher channelDispat |
| | | 193 | | { |
| | 33 | 194 | | if (BehaviorMissingObjectNullOrServiceImplements(description, channelDispatcher)) |
| | | 195 | | { |
| | 0 | 196 | | return false; |
| | | 197 | | } |
| | | 198 | | |
| | 132 | 199 | | foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints) |
| | | 200 | | { |
| | 33 | 201 | | if (endpointDispatcher.ContractName == MexContractName |
| | 33 | 202 | | && endpointDispatcher.ContractNamespace == MexContractNamespace) |
| | | 203 | | { |
| | 0 | 204 | | return true; |
| | | 205 | | } |
| | | 206 | | } |
| | | 207 | | |
| | 33 | 208 | | return false; |
| | 0 | 209 | | } |
| | | 210 | | |
| | | 211 | | private static bool BehaviorMissingObjectNullOrServiceImplements(ServiceDescription description, object obj) |
| | | 212 | | { |
| | 33 | 213 | | if (obj == null) |
| | | 214 | | { |
| | 0 | 215 | | return true; |
| | | 216 | | } |
| | | 217 | | |
| | 33 | 218 | | if (description.Behaviors != null && description.Behaviors.Find<ServiceMetadataBehavior>() == null) |
| | | 219 | | { |
| | 0 | 220 | | return true; |
| | | 221 | | } |
| | | 222 | | |
| | 33 | 223 | | if (description.ServiceType != null && description.ServiceType.GetInterface(typeof(IMetadataExchange).Name) |
| | | 224 | | { |
| | 0 | 225 | | return true; |
| | | 226 | | } |
| | | 227 | | |
| | 33 | 228 | | return false; |
| | | 229 | | } |
| | | 230 | | |
| | | 231 | | internal static bool IsHttpGetMetadataDispatcher(ServiceDescription description, ChannelDispatcher channelDispat |
| | | 232 | | { |
| | 0 | 233 | | if (description.Behaviors.Find<ServiceMetadataBehavior>() == null) |
| | | 234 | | { |
| | 0 | 235 | | return false; |
| | | 236 | | } |
| | | 237 | | |
| | 0 | 238 | | foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints) |
| | | 239 | | { |
| | 0 | 240 | | if (endpointDispatcher.ContractName == ServiceMetadataExtension.HttpGetImpl.ContractName |
| | 0 | 241 | | && endpointDispatcher.ContractNamespace == ServiceMetadataExtension.HttpGetImpl.ContractNamespace) |
| | | 242 | | { |
| | 0 | 243 | | return true; |
| | | 244 | | } |
| | | 245 | | } |
| | | 246 | | |
| | 0 | 247 | | return false; |
| | 0 | 248 | | } |
| | | 249 | | |
| | | 250 | | internal static bool IsMetadataEndpoint(ServiceDescription description, ServiceEndpoint endpoint) |
| | | 251 | | { |
| | 0 | 252 | | if (BehaviorMissingObjectNullOrServiceImplements(description, endpoint)) |
| | | 253 | | { |
| | 0 | 254 | | return false; |
| | | 255 | | } |
| | | 256 | | |
| | 0 | 257 | | return IsMetadataEndpoint(endpoint); |
| | | 258 | | |
| | | 259 | | } |
| | | 260 | | |
| | | 261 | | private static bool IsMetadataEndpoint(ServiceEndpoint endpoint) |
| | | 262 | | { |
| | 0 | 263 | | return endpoint.Contract.Name == MexContractName |
| | 0 | 264 | | && endpoint.Contract.Namespace == MexContractNamespace; |
| | | 265 | | } |
| | | 266 | | |
| | | 267 | | internal static bool IsMetadataImplementedType(ServiceDescription description, Type type) |
| | | 268 | | { |
| | 0 | 269 | | if (BehaviorMissingObjectNullOrServiceImplements(description, type)) |
| | | 270 | | { |
| | 0 | 271 | | return false; |
| | | 272 | | } |
| | | 273 | | |
| | 0 | 274 | | return type == typeof(IMetadataExchange); |
| | | 275 | | } |
| | | 276 | | |
| | | 277 | | internal static bool IsMetadataImplementedType(Type type) |
| | | 278 | | { |
| | 0 | 279 | | return type == typeof(IMetadataExchange); |
| | | 280 | | } |
| | | 281 | | |
| | | 282 | | private static void EnsureMexContractDescription() |
| | | 283 | | { |
| | 0 | 284 | | if (s_mexContract == null) |
| | | 285 | | { |
| | 0 | 286 | | lock (s_thisLock) |
| | | 287 | | { |
| | 0 | 288 | | if (s_mexContract == null) |
| | | 289 | | { |
| | 0 | 290 | | s_mexContract = CreateMexContract(); |
| | | 291 | | } |
| | 0 | 292 | | } |
| | | 293 | | } |
| | 0 | 294 | | } |
| | | 295 | | |
| | | 296 | | private static ContractDescription CreateMexContract() |
| | | 297 | | { |
| | | 298 | | // Using ServiceMetadataBehavior as a dummy type to pass to GetContract as it doesn't actually need the type |
| | | 299 | | // to be passed. |
| | 0 | 300 | | ContractDescription mexContract = ContractDescription.GetContract<ServiceMetadataBehavior>(typeof(IMetadataE |
| | 0 | 301 | | foreach (OperationDescription operation in mexContract.Operations) |
| | | 302 | | { |
| | 0 | 303 | | ((KeyedByTypeCollection<IOperationBehavior>)operation.OperationBehaviors).Find<OperationBehaviorAttribut |
| | | 304 | | } |
| | | 305 | | |
| | 0 | 306 | | mexContract.ContractBehaviors.Add(new ServiceMetadataContractBehavior(true)); |
| | 0 | 307 | | return mexContract; |
| | | 308 | | } |
| | | 309 | | |
| | | 310 | | internal class MetadataExtensionInitializer |
| | | 311 | | { |
| | | 312 | | private readonly ServiceMetadataBehavior _behavior; |
| | | 313 | | private readonly ServiceDescription _description; |
| | | 314 | | private readonly ServiceHostBase _host; |
| | | 315 | | private Exception _metadataGenerationException = null; |
| | | 316 | | |
| | 25 | 317 | | internal MetadataExtensionInitializer(ServiceMetadataBehavior behavior, ServiceDescription description, Serv |
| | | 318 | | { |
| | 25 | 319 | | _behavior = behavior; |
| | 25 | 320 | | _description = description; |
| | 25 | 321 | | _host = host; |
| | 25 | 322 | | } |
| | | 323 | | |
| | | 324 | | internal MetadataSet GenerateMetadata() |
| | | 325 | | { |
| | 24 | 326 | | if (_behavior.ExternalMetadataLocation == null || _behavior.ExternalMetadataLocation.ToString() == strin |
| | | 327 | | { |
| | 24 | 328 | | if (_metadataGenerationException != null) |
| | | 329 | | { |
| | 0 | 330 | | throw _metadataGenerationException; |
| | | 331 | | } |
| | | 332 | | |
| | | 333 | | try |
| | | 334 | | { |
| | 24 | 335 | | MetadataExporter exporter = _behavior.MetadataExporter; |
| | 24 | 336 | | XmlQualifiedName serviceName = new XmlQualifiedName(_description.Name, _description.Namespace); |
| | 24 | 337 | | Collection<ServiceEndpoint> exportedEndpoints = new Collection<ServiceEndpoint>(); |
| | 112 | 338 | | foreach (ServiceEndpoint endpoint in _description.Endpoints) |
| | | 339 | | { |
| | 32 | 340 | | ServiceMetadataContractBehavior contractBehavior = ((KeyedByTypeCollection<IContractBehavior |
| | | 341 | | |
| | | 342 | | // if contract behavior exists, generate metadata when the behavior allows metadata generati |
| | | 343 | | // if contract behavior doesn't exist, generate metadata only for non system endpoints |
| | 32 | 344 | | if ((contractBehavior != null && !contractBehavior.MetadataGenerationDisabled) || |
| | 32 | 345 | | (contractBehavior == null && !endpoint.IsSystemEndpoint)) |
| | | 346 | | { |
| | 32 | 347 | | EndpointAddress address = null; |
| | 32 | 348 | | EndpointDispatcher endpointDispatcher = GetListenerByID(_host.ChannelDispatchers, endpoi |
| | 32 | 349 | | if (endpointDispatcher != null) |
| | | 350 | | { |
| | 32 | 351 | | address = endpointDispatcher.EndpointAddress; |
| | | 352 | | } |
| | | 353 | | |
| | 32 | 354 | | ServiceEndpoint exportedEndpoint = new ServiceEndpoint(endpoint.Contract) |
| | 32 | 355 | | { |
| | 32 | 356 | | Binding = endpoint.Binding, |
| | 32 | 357 | | Name = endpoint.Name, |
| | 32 | 358 | | Address = address |
| | 32 | 359 | | }; |
| | 128 | 360 | | foreach (IEndpointBehavior behavior in endpoint.EndpointBehaviors) |
| | | 361 | | { |
| | 32 | 362 | | exportedEndpoint.EndpointBehaviors.Add(behavior); |
| | | 363 | | } |
| | | 364 | | |
| | 32 | 365 | | exportedEndpoints.Add(exportedEndpoint); |
| | | 366 | | } |
| | | 367 | | } |
| | | 368 | | |
| | 24 | 369 | | if (exporter is WsdlExporter wsdlExporter) |
| | | 370 | | { |
| | | 371 | | // Fix issue with shared exporter. Need to do comparison of Type objects as "is" will return |
| | 24 | 372 | | if (exporter.GetType() == typeof(WsdlExporter)) |
| | | 373 | | { |
| | 24 | 374 | | exporter = wsdlExporter = wsdlExporter.Clone(); |
| | | 375 | | } |
| | | 376 | | |
| | | 377 | | // Pass the BindingParameterCollection into the ExportEndpoints method so that the binding p |
| | | 378 | | // The binding parameters are used in BuildChannelListener, during which they can modify the |
| | | 379 | | // be communicated in the WSDL. For example, in the case of Multi-Auth, the AuthenticationSc |
| | | 380 | | // to set the AuthenticationSchemes supported by the virtual directory on the HttpTransportB |
| | | 381 | | // to be in the WSDL, so that clients know what authentication schemes are supported by the |
| | | 382 | | Fx.Assert(_host != null, "ServiceHostBase field on MetadataExtensionInitializer should never |
| | 24 | 383 | | wsdlExporter.ExportEndpoints(exportedEndpoints, serviceName, GetBindingParameters(_host, exp |
| | | 384 | | } |
| | | 385 | | else |
| | | 386 | | { |
| | 0 | 387 | | foreach (ServiceEndpoint endpoint in exportedEndpoints) |
| | | 388 | | { |
| | 0 | 389 | | exporter.ExportEndpoint(endpoint); |
| | | 390 | | } |
| | | 391 | | } |
| | | 392 | | |
| | | 393 | | //if (exporter.Errors.Count > 0 && DiagnosticUtility.ShouldTraceWarning) |
| | | 394 | | //{ |
| | | 395 | | // TraceWsdlExportErrors(exporter); |
| | | 396 | | //} |
| | | 397 | | |
| | 24 | 398 | | return exporter.GetGeneratedMetadata(); |
| | | 399 | | } |
| | 0 | 400 | | catch (Exception e) |
| | | 401 | | { |
| | 0 | 402 | | _metadataGenerationException = e; |
| | 0 | 403 | | throw; |
| | | 404 | | } |
| | | 405 | | } |
| | | 406 | | |
| | 0 | 407 | | return null; |
| | 24 | 408 | | } |
| | | 409 | | |
| | | 410 | | private BindingParameterCollection GetBindingParameters(ServiceHostBase serviceHost, Collection<ServiceEndpo |
| | | 411 | | { |
| | 24 | 412 | | BindingParameterCollection parameters = new BindingParameterCollection(); |
| | 254 | 413 | | foreach (IServiceBehavior behavior in serviceHost.Description.Behaviors) |
| | | 414 | | { |
| | 103 | 415 | | behavior.AddBindingParameters(serviceHost.Description, serviceHost, endpoints, parameters); |
| | | 416 | | } |
| | | 417 | | |
| | 112 | 418 | | foreach (ServiceEndpoint endpoint in endpoints) |
| | | 419 | | { |
| | 32 | 420 | | AddBindingParametersForSecurityContractInformation(endpoint, parameters); |
| | 128 | 421 | | foreach (IContractBehavior icb in endpoint.Contract.ContractBehaviors) |
| | | 422 | | { |
| | 32 | 423 | | icb.AddBindingParameters(endpoint.Contract, endpoint, parameters); |
| | | 424 | | } |
| | | 425 | | |
| | 128 | 426 | | foreach (IEndpointBehavior ieb in endpoint.EndpointBehaviors) |
| | | 427 | | { |
| | 32 | 428 | | ieb.AddBindingParameters(endpoint, parameters); |
| | | 429 | | } |
| | | 430 | | |
| | 382 | 431 | | foreach (OperationDescription op in endpoint.Contract.Operations) |
| | | 432 | | { |
| | 1272 | 433 | | foreach (IOperationBehavior iob in op.OperationBehaviors) |
| | | 434 | | { |
| | 477 | 435 | | iob.AddBindingParameters(op, parameters); |
| | | 436 | | } |
| | | 437 | | } |
| | | 438 | | } |
| | | 439 | | |
| | 24 | 440 | | return parameters; |
| | | 441 | | } |
| | | 442 | | |
| | | 443 | | internal static void AddBindingParametersForSecurityContractInformation(ServiceEndpoint endpoint, BindingPar |
| | | 444 | | { |
| | | 445 | | // get Contract info security needs, and put in BindingParameterCollection |
| | 32 | 446 | | ISecurityCapabilities isc = null; |
| | 32 | 447 | | BindingElementCollection elements = endpoint.Binding.CreateBindingElements(); |
| | 152 | 448 | | for (int i = 0; i < elements.Count; ++i) |
| | | 449 | | { |
| | 54 | 450 | | if (!(elements[i] is ITransportTokenAssertionProvider)) |
| | | 451 | | { |
| | 51 | 452 | | ISecurityCapabilities tmp = elements[i].GetProperty<ISecurityCapabilities>(new BindingContext(ne |
| | 51 | 453 | | if (tmp != null) |
| | | 454 | | { |
| | 10 | 455 | | isc = tmp; |
| | 10 | 456 | | break; |
| | | 457 | | } |
| | | 458 | | } |
| | | 459 | | } |
| | | 460 | | |
| | 32 | 461 | | if (isc != null) |
| | | 462 | | { |
| | | 463 | | // ensure existence of binding parameter |
| | 10 | 464 | | ChannelProtectionRequirements requirements = parameters.Find<ChannelProtectionRequirements>(); |
| | 10 | 465 | | if (requirements == null) |
| | | 466 | | { |
| | 3 | 467 | | requirements = new ChannelProtectionRequirements(); |
| | 3 | 468 | | parameters.Add(requirements); |
| | | 469 | | } |
| | | 470 | | |
| | 10 | 471 | | MessageEncodingBindingElement encoding = elements.Find<MessageEncodingBindingElement>(); |
| | | 472 | | // use endpoint.Binding.Version |
| | 10 | 473 | | if (encoding != null && encoding.MessageVersion.Addressing == AddressingVersion.None) |
| | | 474 | | { |
| | | 475 | | // This binding does not support response actions, so... |
| | 0 | 476 | | requirements.Add(ChannelProtectionRequirements.CreateFromContractAndUnionResponseProtectionRequi |
| | | 477 | | } |
| | | 478 | | else |
| | | 479 | | { |
| | 10 | 480 | | requirements.Add(ChannelProtectionRequirements.CreateFromContract(endpoint.Contract, isc)); |
| | | 481 | | } |
| | | 482 | | } |
| | 32 | 483 | | } |
| | | 484 | | } |
| | | 485 | | } |
| | | 486 | | } |