| | | 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.Linq; |
| | | 8 | | using System.Reflection; |
| | | 9 | | using System.Threading.Tasks; |
| | | 10 | | using System.Xml; |
| | | 11 | | using CoreWCF.Channels; |
| | | 12 | | using CoreWCF.Configuration; |
| | | 13 | | using CoreWCF.Dispatcher; |
| | | 14 | | using CoreWCF.Runtime; |
| | | 15 | | using CoreWCF.Security; |
| | | 16 | | using Microsoft.AspNetCore.Authorization; |
| | | 17 | | using Microsoft.AspNetCore.Hosting.Server.Features; |
| | | 18 | | using Microsoft.Extensions.DependencyInjection; |
| | | 19 | | |
| | | 20 | | namespace CoreWCF.Description |
| | | 21 | | { |
| | | 22 | | internal class DispatcherBuilder |
| | | 23 | | { |
| | | 24 | | private static void ValidateDescription(ServiceHostBase serviceHost) |
| | | 25 | | { |
| | 576 | 26 | | ServiceDescription description = serviceHost.Description; |
| | 576 | 27 | | description.EnsureInvariants(); |
| | | 28 | | // TODO: Reenable SecurityValidationBehavior validation |
| | | 29 | | //(SecurityValidationBehavior.Instance as IServiceBehavior).Validate(description, serviceHost); |
| | 576 | 30 | | (new UniqueContractNameValidationBehavior() as IServiceBehavior).Validate(description, serviceHost); |
| | 4850 | 31 | | for (int i = 0; i < description.Behaviors.Count; i++) |
| | | 32 | | { |
| | 1849 | 33 | | IServiceBehavior iServiceBehavior = description.Behaviors[i]; |
| | 1849 | 34 | | iServiceBehavior.Validate(description, serviceHost); |
| | | 35 | | } |
| | 2434 | 36 | | for (int i = 0; i < description.Endpoints.Count; i++) |
| | | 37 | | { |
| | 641 | 38 | | ServiceEndpoint endpoint = description.Endpoints[i]; |
| | 641 | 39 | | ContractDescription contract = endpoint.Contract; |
| | 641 | 40 | | bool alreadyProcessedThisContract = false; |
| | 1284 | 41 | | for (int j = 0; j < i; j++) |
| | | 42 | | { |
| | 65 | 43 | | if (description.Endpoints[j].Contract == contract) |
| | | 44 | | { |
| | 64 | 45 | | alreadyProcessedThisContract = true; |
| | 64 | 46 | | break; |
| | | 47 | | } |
| | | 48 | | } |
| | 641 | 49 | | endpoint.ValidateForService(!alreadyProcessedThisContract); |
| | | 50 | | } |
| | 576 | 51 | | } |
| | | 52 | | |
| | | 53 | | private static void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection parameters) |
| | | 54 | | { |
| | 2576 | 55 | | foreach (IContractBehavior icb in endpoint.Contract.Behaviors) |
| | | 56 | | { |
| | 647 | 57 | | icb.AddBindingParameters(endpoint.Contract, endpoint, parameters); |
| | | 58 | | } |
| | 2720 | 59 | | foreach (IEndpointBehavior ieb in endpoint.Behaviors) |
| | | 60 | | { |
| | 719 | 61 | | ieb.AddBindingParameters(endpoint, parameters); |
| | | 62 | | } |
| | 7338 | 63 | | foreach (OperationDescription op in endpoint.Contract.Operations) |
| | | 64 | | { |
| | 24582 | 65 | | foreach (IOperationBehavior iob in op.Behaviors) |
| | | 66 | | { |
| | 9263 | 67 | | iob.AddBindingParameters(op, parameters); |
| | | 68 | | } |
| | | 69 | | } |
| | 641 | 70 | | } |
| | | 71 | | |
| | | 72 | | private static void EnsureThereAreApplicationEndpoints(ServiceDescription description) |
| | | 73 | | { |
| | 1728 | 74 | | foreach (ServiceEndpoint endpoint in description.Endpoints) |
| | | 75 | | { |
| | 576 | 76 | | if (!endpoint.InternalIsSystemEndpoint(description)) |
| | | 77 | | { |
| | 576 | 78 | | return; |
| | | 79 | | } |
| | | 80 | | } |
| | 0 | 81 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException( |
| | 0 | 82 | | SR.Format(SR.ServiceHasZeroAppEndpoints, descr |
| | 576 | 83 | | } |
| | | 84 | | |
| | | 85 | | internal static Uri EnsureListenUri(ServiceHostBase serviceHost, ServiceEndpoint endpoint) |
| | | 86 | | { |
| | 641 | 87 | | Uri listenUri = endpoint.ListenUri; |
| | 641 | 88 | | if (listenUri == null) |
| | | 89 | | { |
| | | 90 | | // TODO: Make sure the InternalBaseAddresses are populated with the relevant base address for the transp |
| | 0 | 91 | | listenUri = GetVia(endpoint.Binding.Scheme, ServiceHostBase.s_emptyUri, serviceHost.InternalBaseAddresse |
| | | 92 | | } |
| | 641 | 93 | | if (listenUri == null) |
| | | 94 | | { |
| | | 95 | | // TODO: Plumb through expected scheme and update exception message |
| | 0 | 96 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFx |
| | | 97 | | } |
| | 641 | 98 | | return listenUri; |
| | | 99 | | } |
| | | 100 | | |
| | | 101 | | internal static Uri GetVia(string scheme, Uri address, UriSchemeKeyedCollection baseAddresses) |
| | | 102 | | { |
| | 0 | 103 | | Uri via = address; |
| | 0 | 104 | | if (!via.IsAbsoluteUri) |
| | | 105 | | { |
| | 0 | 106 | | if (!baseAddresses.Contains(scheme)) |
| | | 107 | | { |
| | 0 | 108 | | return null; |
| | | 109 | | } |
| | | 110 | | |
| | 0 | 111 | | via = GetUri(baseAddresses[scheme], address.OriginalString); |
| | | 112 | | } |
| | 0 | 113 | | return via; |
| | | 114 | | } |
| | | 115 | | |
| | | 116 | | internal static Uri GetUri(Uri baseUri, string path) |
| | | 117 | | { |
| | 0 | 118 | | if (path.StartsWith("/", StringComparison.Ordinal) || path.StartsWith("\\", StringComparison.Ordinal)) |
| | | 119 | | { |
| | 0 | 120 | | int i = 1; |
| | 0 | 121 | | for (; i < path.Length; ++i) |
| | | 122 | | { |
| | 0 | 123 | | if (path[i] != '/' && path[i] != '\\') |
| | | 124 | | { |
| | | 125 | | break; |
| | | 126 | | } |
| | | 127 | | } |
| | 0 | 128 | | path = path.Substring(i); |
| | | 129 | | } |
| | | 130 | | |
| | | 131 | | // VSWhidbey#541152: new Uri(Uri, string.Empty) is broken |
| | 0 | 132 | | if (path.Length == 0) |
| | | 133 | | { |
| | 0 | 134 | | return baseUri; |
| | | 135 | | } |
| | | 136 | | |
| | 0 | 137 | | if (!baseUri.AbsoluteUri.EndsWith("/", StringComparison.Ordinal)) |
| | | 138 | | { |
| | 0 | 139 | | baseUri = new Uri(baseUri.AbsoluteUri + "/"); |
| | | 140 | | } |
| | 0 | 141 | | return new Uri(baseUri, path); |
| | | 142 | | } |
| | | 143 | | |
| | | 144 | | internal static ListenUriInfo GetListenUriInfoForEndpoint(ServiceHostBase host, ServiceEndpoint endpoint) |
| | | 145 | | { |
| | 641 | 146 | | Uri listenUri = EnsureListenUri(host, endpoint); |
| | 641 | 147 | | return new ListenUriInfo(listenUri, endpoint.ListenUriMode); |
| | | 148 | | } |
| | | 149 | | |
| | | 150 | | internal static void InitializeServiceHost(ServiceHostBase serviceHost, IServiceProvider services) |
| | | 151 | | { |
| | 576 | 152 | | ServiceDescription description = serviceHost.Description; |
| | 576 | 153 | | if (serviceHost.ImplementedContracts != null && serviceHost.ImplementedContracts.Count > 0) |
| | | 154 | | { |
| | 576 | 155 | | EnsureThereAreApplicationEndpoints(description); |
| | | 156 | | } |
| | | 157 | | |
| | 576 | 158 | | ValidateDescription(serviceHost); |
| | | 159 | | |
| | 576 | 160 | | var stuffPerListenUriInfo = new Dictionary<ListenUriInfo, StuffPerListenUriInfo>(); |
| | 576 | 161 | | var endpointInfosPerEndpointAddress = new Dictionary<EndpointAddress, Collection<EndpointInfo>>(); |
| | | 162 | | |
| | | 163 | | // Ensure ListenUri and group endpoints per ListenUri |
| | 2434 | 164 | | for (int i = 0; i < description.Endpoints.Count; i++) |
| | | 165 | | { |
| | 641 | 166 | | ServiceEndpoint endpoint = description.Endpoints[i]; |
| | | 167 | | |
| | 641 | 168 | | ListenUriInfo listenUriInfo = GetListenUriInfoForEndpoint(serviceHost, endpoint); |
| | 641 | 169 | | if (!stuffPerListenUriInfo.ContainsKey(listenUriInfo)) |
| | | 170 | | { |
| | 640 | 171 | | StuffPerListenUriInfo stuff = new StuffPerListenUriInfo(); |
| | 640 | 172 | | stuff.Parameters.Add(services); |
| | 640 | 173 | | stuffPerListenUriInfo.Add(listenUriInfo, stuff); |
| | | 174 | | } |
| | 641 | 175 | | stuffPerListenUriInfo[listenUriInfo].Endpoints.Add(endpoint); |
| | | 176 | | } |
| | | 177 | | |
| | 2432 | 178 | | foreach (KeyValuePair<ListenUriInfo, StuffPerListenUriInfo> stuff in stuffPerListenUriInfo) |
| | | 179 | | { |
| | 640 | 180 | | Uri listenUri = stuff.Key.ListenUri; |
| | 640 | 181 | | BindingParameterCollection parameters = stuff.Value.Parameters; |
| | 640 | 182 | | Binding binding = stuff.Value.Endpoints[0].Binding; |
| | 640 | 183 | | EndpointIdentity identity = stuff.Value.Endpoints[0].Address.Identity; |
| | | 184 | | // same EndpointAddressTable instance must be shared between channelDispatcher and parameters |
| | | 185 | | //ThreadSafeMessageFilterTable<EndpointAddress> endpointAddressTable = new ThreadSafeMessageFilterTable< |
| | | 186 | | //parameters.Add(endpointAddressTable); |
| | | 187 | | |
| | | 188 | | // add service-level binding parameters |
| | 5414 | 189 | | foreach (IServiceBehavior behavior in description.Behaviors) |
| | | 190 | | { |
| | 2067 | 191 | | behavior.AddBindingParameters(description, serviceHost, stuff.Value.Endpoints, parameters); |
| | | 192 | | } |
| | 2562 | 193 | | for (int i = 0; i < stuff.Value.Endpoints.Count; i++) |
| | | 194 | | { |
| | 641 | 195 | | ServiceEndpoint endpoint = stuff.Value.Endpoints[i]; |
| | 641 | 196 | | string viaString = listenUri.AbsoluteUri; |
| | | 197 | | |
| | | 198 | | // ensure all endpoints with this ListenUriInfo have same binding |
| | 641 | 199 | | if (endpoint.Binding != binding) |
| | | 200 | | { |
| | 0 | 201 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma |
| | | 202 | | } |
| | | 203 | | |
| | | 204 | | // ensure all endpoints with this ListenUriInfo have same identity |
| | 641 | 205 | | if (!Equals(endpoint.Address.Identity, identity)) |
| | | 206 | | { |
| | 0 | 207 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException( |
| | 0 | 208 | | SR.Format(SR.SFxWhenMultipleEndpoi |
| | | 209 | | } |
| | | 210 | | |
| | | 211 | | // add binding parameters (endpoint scope and below) |
| | 641 | 212 | | AddBindingParametersForSecurityContractInformation(endpoint, parameters); |
| | 641 | 213 | | AddBindingParameters(endpoint, parameters); |
| | | 214 | | } |
| | | 215 | | |
| | 640 | 216 | | List<Type> channelTypes = GetSupportedChannelTypes(stuff.Value); |
| | | 217 | | |
| | 640 | 218 | | var bindingQname = new XmlQualifiedName(binding.Name, binding.Namespace); |
| | 640 | 219 | | var channelDispatcher = new ChannelDispatcher(listenUri, binding, bindingQname.ToString(), binding, chan |
| | | 220 | | //channelDispatcher.SetEndpointAddressTable(endpointAddressTable); |
| | 640 | 221 | | stuff.Value.ChannelDispatcher = channelDispatcher; |
| | | 222 | | |
| | 2562 | 223 | | for (int i = 0; i < stuff.Value.Endpoints.Count; i++) |
| | | 224 | | { |
| | 641 | 225 | | ServiceEndpoint endpoint = stuff.Value.Endpoints[i]; |
| | | 226 | | |
| | | 227 | | //EndpointFilterProvider provider = new EndpointFilterProvider(); |
| | 641 | 228 | | EndpointDispatcher dispatcher = BuildEndpointDispatcher(description, endpoint); |
| | | 229 | | |
| | 641 | 230 | | if (!endpointInfosPerEndpointAddress.ContainsKey(endpoint.Address)) |
| | | 231 | | { |
| | 640 | 232 | | endpointInfosPerEndpointAddress.Add(endpoint.Address, new Collection<EndpointInfo>()); |
| | | 233 | | } |
| | | 234 | | |
| | 641 | 235 | | endpointInfosPerEndpointAddress[endpoint.Address].Add(new EndpointInfo(endpoint, dispatcher, /*provi |
| | 641 | 236 | | channelDispatcher.Endpoints.Add(dispatcher); |
| | | 237 | | } // end foreach "endpoint" |
| | | 238 | | |
| | 640 | 239 | | serviceHost.ChannelDispatchers.Add(channelDispatcher); |
| | | 240 | | } // end foreach "ListenUri/ChannelDispatcher" group |
| | | 241 | | |
| | | 242 | | // run service behaviors |
| | 4850 | 243 | | for (int i = 0; i < description.Behaviors.Count; i++) |
| | | 244 | | { |
| | 1849 | 245 | | IServiceBehavior serviceBehavior = description.Behaviors[i]; |
| | 1849 | 246 | | serviceBehavior.ApplyDispatchBehavior(description, serviceHost); |
| | | 247 | | } |
| | | 248 | | |
| | 2432 | 249 | | foreach (KeyValuePair<ListenUriInfo, StuffPerListenUriInfo> stuff in stuffPerListenUriInfo) |
| | | 250 | | { |
| | 2562 | 251 | | for (int i = 0; i < stuff.Value.Endpoints.Count; i++) |
| | | 252 | | { |
| | 641 | 253 | | ServiceEndpoint endpoint = stuff.Value.Endpoints[i]; |
| | | 254 | | // rediscover which dispatcher goes with this endpoint |
| | 641 | 255 | | Collection<EndpointInfo> infos = endpointInfosPerEndpointAddress[endpoint.Address]; |
| | 641 | 256 | | EndpointInfo info = null; |
| | 1925 | 257 | | foreach (EndpointInfo ei in infos) |
| | | 258 | | { |
| | 642 | 259 | | if (ei.Endpoint == endpoint) |
| | | 260 | | { |
| | 641 | 261 | | info = ei; |
| | 641 | 262 | | break; |
| | | 263 | | } |
| | | 264 | | } |
| | 641 | 265 | | EndpointDispatcher dispatcher = info.EndpointDispatcher; |
| | | 266 | | // run contract behaviors |
| | 2576 | 267 | | for (int k = 0; k < endpoint.Contract.Behaviors.Count; k++) |
| | | 268 | | { |
| | 647 | 269 | | IContractBehavior behavior = endpoint.Contract.Behaviors[k]; |
| | 647 | 270 | | behavior.ApplyDispatchBehavior(endpoint.Contract, endpoint, dispatcher.DispatchRuntime); |
| | | 271 | | } |
| | | 272 | | // run endpoint behaviors |
| | 641 | 273 | | ApplyBindingInformationFromEndpointToDispatcher(endpoint, dispatcher); |
| | 2720 | 274 | | for (int j = 0; j < endpoint.Behaviors.Count; j++) |
| | | 275 | | { |
| | 719 | 276 | | IEndpointBehavior eb = endpoint.Behaviors[j]; |
| | 719 | 277 | | eb.ApplyDispatchBehavior(endpoint, dispatcher); |
| | | 278 | | } |
| | | 279 | | // run operation behaviors |
| | 641 | 280 | | BindOperations(endpoint.Contract, null, dispatcher.DispatchRuntime); |
| | | 281 | | } |
| | | 282 | | } |
| | | 283 | | |
| | 576 | 284 | | EnsureRequiredRuntimeProperties(endpointInfosPerEndpointAddress); |
| | | 285 | | |
| | | 286 | | // Warn about obvious demux conflicts |
| | 2432 | 287 | | foreach (Collection<EndpointInfo> endpointInfos in endpointInfosPerEndpointAddress.Values) |
| | | 288 | | { |
| | | 289 | | // all elements of endpointInfos share the same Address (and thus EndpointListener.AddressFilter) |
| | 640 | 290 | | if (endpointInfos.Count > 1) |
| | | 291 | | { |
| | 6 | 292 | | for (int i = 0; i < endpointInfos.Count; i++) |
| | | 293 | | { |
| | 6 | 294 | | for (int j = i + 1; j < endpointInfos.Count; j++) |
| | | 295 | | { |
| | | 296 | | // if not same ListenUri, won't conflict |
| | | 297 | | // if not same ChannelType, may not conflict (some transports demux based on this) |
| | | 298 | | // if they share a ChannelDispatcher, this means same ListenUri and same ChannelType |
| | 1 | 299 | | if (endpointInfos[i].EndpointDispatcher.ChannelDispatcher == |
| | 1 | 300 | | endpointInfos[j].EndpointDispatcher.ChannelDispatcher) |
| | | 301 | | { |
| | 1 | 302 | | EndpointFilterProvider iProvider = endpointInfos[i].FilterProvider; |
| | 1 | 303 | | EndpointFilterProvider jProvider = endpointInfos[j].FilterProvider; |
| | | 304 | | // if not default EndpointFilterProvider, we won't try to throw, you're on your own |
| | 1 | 305 | | if (iProvider != null && jProvider != null |
| | 1 | 306 | | && HaveCommonInitiatingActions(iProvider, jProvider, out string commonAction)) |
| | | 307 | | { |
| | | 308 | | // you will definitely get a MultipleFiltersMatchedException at runtime, |
| | | 309 | | // so let's go ahead and throw now |
| | 0 | 310 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( |
| | 0 | 311 | | new InvalidOperationException( |
| | 0 | 312 | | SR.Format(SR.SFxDuplicateInitiatingActionAtSameVia, endpointInfos[i].Endpoin |
| | | 313 | | } |
| | | 314 | | } |
| | | 315 | | } |
| | | 316 | | } |
| | | 317 | | } |
| | | 318 | | } |
| | 576 | 319 | | } |
| | | 320 | | |
| | | 321 | | private static void EnsureRequiredRuntimeProperties(Dictionary<EndpointAddress, Collection<EndpointInfo>> endpoi |
| | | 322 | | { |
| | 2432 | 323 | | foreach (Collection<EndpointInfo> endpointInfos in endpointInfosPerEndpointAddress.Values) |
| | | 324 | | { |
| | 2562 | 325 | | for (int i = 0; i < endpointInfos.Count; i++) |
| | | 326 | | { |
| | 641 | 327 | | DispatchRuntime dispatch = endpointInfos[i].EndpointDispatcher.DispatchRuntime; |
| | | 328 | | |
| | 641 | 329 | | if (dispatch.InstanceContextProvider == null) |
| | | 330 | | { |
| | 0 | 331 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma |
| | | 332 | | } |
| | | 333 | | } |
| | | 334 | | } |
| | 576 | 335 | | } |
| | | 336 | | |
| | | 337 | | private static List<Type> GetSupportedChannelTypes(StuffPerListenUriInfo stuff) |
| | | 338 | | { |
| | 640 | 339 | | Binding originalBinding = stuff.Endpoints[0].Binding; |
| | 640 | 340 | | CustomBinding binding = new CustomBinding(originalBinding); |
| | | 341 | | |
| | | 342 | | // All types are supported to start |
| | 640 | 343 | | bool reply = true; |
| | 640 | 344 | | bool replySession = true; |
| | 640 | 345 | | bool input = true; |
| | 640 | 346 | | bool inputSession = true; |
| | 640 | 347 | | bool duplex = true; |
| | 640 | 348 | | bool duplexSession = true; |
| | 640 | 349 | | string sessionContractName = null; |
| | 640 | 350 | | string datagramContractName = null; |
| | | 351 | | // each endpoint adds constraints |
| | 2562 | 352 | | for (int i = 0; i < stuff.Endpoints.Count; ++i) |
| | | 353 | | { |
| | 641 | 354 | | ContractDescription contract = stuff.Endpoints[i].Contract; |
| | 641 | 355 | | if (contract.SessionMode == SessionMode.Required) |
| | | 356 | | { |
| | 9 | 357 | | sessionContractName = contract.Name; |
| | | 358 | | } |
| | 641 | 359 | | if (contract.SessionMode == SessionMode.NotAllowed) |
| | | 360 | | { |
| | 0 | 361 | | datagramContractName = contract.Name; |
| | | 362 | | } |
| | | 363 | | |
| | 641 | 364 | | System.Collections.IList endpointTypes = GetSupportedChannelTypes(contract); |
| | 641 | 365 | | if (!endpointTypes.Contains(typeof(IReplyChannel))) |
| | | 366 | | { |
| | 11 | 367 | | reply = false; |
| | | 368 | | } |
| | 641 | 369 | | if (!endpointTypes.Contains(typeof(IReplySessionChannel))) |
| | | 370 | | { |
| | 2 | 371 | | replySession = false; |
| | | 372 | | } |
| | 641 | 373 | | if (!endpointTypes.Contains(typeof(IInputChannel))) |
| | | 374 | | { |
| | 589 | 375 | | input = false; |
| | | 376 | | } |
| | 641 | 377 | | if (!endpointTypes.Contains(typeof(IInputSessionChannel))) |
| | | 378 | | { |
| | 589 | 379 | | inputSession = false; |
| | | 380 | | } |
| | 641 | 381 | | if (!endpointTypes.Contains(typeof(IDuplexChannel))) |
| | | 382 | | { |
| | 9 | 383 | | duplex = false; |
| | | 384 | | } |
| | 641 | 385 | | if (!endpointTypes.Contains(typeof(IDuplexSessionChannel))) |
| | | 386 | | { |
| | 0 | 387 | | duplexSession = false; |
| | | 388 | | } |
| | | 389 | | } |
| | | 390 | | |
| | 640 | 391 | | if ((sessionContractName != null) && (datagramContractName != null)) |
| | | 392 | | { |
| | 0 | 393 | | string text = SR.Format(SR.SFxCannotRequireBothSessionAndDatagram3, datagramContractName, sessionContrac |
| | 0 | 394 | | Exception error = new InvalidOperationException(text); |
| | 0 | 395 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(error); |
| | | 396 | | } |
| | | 397 | | |
| | | 398 | | // TODO: Restrict list further based on SessionMode constraints |
| | | 399 | | |
| | 640 | 400 | | var supportedChannelTypes = new List<Type>(); |
| | 640 | 401 | | if (input) |
| | | 402 | | { |
| | 52 | 403 | | supportedChannelTypes.Add(typeof(IInputChannel)); |
| | | 404 | | } |
| | 640 | 405 | | if (inputSession) |
| | | 406 | | { |
| | 52 | 407 | | supportedChannelTypes.Add(typeof(IInputSessionChannel)); |
| | | 408 | | } |
| | 640 | 409 | | if (reply) |
| | | 410 | | { |
| | 629 | 411 | | supportedChannelTypes.Add(typeof(IReplyChannel)); |
| | | 412 | | } |
| | 640 | 413 | | if (replySession) |
| | | 414 | | { |
| | 638 | 415 | | supportedChannelTypes.Add(typeof(IReplySessionChannel)); |
| | | 416 | | } |
| | 640 | 417 | | if (duplex) |
| | | 418 | | { |
| | 631 | 419 | | supportedChannelTypes.Add(typeof(IDuplexChannel)); |
| | | 420 | | } |
| | 640 | 421 | | if (duplexSession) |
| | | 422 | | { |
| | 640 | 423 | | supportedChannelTypes.Add(typeof(IDuplexSessionChannel)); |
| | | 424 | | } |
| | | 425 | | |
| | 640 | 426 | | return supportedChannelTypes; |
| | | 427 | | } |
| | | 428 | | |
| | | 429 | | private static Type[] GetSupportedChannelTypes(ContractDescription contractDescription) |
| | | 430 | | { |
| | 641 | 431 | | if (contractDescription == null) |
| | | 432 | | { |
| | 0 | 433 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(contractDescr |
| | | 434 | | } |
| | | 435 | | |
| | 641 | 436 | | ChannelRequirements.ComputeContractRequirements(contractDescription, out ChannelRequirements reqs); |
| | 641 | 437 | | Type[] supportedChannels = ChannelRequirements.ComputeRequiredChannels(ref reqs); |
| | | 438 | | // supportedChannels is client-side, need to make server-side |
| | 6574 | 439 | | for (int i = 0; i < supportedChannels.Length; i++) |
| | | 440 | | { |
| | 2646 | 441 | | if (supportedChannels[i] == typeof(IRequestChannel)) |
| | | 442 | | { |
| | 630 | 443 | | supportedChannels[i] = typeof(IReplyChannel); |
| | | 444 | | } |
| | 2016 | 445 | | else if (supportedChannels[i] == typeof(IRequestSessionChannel)) |
| | | 446 | | { |
| | 639 | 447 | | supportedChannels[i] = typeof(IReplySessionChannel); |
| | | 448 | | } |
| | 1377 | 449 | | else if (supportedChannels[i] == typeof(IOutputChannel)) |
| | | 450 | | { |
| | 52 | 451 | | supportedChannels[i] = typeof(IInputChannel); |
| | | 452 | | } |
| | 1325 | 453 | | else if (supportedChannels[i] == typeof(IOutputSessionChannel)) |
| | | 454 | | { |
| | 52 | 455 | | supportedChannels[i] = typeof(IInputSessionChannel); |
| | | 456 | | } |
| | 1273 | 457 | | else if (supportedChannels[i] == typeof(IDuplexChannel)) |
| | | 458 | | { |
| | | 459 | | // no-op; duplex is its own dual |
| | | 460 | | } |
| | 641 | 461 | | else if (supportedChannels[i] == typeof(IDuplexSessionChannel)) |
| | | 462 | | { |
| | | 463 | | // no-op; duplex is its own dual |
| | | 464 | | } |
| | | 465 | | else |
| | | 466 | | { |
| | 0 | 467 | | throw Fx.AssertAndThrowFatal("DispatcherBuilder.GetSupportedChannelTypes: Unexpected channel type"); |
| | | 468 | | } |
| | | 469 | | } |
| | | 470 | | |
| | 641 | 471 | | return supportedChannels; |
| | | 472 | | } |
| | | 473 | | |
| | | 474 | | internal static EndpointDispatcher BuildEndpointDispatcher(ServiceDescription serviceDescription, |
| | | 475 | | ServiceEndpoint endpoint) |
| | | 476 | | { |
| | 641 | 477 | | if (serviceDescription == null) |
| | | 478 | | { |
| | 0 | 479 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(serviceDescription)); |
| | | 480 | | } |
| | | 481 | | |
| | 641 | 482 | | ContractDescription contractDescription = endpoint.Contract; |
| | 641 | 483 | | if (contractDescription == null) |
| | | 484 | | { |
| | 0 | 485 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(endpoint.Contract)); |
| | | 486 | | } |
| | | 487 | | |
| | 641 | 488 | | EndpointFilterProvider provider = new EndpointFilterProvider(); |
| | | 489 | | |
| | 641 | 490 | | EndpointAddress address = endpoint.Address; |
| | 641 | 491 | | EndpointDispatcher dispatcher = new EndpointDispatcher(address, contractDescription.Name, contractDescriptio |
| | | 492 | | |
| | 641 | 493 | | DispatchRuntime dispatch = dispatcher.DispatchRuntime; |
| | 641 | 494 | | if (contractDescription.CallbackContractType != null) |
| | | 495 | | { |
| | 2 | 496 | | dispatch.CallbackClientRuntime.CallbackClientType = contractDescription.CallbackContractType; |
| | 2 | 497 | | dispatch.CallbackClientRuntime.ContractClientType = contractDescription.ContractType; |
| | | 498 | | } |
| | | 499 | | |
| | 7338 | 500 | | for (int i = 0; i < contractDescription.Operations.Count; i++) |
| | | 501 | | { |
| | 3028 | 502 | | OperationDescription operation = contractDescription.Operations[i]; |
| | | 503 | | |
| | 3028 | 504 | | if (!operation.IsServerInitiated()) |
| | | 505 | | { |
| | 3026 | 506 | | BuildDispatchOperation(operation, dispatch, provider, serviceDescription.ServiceProvider); |
| | | 507 | | } |
| | | 508 | | else |
| | | 509 | | { |
| | 2 | 510 | | BuildProxyOperation(operation, dispatch.CallbackClientRuntime); |
| | | 511 | | } |
| | | 512 | | } |
| | | 513 | | |
| | | 514 | | //dispatcher.SetSupportedChannels(DispatcherBuilder.GetSupportedChannelTypes(contractDescription)); |
| | 641 | 515 | | dispatcher.ContractFilter = provider.CreateFilter(out int filterPriority); |
| | 641 | 516 | | dispatcher.FilterPriority = filterPriority; |
| | | 517 | | |
| | 641 | 518 | | return dispatcher; |
| | | 519 | | } |
| | | 520 | | |
| | | 521 | | private static void BuildProxyOperation(OperationDescription operation, ClientRuntime parent) |
| | | 522 | | { |
| | | 523 | | ClientOperation child; |
| | 2 | 524 | | if (operation.Messages.Count == 1) |
| | | 525 | | { |
| | 0 | 526 | | child = new ClientOperation(parent, operation.Name, operation.Messages[0].Action); |
| | | 527 | | } |
| | | 528 | | else |
| | | 529 | | { |
| | 2 | 530 | | child = new ClientOperation(parent, operation.Name, operation.Messages[0].Action, |
| | 2 | 531 | | operation.Messages[1].Action); |
| | | 532 | | } |
| | 2 | 533 | | child.TaskMethod = operation.TaskMethod; |
| | 2 | 534 | | child.TaskTResult = operation.TaskTResult; |
| | 2 | 535 | | child.SyncMethod = operation.SyncMethod; |
| | 2 | 536 | | child.BeginMethod = operation.BeginMethod; |
| | 2 | 537 | | child.EndMethod = operation.EndMethod; |
| | 2 | 538 | | child.IsOneWay = operation.IsOneWay; |
| | 2 | 539 | | child.IsTerminating = operation.IsTerminating; |
| | 2 | 540 | | child.IsInitiating = operation.IsInitiating; |
| | 2 | 541 | | child.IsSessionOpenNotificationEnabled = operation.IsSessionOpenNotificationEnabled; |
| | 4 | 542 | | for (int i = 0; i < operation.Faults.Count; i++) |
| | | 543 | | { |
| | 0 | 544 | | FaultDescription fault = operation.Faults[i]; |
| | 0 | 545 | | child.FaultContractInfos.Add(new FaultContractInfo(fault.Action, fault.DetailType, fault.ElementName, fa |
| | | 546 | | } |
| | | 547 | | |
| | 2 | 548 | | parent.Operations.Add(child); |
| | 2 | 549 | | } |
| | | 550 | | |
| | | 551 | | private static void BuildDispatchOperation(OperationDescription operation, DispatchRuntime parent, EndpointFilte |
| | | 552 | | IServiceProvider services) |
| | | 553 | | { |
| | 3026 | 554 | | string requestAction = operation.Messages[0].Action; |
| | | 555 | | DispatchOperation child; |
| | 3026 | 556 | | if (operation.IsOneWay) |
| | | 557 | | { |
| | 324 | 558 | | child = new DispatchOperation(parent, operation.Name, requestAction); |
| | | 559 | | } |
| | | 560 | | else |
| | | 561 | | { |
| | 2702 | 562 | | string replyAction = operation.Messages[1].Action; |
| | 2702 | 563 | | child = new DispatchOperation(parent, operation.Name, requestAction, replyAction); |
| | | 564 | | } |
| | | 565 | | |
| | 3026 | 566 | | child.HasNoDisposableParameters = operation.HasNoDisposableParameters; |
| | | 567 | | |
| | 3026 | 568 | | child.IsTerminating = operation.IsTerminating; |
| | 3026 | 569 | | child.IsSessionOpenNotificationEnabled = operation.IsSessionOpenNotificationEnabled; |
| | 6376 | 570 | | for (int i = 0; i < operation.Faults.Count; i++) |
| | | 571 | | { |
| | 162 | 572 | | FaultDescription fault = operation.Faults[i]; |
| | 162 | 573 | | child.FaultContractInfos.Add(new FaultContractInfo(fault.Action, fault.DetailType, fault.ElementName, fa |
| | | 574 | | } |
| | | 575 | | |
| | 3026 | 576 | | if (provider != null) |
| | | 577 | | { |
| | 3026 | 578 | | if (operation.IsInitiating) |
| | | 579 | | { |
| | 3018 | 580 | | provider.InitiatingActions.Add(requestAction); |
| | | 581 | | } |
| | | 582 | | } |
| | | 583 | | |
| | 3026 | 584 | | if (requestAction != MessageHeaders.WildcardAction) |
| | | 585 | | { |
| | 3016 | 586 | | parent.Operations.Add(child); |
| | | 587 | | } |
| | | 588 | | else |
| | | 589 | | { |
| | 10 | 590 | | if (parent.HasMatchAllOperation) |
| | | 591 | | { |
| | 0 | 592 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxMultip |
| | | 593 | | } |
| | | 594 | | |
| | 10 | 595 | | parent.UnhandledDispatchOperation = child; |
| | | 596 | | } |
| | | 597 | | |
| | 3026 | 598 | | var authorizationPolicyProvider = services.GetService<IAuthorizationPolicyProvider>(); |
| | 3026 | 599 | | if (authorizationPolicyProvider != null) |
| | | 600 | | { |
| | 279 | 601 | | child.AuthorizationPolicy = new Lazy<AuthorizationPolicy>(() => |
| | 279 | 602 | | { |
| | 55 | 603 | | object serviceInstance = OperationContext.Current.InstanceContext.GetServiceInstance(); |
| | 55 | 604 | | Type serviceType = serviceInstance.GetType(); |
| | 55 | 605 | | ReadOnlyCollection<IAuthorizeData> authorizeData = operation.AuthorizeData.ContainsKey(serviceType) |
| | 55 | 606 | | ? operation.AuthorizeData[serviceType] |
| | 55 | 607 | | : operation.AuthorizeData[serviceType] = BuildAuthorizeData(operation, serviceType); |
| | 279 | 608 | | |
| | 55 | 609 | | if (authorizeData.Count > 0) |
| | 279 | 610 | | { |
| | 279 | 611 | | // TODO: Make this chain call async |
| | 54 | 612 | | return AuthorizationPolicy.CombineAsync(authorizationPolicyProvider, authorizeData).GetAwaiter() |
| | 54 | 613 | | .GetResult(); |
| | 279 | 614 | | } |
| | 279 | 615 | | |
| | 1 | 616 | | return null; |
| | 279 | 617 | | }); |
| | | 618 | | } |
| | 3026 | 619 | | } |
| | | 620 | | |
| | | 621 | | private static ReadOnlyCollection<IAuthorizeData> BuildAuthorizeData(OperationDescription operation, Type servic |
| | | 622 | | { |
| | 55 | 623 | | List<IAuthorizeData> authorizeData = new(); |
| | 55 | 624 | | authorizeData.AddRange(serviceType.GetCustomAttributes(false).OfType<IAuthorizeData>()); |
| | | 625 | | |
| | 55 | 626 | | Type declaringType = operation.OperationMethod.DeclaringType; |
| | | 627 | | |
| | | 628 | | // Check if the declaring type is an interface (split contract and implementation) |
| | 55 | 629 | | if (declaringType.IsInterface) |
| | | 630 | | { |
| | 53 | 631 | | InterfaceMapping interfaceMapping = serviceType.GetInterfaceMap(declaringType); |
| | 53 | 632 | | int index = Array.IndexOf(interfaceMapping.InterfaceMethods, operation.OperationMethod); |
| | 53 | 633 | | if (index >= 0) |
| | | 634 | | { |
| | 53 | 635 | | authorizeData.AddRange(interfaceMapping.TargetMethods[index].GetCustomAttributes(false).OfType<IAuth |
| | | 636 | | } |
| | | 637 | | } |
| | | 638 | | else |
| | | 639 | | { |
| | | 640 | | // The declaring type is the service class itself (contract defined on class) |
| | | 641 | | // Directly get attributes from the operation method |
| | 2 | 642 | | authorizeData.AddRange(operation.OperationMethod.GetCustomAttributes(false).OfType<IAuthorizeData>()); |
| | | 643 | | } |
| | | 644 | | |
| | 55 | 645 | | return authorizeData.AsReadOnly(); |
| | | 646 | | } |
| | | 647 | | |
| | | 648 | | private static void BindOperations(ContractDescription contract, ClientRuntime proxy, DispatchRuntime dispatch) |
| | | 649 | | { |
| | 641 | 650 | | if (!(((proxy == null) != (dispatch == null)))) |
| | | 651 | | { |
| | 0 | 652 | | throw Fx.AssertAndThrowFatal("DispatcherBuilder.BindOperations: ((proxy == null) != (dispatch == null))" |
| | | 653 | | } |
| | | 654 | | |
| | 641 | 655 | | MessageDirection local = (proxy == null) ? MessageDirection.Input : MessageDirection.Output; |
| | | 656 | | |
| | 7338 | 657 | | for (int i = 0; i < contract.Operations.Count; i++) |
| | | 658 | | { |
| | 3028 | 659 | | OperationDescription operation = contract.Operations[i]; |
| | 3028 | 660 | | MessageDescription first = operation.Messages[0]; |
| | | 661 | | |
| | 3028 | 662 | | if (first.Direction != local) |
| | | 663 | | { |
| | 2 | 664 | | if (proxy == null) |
| | | 665 | | { |
| | 2 | 666 | | proxy = dispatch.CallbackClientRuntime; |
| | | 667 | | } |
| | | 668 | | |
| | 2 | 669 | | ClientOperation proxyOperation = proxy.Operations[operation.Name]; |
| | | 670 | | Fx.Assert(proxyOperation != null, ""); |
| | | 671 | | |
| | 16 | 672 | | for (int j = 0; j < operation.Behaviors.Count; j++) |
| | | 673 | | { |
| | 6 | 674 | | IOperationBehavior behavior = operation.Behaviors[j]; |
| | 6 | 675 | | behavior.ApplyClientBehavior(operation, proxyOperation); |
| | | 676 | | } |
| | | 677 | | } |
| | | 678 | | else |
| | | 679 | | { |
| | 3026 | 680 | | if (dispatch == null) |
| | | 681 | | { |
| | 0 | 682 | | dispatch = proxy.CallbackDispatchRuntime; |
| | | 683 | | } |
| | | 684 | | |
| | 3026 | 685 | | DispatchOperation dispatchOperation = null; |
| | 3026 | 686 | | if (dispatch.Operations.Contains(operation.Name)) |
| | | 687 | | { |
| | 3016 | 688 | | dispatchOperation = dispatch.Operations[operation.Name]; |
| | | 689 | | } |
| | 3026 | 690 | | if (dispatchOperation == null && dispatch.UnhandledDispatchOperation != null && dispatch.UnhandledDi |
| | | 691 | | { |
| | 10 | 692 | | dispatchOperation = dispatch.UnhandledDispatchOperation; |
| | | 693 | | } |
| | | 694 | | |
| | 3026 | 695 | | if (dispatchOperation != null) |
| | | 696 | | { |
| | | 697 | | // Applying authorizations before behaviors so that behaviors can be used validate or customize |
| | | 698 | | // any claims that have been applied. |
| | 6368 | 699 | | for (int k = 0; k < operation.AuthorizeOperation.Count; k++) |
| | | 700 | | { |
| | 158 | 701 | | IAuthorizeOperation authorizeOperation = operation.AuthorizeOperation[k]; |
| | 158 | 702 | | authorizeOperation.BuildClaim(operation, dispatchOperation); |
| | | 703 | | } |
| | | 704 | | |
| | 24580 | 705 | | for (int j = 0; j < operation.Behaviors.Count; j++) |
| | | 706 | | { |
| | 9264 | 707 | | IOperationBehavior behavior = operation.Behaviors[j]; |
| | 9264 | 708 | | behavior.ApplyDispatchBehavior(operation, dispatchOperation); |
| | | 709 | | } |
| | | 710 | | } |
| | | 711 | | } |
| | | 712 | | } |
| | 641 | 713 | | } |
| | | 714 | | |
| | | 715 | | private static bool HaveCommonInitiatingActions(EndpointFilterProvider x, EndpointFilterProvider y, out string c |
| | | 716 | | { |
| | 0 | 717 | | commonAction = null; |
| | 0 | 718 | | foreach (string action in x.InitiatingActions) |
| | | 719 | | { |
| | 0 | 720 | | if (y.InitiatingActions.Contains(action)) |
| | | 721 | | { |
| | 0 | 722 | | commonAction = action; |
| | 0 | 723 | | return true; |
| | | 724 | | } |
| | | 725 | | } |
| | 0 | 726 | | return false; |
| | 0 | 727 | | } |
| | | 728 | | |
| | | 729 | | internal static List<IServiceDispatcher> BuildDispatcher<TService>(ServiceConfiguration<TService> serviceConfig, |
| | | 730 | | { |
| | 583 | 731 | | IServiceBuilder serviceBuilder = services.GetRequiredService<IServiceBuilder>(); |
| | 583 | 732 | | Uri[] serverUriAddresses = serviceBuilder.BaseAddresses.ToArray(); |
| | | 733 | | ServiceHostObjectModel<TService> serviceHost; |
| | 583 | 734 | | serviceHost = services.GetRequiredService<ServiceHostObjectModel<TService>>(); |
| | | 735 | | |
| | 576 | 736 | | AllServicesConfigurationDelegateHolder allServicesConfigDelegate = services.GetService<AllServicesConfigurat |
| | 576 | 737 | | ServiceConfigurationDelegateHolder<TService> configDelegate = services.GetService<ServiceConfigurationDelega |
| | 576 | 738 | | var options = new ServiceOptions<TService>(serviceHost); |
| | 1332 | 739 | | foreach (var serverUriAddress in serverUriAddresses) |
| | | 740 | | { |
| | 90 | 741 | | options.BaseAddresses.Add(serverUriAddress); |
| | | 742 | | } |
| | | 743 | | |
| | 576 | 744 | | options.ApplyOptions(configDelegate); |
| | | 745 | | |
| | | 746 | | // TODO: Create internal behavior which configures any extensibilities which exist in serviceProvider, eg IM |
| | 2434 | 747 | | foreach (ServiceEndpointConfiguration endpointConfig in serviceConfig.Endpoints) |
| | | 748 | | { |
| | 641 | 749 | | if (!serviceHost.ReflectedContracts.Contains(endpointConfig.Contract)) |
| | | 750 | | { |
| | 0 | 751 | | throw new ArgumentException($"Service type {typeof(TService)} doesn't implement interface {endpointC |
| | | 752 | | } |
| | | 753 | | |
| | 641 | 754 | | ContractDescription contract = serviceHost.ReflectedContracts[endpointConfig.Contract]; |
| | 641 | 755 | | Uri uri = serviceHost.MakeAbsoluteUri(endpointConfig.Address, endpointConfig.Binding); |
| | 641 | 756 | | var serviceEndpoint = new ServiceEndpoint( |
| | 641 | 757 | | contract, |
| | 641 | 758 | | endpointConfig.Binding, |
| | 641 | 759 | | new EndpointAddress(uri)); |
| | | 760 | | |
| | 641 | 761 | | if (endpointConfig.ConfigureEndpoint != null) |
| | | 762 | | { |
| | 37 | 763 | | serviceEndpoint.Behaviors.Add(new EndpointConfiguratorEndpointBehavior(endpointConfig.ConfigureEndpo |
| | | 764 | | } |
| | | 765 | | |
| | 641 | 766 | | serviceHost.Description.Endpoints.Add(serviceEndpoint); |
| | | 767 | | } |
| | | 768 | | |
| | 576 | 769 | | configDelegate?.Configure(serviceHost); |
| | 576 | 770 | | allServicesConfigDelegate?.Configure(serviceHost); |
| | 576 | 771 | | InitializeServiceHost(serviceHost, services); |
| | | 772 | | |
| | | 773 | | // TODO: Add error checking to make sure property chain is correctly populated with objects |
| | 576 | 774 | | var dispatchers = new List<IServiceDispatcher>(serviceHost.ChannelDispatchers.Count); |
| | 2429 | 775 | | foreach (ChannelDispatcherBase cdb in serviceHost.ChannelDispatchers) |
| | | 776 | | { |
| | 640 | 777 | | var cd = cdb as ChannelDispatcher; |
| | 640 | 778 | | cd.Init(); |
| | 637 | 779 | | System.Threading.Tasks.Task openTask = cd.OpenAsync(); |
| | | 780 | | Fx.Assert(openTask.IsCompleted, "ChannelDispatcher should open synchronously"); |
| | 637 | 781 | | openTask.GetAwaiter().GetResult(); |
| | 637 | 782 | | dispatchers.Add(new ServiceDispatcher(cd)); |
| | | 783 | | } |
| | | 784 | | |
| | 573 | 785 | | return dispatchers; |
| | | 786 | | } |
| | | 787 | | |
| | | 788 | | public static void ApplyBindingInformationFromEndpointToDispatcher(ServiceEndpoint serviceEndpoint, EndpointDisp |
| | | 789 | | { |
| | 641 | 790 | | endpointDispatcher.ChannelDispatcher.ReceiveSynchronously = false; // No sync code for .Net Core |
| | 641 | 791 | | endpointDispatcher.ChannelDispatcher.ManualAddressing = IsManualAddressing(serviceEndpoint.Binding); |
| | 641 | 792 | | endpointDispatcher.ChannelDispatcher.EnableFaults = true; |
| | 641 | 793 | | endpointDispatcher.ChannelDispatcher.MessageVersion = serviceEndpoint.Binding.MessageVersion; |
| | 641 | 794 | | } |
| | | 795 | | |
| | | 796 | | internal static bool IsManualAddressing(Binding binding) |
| | | 797 | | { |
| | 641 | 798 | | TransportBindingElement transport = binding.CreateBindingElements().Find<TransportBindingElement>(); |
| | 641 | 799 | | if (transport == null) |
| | | 800 | | { |
| | 0 | 801 | | string text = SR.Format(SR.SFxBindingMustContainTransport2, binding.Name, binding.Namespace); |
| | 0 | 802 | | Exception error = new InvalidOperationException(text); |
| | 0 | 803 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(error); |
| | | 804 | | } |
| | 641 | 805 | | return transport.ManualAddressing; |
| | | 806 | | } |
| | | 807 | | |
| | | 808 | | public static void AddBindingParametersForSecurityContractInformation(ServiceEndpoint endpoint, BindingParameter |
| | | 809 | | { |
| | | 810 | | // get Contract info security needs, and put in BindingParameterCollection |
| | 641 | 811 | | ISecurityCapabilities isc = null; |
| | 641 | 812 | | BindingElementCollection elements = endpoint.Binding.CreateBindingElements(); |
| | 3642 | 813 | | for (int i = 0; i < elements.Count; ++i) |
| | | 814 | | { |
| | 1214 | 815 | | if (!(elements[i] is ITransportTokenAssertionProvider)) |
| | | 816 | | { |
| | 1159 | 817 | | ISecurityCapabilities tmp = elements[i].GetIndividualProperty<ISecurityCapabilities>(); |
| | 1159 | 818 | | if (tmp != null) |
| | | 819 | | { |
| | 34 | 820 | | isc = tmp; |
| | 34 | 821 | | break; |
| | | 822 | | } |
| | | 823 | | } |
| | | 824 | | } |
| | 641 | 825 | | if (isc != null) |
| | | 826 | | { |
| | | 827 | | // ensure existence of binding parameter |
| | 34 | 828 | | ChannelProtectionRequirements requirements = parameters.Find<ChannelProtectionRequirements>(); |
| | 34 | 829 | | if (requirements == null) |
| | | 830 | | { |
| | 34 | 831 | | requirements = new ChannelProtectionRequirements(); |
| | 34 | 832 | | parameters.Add(requirements); |
| | | 833 | | } |
| | | 834 | | |
| | 34 | 835 | | MessageEncodingBindingElement encoding = elements.Find<MessageEncodingBindingElement>(); |
| | | 836 | | // use endpoint.Binding.Version |
| | 34 | 837 | | if (encoding != null && encoding.MessageVersion.Addressing == AddressingVersion.None) |
| | | 838 | | { |
| | | 839 | | // This binding does not support response actions, so... |
| | 6 | 840 | | requirements.Add(ChannelProtectionRequirements.CreateFromContractAndUnionResponseProtectionRequireme |
| | | 841 | | } |
| | | 842 | | else |
| | | 843 | | { |
| | 28 | 844 | | requirements.Add(ChannelProtectionRequirements.CreateFromContract(endpoint.Contract, isc)); |
| | | 845 | | } |
| | | 846 | | } |
| | 635 | 847 | | } |
| | | 848 | | |
| | | 849 | | #region InnerClasses |
| | | 850 | | private class EndpointInfo |
| | | 851 | | { |
| | 641 | 852 | | public EndpointInfo(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher, EndpointFilterProvider |
| | | 853 | | { |
| | 641 | 854 | | Endpoint = endpoint; |
| | 641 | 855 | | EndpointDispatcher = endpointDispatcher; |
| | 641 | 856 | | FilterProvider = provider; |
| | 641 | 857 | | } |
| | 642 | 858 | | public ServiceEndpoint Endpoint { get; } |
| | 2 | 859 | | public EndpointFilterProvider FilterProvider { get; } |
| | 1284 | 860 | | public EndpointDispatcher EndpointDispatcher { get; } |
| | | 861 | | } |
| | | 862 | | |
| | | 863 | | internal class ListenUriInfo |
| | | 864 | | { |
| | 641 | 865 | | public ListenUriInfo(Uri listenUri, ListenUriMode listenUriMode) |
| | | 866 | | { |
| | 641 | 867 | | ListenUri = listenUri; |
| | 641 | 868 | | ListenUriMode = listenUriMode; |
| | 641 | 869 | | } |
| | | 870 | | |
| | 1990 | 871 | | public Uri ListenUri { get; } |
| | | 872 | | |
| | 4 | 873 | | public ListenUriMode ListenUriMode { get; } |
| | | 874 | | |
| | | 875 | | // implement Equals and GetHashCode so that we can use this as a key in a dictionary |
| | | 876 | | public override bool Equals(object obj) |
| | | 877 | | { |
| | 642 | 878 | | return Equals(obj as ListenUriInfo); |
| | | 879 | | } |
| | | 880 | | |
| | | 881 | | public bool Equals(ListenUriInfo other) |
| | | 882 | | { |
| | 642 | 883 | | if (other == null) |
| | | 884 | | { |
| | 0 | 885 | | return false; |
| | | 886 | | } |
| | | 887 | | |
| | 642 | 888 | | if (ReferenceEquals(this, other)) |
| | | 889 | | { |
| | 640 | 890 | | return true; |
| | | 891 | | } |
| | | 892 | | |
| | 2 | 893 | | return (ListenUriMode == other.ListenUriMode) |
| | 2 | 894 | | && EndpointAddress.UriEquals(ListenUri, other.ListenUri, true /* ignoreCase */, true /* includeHost |
| | | 895 | | } |
| | | 896 | | |
| | | 897 | | public override int GetHashCode() |
| | | 898 | | { |
| | 1346 | 899 | | return EndpointAddress.UriGetHashCode(ListenUri, true /* includeHost */); |
| | | 900 | | } |
| | | 901 | | } |
| | | 902 | | |
| | | 903 | | private class StuffPerListenUriInfo |
| | | 904 | | { |
| | 640 | 905 | | public BindingParameterCollection Parameters = new BindingParameterCollection(); |
| | 640 | 906 | | public Collection<ServiceEndpoint> Endpoints = new Collection<ServiceEndpoint>(); |
| | | 907 | | public ChannelDispatcher ChannelDispatcher = null; |
| | | 908 | | } |
| | | 909 | | #endregion // InnerClasses |
| | | 910 | | } |
| | | 911 | | } |