| | | 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.Net; |
| | | 7 | | using System.Security.Authentication.ExtendedProtection; |
| | | 8 | | using System.Xml; |
| | | 9 | | using CoreWCF.Configuration; |
| | | 10 | | using CoreWCF.Description; |
| | | 11 | | using Microsoft.AspNetCore.Builder; |
| | | 12 | | using WsdlNS = System.Web.Services.Description; |
| | | 13 | | |
| | | 14 | | namespace CoreWCF.Channels |
| | | 15 | | { |
| | | 16 | | /// <summary> |
| | | 17 | | /// This TransportBindingElement is used to specify an HTTP transport for transmitting messages. |
| | | 18 | | /// </summary> |
| | | 19 | | /// <remarks>HttpTransportBindingElement is also used as a starting point for creating a custom bindings using HTTP. |
| | | 20 | | public class HttpTransportBindingElement : TransportBindingElement, IWsdlExportExtension, IPolicyExportExtension |
| | | 21 | | { |
| | | 22 | | private int _maxBufferSize; |
| | | 23 | | private bool _maxBufferSizeInitialized; |
| | | 24 | | private string _realm; |
| | | 25 | | private TransferMode _transferMode; |
| | | 26 | | private WebSocketTransportSettings _webSocketSettings; |
| | | 27 | | private ExtendedProtectionPolicy _extendedProtectionPolicy; |
| | | 28 | | |
| | | 29 | | //HttpAnonymousUriPrefixMatcher _anonymousUriPrefixMatcher; |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Initializes a new instance of the HttpTransportBindingElement class. |
| | | 33 | | /// </summary> |
| | | 34 | | /// <remarks>The defaults are AuthenticationSchemes.Anonymous, TransferMode.Buffered, MaxBufferSize = 65536, and |
| | 874 | 35 | | public HttpTransportBindingElement() |
| | | 36 | | { |
| | 874 | 37 | | AuthenticationScheme = HttpTransportDefaults.AuthenticationScheme; |
| | 874 | 38 | | _maxBufferSize = TransportDefaults.MaxBufferSize; |
| | 874 | 39 | | KeepAliveEnabled = HttpTransportDefaults.KeepAliveEnabled; |
| | 874 | 40 | | TransferMode = HttpTransportDefaults.TransferMode; |
| | 874 | 41 | | WebSocketSettings = HttpTransportDefaults.GetDefaultWebSocketTransportSettings(); |
| | 874 | 42 | | } |
| | | 43 | | |
| | 8345 | 44 | | protected HttpTransportBindingElement(HttpTransportBindingElement elementToBeCloned) : base(elementToBeCloned) |
| | | 45 | | { |
| | 8345 | 46 | | AuthenticationScheme = elementToBeCloned.AuthenticationScheme; |
| | 8345 | 47 | | _maxBufferSize = elementToBeCloned._maxBufferSize; |
| | 8345 | 48 | | _maxBufferSizeInitialized = elementToBeCloned._maxBufferSizeInitialized; |
| | 8345 | 49 | | KeepAliveEnabled = elementToBeCloned.KeepAliveEnabled; |
| | 8345 | 50 | | TransferMode = elementToBeCloned.TransferMode; |
| | 8345 | 51 | | WebSocketSettings = elementToBeCloned.WebSocketSettings.Clone(); |
| | 8345 | 52 | | AlwaysUseAuthorizationPolicySupport = elementToBeCloned.AlwaysUseAuthorizationPolicySupport; |
| | 8345 | 53 | | } |
| | | 54 | | |
| | | 55 | | // public bool AllowCookies { get { return default(bool); } set { } } |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// Gets or sets the authentication scheme. |
| | | 59 | | /// </summary> |
| | | 60 | | /// <value>The authentication scheme.</value> |
| | 24017 | 61 | | public AuthenticationSchemes AuthenticationScheme { get; set; } |
| | | 62 | | |
| | | 63 | | /// <summary> |
| | | 64 | | /// Gets or sets the ASP.NET Core Authorization policy support |
| | | 65 | | /// </summary> |
| | | 66 | | /// <value>A value of true always uses it, a value of false means it might be used if implicitly turned on (Inhe |
| | 23097 | 67 | | public bool AlwaysUseAuthorizationPolicySupport { get; set; } |
| | | 68 | | |
| | | 69 | | // public System.Net.AuthenticationSchemes AuthenticationScheme { get { return default(System.Net.Authentication |
| | | 70 | | |
| | | 71 | | /// <summary> |
| | | 72 | | /// Gets or sets the maximum size of the buffer. |
| | | 73 | | /// </summary> |
| | | 74 | | /// <value>The maximum size of the buffer.</value> |
| | | 75 | | /// <exception cref="ArgumentOutOfRangeException">The value is less than or equal to 0.</exception> |
| | | 76 | | /// <remarks>If not set, this defaults the to lessor of MaxReceivedMessageSize and Int32.MaxValue.</remarks> |
| | | 77 | | public int MaxBufferSize |
| | | 78 | | { |
| | | 79 | | get |
| | | 80 | | { |
| | 860 | 81 | | if (_maxBufferSizeInitialized || TransferMode != TransferMode.Buffered) |
| | | 82 | | { |
| | 42 | 83 | | return _maxBufferSize; |
| | | 84 | | } |
| | | 85 | | |
| | 818 | 86 | | long maxReceivedMessageSize = MaxReceivedMessageSize; |
| | 818 | 87 | | if (maxReceivedMessageSize > int.MaxValue) |
| | | 88 | | { |
| | 0 | 89 | | return int.MaxValue; |
| | | 90 | | } |
| | | 91 | | else |
| | | 92 | | { |
| | 818 | 93 | | return (int)maxReceivedMessageSize; |
| | | 94 | | } |
| | | 95 | | } |
| | | 96 | | set |
| | | 97 | | { |
| | 34 | 98 | | if (value <= 0) |
| | | 99 | | { |
| | 0 | 100 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 101 | | SRCommon.ValueMustBePositive)); |
| | | 102 | | } |
| | | 103 | | |
| | 34 | 104 | | _maxBufferSizeInitialized = true; |
| | 34 | 105 | | _maxBufferSize = value; |
| | 34 | 106 | | } |
| | | 107 | | } |
| | | 108 | | |
| | 17991 | 109 | | public bool KeepAliveEnabled { get; set; } |
| | | 110 | | |
| | | 111 | | public string Realm |
| | | 112 | | { |
| | | 113 | | get |
| | | 114 | | { |
| | 0 | 115 | | return _realm; |
| | | 116 | | } |
| | | 117 | | set |
| | | 118 | | { |
| | 5984 | 119 | | _realm = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value)); |
| | 5984 | 120 | | } |
| | | 121 | | } |
| | | 122 | | |
| | | 123 | | /// <summary> |
| | | 124 | | /// Gets the HTTP scheme. |
| | | 125 | | /// </summary> |
| | | 126 | | /// <value>The HTTP scheme.</value> |
| | | 127 | | /// <remarks>This will be 'http' unless overridden in a subclass.</remarks> |
| | 2496 | 128 | | public override string Scheme => "http"; |
| | | 129 | | |
| | | 130 | | /// <summary> |
| | | 131 | | /// Gets or sets the transfer mode. |
| | | 132 | | /// </summary> |
| | | 133 | | /// <value>The transfer mode.</value> |
| | | 134 | | public TransferMode TransferMode |
| | | 135 | | { |
| | | 136 | | get |
| | | 137 | | { |
| | 9620 | 138 | | return _transferMode; |
| | | 139 | | } |
| | | 140 | | set |
| | | 141 | | { |
| | 9274 | 142 | | TransferModeHelper.Validate(value); |
| | 9274 | 143 | | _transferMode = value; |
| | 9274 | 144 | | } |
| | | 145 | | } |
| | | 146 | | |
| | | 147 | | /// <summary> |
| | | 148 | | /// Gets or sets the web socket settings. |
| | | 149 | | /// </summary> |
| | | 150 | | /// <value>The web socket settings. This may not be null.</value> |
| | | 151 | | public WebSocketTransportSettings WebSocketSettings |
| | | 152 | | { |
| | | 153 | | get |
| | | 154 | | { |
| | 10983 | 155 | | return _webSocketSettings; |
| | | 156 | | } |
| | | 157 | | set |
| | | 158 | | { |
| | 9561 | 159 | | _webSocketSettings = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(va |
| | 9561 | 160 | | } |
| | | 161 | | } |
| | | 162 | | |
| | | 163 | | internal virtual bool GetSupportsClientAuthenticationImpl(AuthenticationSchemes effectiveAuthenticationSchemes) |
| | | 164 | | { |
| | 0 | 165 | | return effectiveAuthenticationSchemes != AuthenticationSchemes.None && |
| | 0 | 166 | | effectiveAuthenticationSchemes.IsNotSet(AuthenticationSchemes.Anonymous); |
| | | 167 | | } |
| | | 168 | | |
| | | 169 | | internal virtual bool GetSupportsClientWindowsIdentityImpl(AuthenticationSchemes effectiveAuthenticationSchemes) |
| | | 170 | | { |
| | 0 | 171 | | return effectiveAuthenticationSchemes != AuthenticationSchemes.None && |
| | 0 | 172 | | effectiveAuthenticationSchemes.IsNotSet(AuthenticationSchemes.Anonymous); |
| | | 173 | | } |
| | | 174 | | |
| | | 175 | | internal string GetWsdlTransportUri(bool useWebSocketTransport) |
| | | 176 | | { |
| | 31 | 177 | | if (useWebSocketTransport) |
| | | 178 | | { |
| | 0 | 179 | | return TransportPolicyConstants.WebSocketTransportUri; |
| | | 180 | | } |
| | | 181 | | |
| | 31 | 182 | | return TransportPolicyConstants.HttpTransportUri; |
| | | 183 | | } |
| | | 184 | | |
| | | 185 | | /// <summary> |
| | | 186 | | /// Clones this instance. |
| | | 187 | | /// </summary> |
| | | 188 | | public override BindingElement Clone() |
| | | 189 | | { |
| | 6894 | 190 | | return new HttpTransportBindingElement(this); |
| | | 191 | | } |
| | | 192 | | |
| | | 193 | | public override IServiceDispatcher BuildServiceDispatcher<TChannel>(BindingContext context, IServiceDispatcher i |
| | | 194 | | { |
| | 435 | 195 | | IApplicationBuilder app = context.BindingParameters.Find<IApplicationBuilder>(); |
| | 435 | 196 | | if (app == null) |
| | | 197 | | { |
| | 0 | 198 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(IApplicationBuilder)); |
| | | 199 | | } |
| | | 200 | | |
| | | 201 | | // Wire up inner dispatcher to ServiceModelHttpMiddleware so that incoming requests get dispatched |
| | | 202 | | //ServiceModelHttpMiddleware.ConfigureDispatcher(app, innerDispatcher); |
| | | 203 | | // Return the previous inner dispatcher as we don't create a wrapping dispatcher here. |
| | 435 | 204 | | return innerDispatcher; |
| | | 205 | | } |
| | | 206 | | |
| | | 207 | | public override bool CanBuildServiceDispatcher<TChannel>(BindingContext context) |
| | | 208 | | { |
| | 1722 | 209 | | if (typeof(TChannel) == typeof(IReplyChannel)) |
| | | 210 | | { |
| | 451 | 211 | | return WebSocketSettings.TransportUsage != WebSocketTransportUsage.Always; |
| | | 212 | | } |
| | 1271 | 213 | | else if (typeof(TChannel) == typeof(IDuplexSessionChannel)) |
| | | 214 | | { |
| | 423 | 215 | | return WebSocketSettings.TransportUsage != WebSocketTransportUsage.Never; |
| | | 216 | | } |
| | | 217 | | |
| | 848 | 218 | | return false; |
| | | 219 | | } |
| | | 220 | | |
| | | 221 | | public override T GetProperty<T>(BindingContext context) |
| | | 222 | | { |
| | 1244 | 223 | | if (context == null) |
| | | 224 | | { |
| | 0 | 225 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context)); |
| | | 226 | | } |
| | | 227 | | |
| | 1244 | 228 | | if (typeof(T) == typeof(ITransportServiceBuilder)) |
| | | 229 | | { |
| | 434 | 230 | | return (T)(object)new HttpTransportServiceBuilder(); |
| | | 231 | | } |
| | | 232 | | |
| | 810 | 233 | | if (typeof(T) == typeof(IAuthorizationCapabilities)) |
| | | 234 | | { |
| | 424 | 235 | | var binding = context.BindingParameters.Find<Binding>(); |
| | 424 | 236 | | if (binding is not null) |
| | | 237 | | { |
| | 424 | 238 | | context.BindingParameters.Remove(binding); |
| | 424 | 239 | | return (T)(object)new AuthorizationCapabilities(AlwaysUseAuthorizationPolicySupport); |
| | | 240 | | } |
| | | 241 | | |
| | 0 | 242 | | return null; |
| | | 243 | | } |
| | | 244 | | |
| | | 245 | | //else if (typeof(T) == typeof(ISecurityCapabilities)) |
| | | 246 | | //{ |
| | | 247 | | // AuthenticationSchemes effectiveAuthenticationSchemes = HttpTransportBindingElement.GetEffectiveAuthent |
| | | 248 | | // context.BindingParameters); |
| | | 249 | | |
| | | 250 | | // return (T)(object)new SecurityCapabilities(this.GetSupportsClientAuthenticationImpl(effectiveAuthentic |
| | | 251 | | // effectiveAuthenticationSchemes == AuthenticationSchemes.Negotiate, |
| | | 252 | | // this.GetSupportsClientWindowsIdentityImpl(effectiveAuthenticationSchemes), |
| | | 253 | | // ProtectionLevel.None, |
| | | 254 | | // ProtectionLevel.None); |
| | | 255 | | //} |
| | | 256 | | //else if (typeof(T) == typeof(IBindingDeliveryCapabilities)) |
| | | 257 | | //{ |
| | | 258 | | // return (T)(object)new BindingDeliveryCapabilitiesHelper(); |
| | | 259 | | //} |
| | 386 | 260 | | else if (typeof(T) == typeof(TransferMode)) |
| | | 261 | | { |
| | 0 | 262 | | return (T)(object)TransferMode; |
| | | 263 | | } |
| | | 264 | | //else if (typeof(T) == typeof(ExtendedProtectionPolicy)) |
| | | 265 | | //{ |
| | | 266 | | // return (T)(object)this.ExtendedProtectionPolicy; |
| | | 267 | | //} |
| | | 268 | | //else if (typeof(T) == typeof(IAnonymousUriPrefixMatcher)) |
| | | 269 | | //{ |
| | | 270 | | // if (_anonymousUriPrefixMatcher == null) |
| | | 271 | | // { |
| | | 272 | | // _anonymousUriPrefixMatcher = new HttpAnonymousUriPrefixMatcher(); |
| | | 273 | | // } |
| | | 274 | | |
| | | 275 | | // return (T)(object)_anonymousUriPrefixMatcher; |
| | | 276 | | //} |
| | 386 | 277 | | else if (typeof(T).FullName.Equals("CoreWCF.Channels.ITransportCompressionSupport")) |
| | | 278 | | { |
| | 2 | 279 | | IApplicationBuilder app = context.BindingParameters.Find<IApplicationBuilder>(); |
| | 2 | 280 | | if (app == null) |
| | | 281 | | { |
| | 0 | 282 | | return base.GetProperty<T>(context); |
| | | 283 | | } |
| | | 284 | | |
| | 2 | 285 | | object tcs = app.ApplicationServices.GetService(typeof(T).Assembly.GetType("CoreWCF.Channels.TransportCo |
| | 2 | 286 | | return (T)tcs; |
| | | 287 | | } |
| | | 288 | | else |
| | | 289 | | { |
| | 384 | 290 | | if (context.BindingParameters.Find<MessageEncodingBindingElement>() == null) |
| | | 291 | | { |
| | 384 | 292 | | context.BindingParameters.Add(new TextMessageEncodingBindingElement()); |
| | | 293 | | } |
| | 384 | 294 | | return base.GetProperty<T>(context); |
| | | 295 | | } |
| | | 296 | | } |
| | | 297 | | |
| | | 298 | | internal static AuthenticationSchemes GetEffectiveAuthenticationSchemes(AuthenticationSchemes currentAuthenticat |
| | | 299 | | { |
| | 40 | 300 | | if (bindingParameters == null) |
| | | 301 | | { |
| | 9 | 302 | | return currentAuthenticationSchemes; |
| | | 303 | | } |
| | | 304 | | |
| | 31 | 305 | | if (!AuthenticationSchemesBindingParameter.TryExtract(bindingParameters, out AuthenticationSchemes hostSuppo |
| | | 306 | | { |
| | 31 | 307 | | return currentAuthenticationSchemes; |
| | | 308 | | } |
| | | 309 | | |
| | | 310 | | // TODO: Add logic for Metadata endpoints to inherit authentication scheme of host. This might not be necess |
| | | 311 | | //if (currentAuthenticationSchemes == AuthenticationSchemes.None || |
| | | 312 | | // (AspNetEnvironment.Current.IsMetadataListener(bindingParameters) && |
| | | 313 | | // currentAuthenticationSchemes == AuthenticationSchemes.Anonymous && |
| | | 314 | | // hostSupportedAuthenticationSchemes.IsNotSet(AuthenticationSchemes.Anonymous))) |
| | | 315 | | //{ |
| | | 316 | | // //Inherit authentication schemes from host. |
| | | 317 | | // //This logic of inheriting from the host for anonymous MEX endpoints was previously implemented in Hos |
| | | 318 | | // //We moved it here to maintain the pre-multi-auth behavior. (see CSDMain 183553) |
| | | 319 | | |
| | | 320 | | // if (!hostSupportedAuthenticationSchemes.IsSingleton() && |
| | | 321 | | // hostSupportedAuthenticationSchemes.IsSet(AuthenticationSchemes.Anonymous) && |
| | | 322 | | // AspNetEnvironment.Current.AspNetCompatibilityEnabled && |
| | | 323 | | // AspNetEnvironment.Current.IsSimpleApplicationHost && |
| | | 324 | | // AspNetEnvironment.Current.IsWindowsAuthenticationConfigured()) |
| | | 325 | | // { |
| | | 326 | | // // Remove Anonymous if ASP.Net authentication mode is Windows (Asp.Net would not allow anonymous r |
| | | 327 | | // hostSupportedAuthenticationSchemes ^= AuthenticationSchemes.Anonymous; |
| | | 328 | | // } |
| | | 329 | | |
| | | 330 | | // return hostSupportedAuthenticationSchemes; |
| | | 331 | | //} |
| | | 332 | | //else |
| | | 333 | | //{ |
| | | 334 | | //build intersection between AuthenticationSchemes supported on the HttpTransportbidningELement and ServiceH |
| | 0 | 335 | | return currentAuthenticationSchemes & hostSupportedAuthenticationSchemes; |
| | | 336 | | //} |
| | | 337 | | } |
| | | 338 | | |
| | | 339 | | public ExtendedProtectionPolicy ExtendedProtectionPolicy |
| | | 340 | | { |
| | | 341 | | get |
| | | 342 | | { |
| | 0 | 343 | | return _extendedProtectionPolicy; |
| | | 344 | | } |
| | | 345 | | set |
| | | 346 | | { |
| | 1823 | 347 | | if (value == null) |
| | | 348 | | { |
| | 0 | 349 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value)); |
| | | 350 | | } |
| | | 351 | | |
| | 1823 | 352 | | if (value.PolicyEnforcement == PolicyEnforcement.Always && |
| | 1823 | 353 | | !ExtendedProtectionPolicy.OSSupportsExtendedProtection) |
| | | 354 | | { |
| | 0 | 355 | | throw new PlatformNotSupportedException(SR.ExtendedProtectionNotSupported); |
| | | 356 | | } |
| | | 357 | | |
| | 1823 | 358 | | _extendedProtectionPolicy = value; |
| | 1823 | 359 | | } |
| | | 360 | | } |
| | | 361 | | |
| | | 362 | | void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context) |
| | | 363 | | { |
| | 40 | 364 | | if (exporter == null) |
| | | 365 | | { |
| | 0 | 366 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(exporter)); |
| | | 367 | | } |
| | | 368 | | |
| | 40 | 369 | | if (context == null) |
| | | 370 | | { |
| | 0 | 371 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context)); |
| | | 372 | | } |
| | | 373 | | |
| | 40 | 374 | | OnExportPolicy(exporter, context); |
| | | 375 | | |
| | | 376 | | bool createdNew; |
| | 40 | 377 | | MessageEncodingBindingElement encodingBindingElement = FindMessageEncodingBindingElement(context.BindingElem |
| | 40 | 378 | | if (createdNew && encodingBindingElement is IPolicyExportExtension) |
| | | 379 | | { |
| | 0 | 380 | | ((IPolicyExportExtension)encodingBindingElement).ExportPolicy(exporter, context); |
| | | 381 | | } |
| | | 382 | | |
| | 40 | 383 | | WsdlExporter.AddWSAddressingAssertion(exporter, context, encodingBindingElement.MessageVersion.Addressing); |
| | 40 | 384 | | } |
| | | 385 | | |
| | | 386 | | internal virtual void OnExportPolicy(MetadataExporter exporter, PolicyConversionContext policyContext) |
| | | 387 | | { |
| | 40 | 388 | | List<string> assertionNames = new List<string>(); |
| | 40 | 389 | | AuthenticationSchemes effectiveAuthenticationSchemes = HttpTransportBindingElement.GetEffectiveAuthenticatio |
| | 40 | 390 | | policyContext.BindingParameters); |
| | | 391 | | |
| | 40 | 392 | | if (effectiveAuthenticationSchemes != AuthenticationSchemes.None && !(effectiveAuthenticationSchemes.IsSet(A |
| | | 393 | | { |
| | | 394 | | // ATTENTION: The order of the if-statements below is essential! When importing WSDL svcutil is actually |
| | | 395 | | // using the first assertion - and the HTTP spec requires clients to use the most secure authentication |
| | | 396 | | // scheme supported by the client. (especially important for downlevel (3.5/4.0) clients |
| | 0 | 397 | | if (effectiveAuthenticationSchemes.IsSet(AuthenticationSchemes.Negotiate)) |
| | | 398 | | { |
| | 0 | 399 | | assertionNames.Add(TransportPolicyConstants.NegotiateHttpAuthenticationName); |
| | | 400 | | } |
| | | 401 | | |
| | 0 | 402 | | if (effectiveAuthenticationSchemes.IsSet(AuthenticationSchemes.Ntlm)) |
| | | 403 | | { |
| | 0 | 404 | | assertionNames.Add(TransportPolicyConstants.NtlmHttpAuthenticationName); |
| | | 405 | | } |
| | | 406 | | |
| | 0 | 407 | | if (effectiveAuthenticationSchemes.IsSet(AuthenticationSchemes.Digest)) |
| | | 408 | | { |
| | 0 | 409 | | assertionNames.Add(TransportPolicyConstants.DigestHttpAuthenticationName); |
| | | 410 | | } |
| | | 411 | | |
| | 0 | 412 | | if (effectiveAuthenticationSchemes.IsSet(AuthenticationSchemes.Basic)) |
| | | 413 | | { |
| | 0 | 414 | | assertionNames.Add(TransportPolicyConstants.BasicHttpAuthenticationName); |
| | | 415 | | } |
| | | 416 | | |
| | 0 | 417 | | if (assertionNames.Count > 0) |
| | | 418 | | { |
| | 0 | 419 | | if (assertionNames.Count == 1) |
| | | 420 | | { |
| | 0 | 421 | | policyContext.GetBindingAssertions().Add(new XmlDocument().CreateElement(TransportPolicyConstant |
| | 0 | 422 | | assertionNames[0], TransportPolicyConstants.HttpTransportNamespace)); |
| | | 423 | | } |
| | | 424 | | else |
| | | 425 | | { |
| | 0 | 426 | | XmlDocument dummy = new XmlDocument(); |
| | 0 | 427 | | XmlElement root = dummy.CreateElement(MetadataStrings.WSPolicy.Prefix, |
| | 0 | 428 | | MetadataStrings.WSPolicy.Elements.ExactlyOne, |
| | 0 | 429 | | exporter.PolicyVersion.Namespace); |
| | | 430 | | |
| | 0 | 431 | | foreach (string assertionName in assertionNames) |
| | | 432 | | { |
| | 0 | 433 | | root.AppendChild(dummy.CreateElement(TransportPolicyConstants.HttpTransportPrefix, |
| | 0 | 434 | | assertionName, |
| | 0 | 435 | | TransportPolicyConstants.HttpTransportNamespace)); |
| | | 436 | | } |
| | | 437 | | |
| | 0 | 438 | | policyContext.GetBindingAssertions().Add(root); |
| | | 439 | | } |
| | | 440 | | } |
| | | 441 | | } |
| | | 442 | | |
| | 40 | 443 | | bool useWebSocketTransport = WebSocketHelper.UseWebSocketTransport(WebSocketSettings.TransportUsage, policyC |
| | 40 | 444 | | if (useWebSocketTransport && TransferMode != TransferMode.Buffered) |
| | | 445 | | { |
| | 0 | 446 | | policyContext.GetBindingAssertions().Add(new XmlDocument().CreateElement(TransportPolicyConstants.WebSoc |
| | 0 | 447 | | TransferMode.ToString(), TransportPolicyConstants.WebSocketPolicyNamespace)); |
| | | 448 | | } |
| | 40 | 449 | | } |
| | | 450 | | |
| | 0 | 451 | | void IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext context) { } |
| | | 452 | | |
| | | 453 | | void IWsdlExportExtension.ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext endpointContext) |
| | | 454 | | { |
| | | 455 | | bool createdNew; |
| | 31 | 456 | | MessageEncodingBindingElement encodingBindingElement = FindMessageEncodingBindingElement(endpointContext, ou |
| | 31 | 457 | | bool useWebSocketTransport = WebSocketHelper.UseWebSocketTransport(WebSocketSettings.TransportUsage, endpoin |
| | | 458 | | |
| | 31 | 459 | | EndpointAddress address = endpointContext.Endpoint.Address; |
| | 31 | 460 | | if (useWebSocketTransport) |
| | | 461 | | { |
| | 0 | 462 | | address = new EndpointAddress(WebSocketHelper.GetWebSocketUri(endpointContext.Endpoint.Address.Uri), end |
| | 0 | 463 | | WsdlNS.SoapAddressBinding binding = GetSoapAddressBinding(endpointContext.WsdlPort); |
| | 0 | 464 | | if (binding != null) |
| | | 465 | | { |
| | 0 | 466 | | binding.Location = address.Uri.AbsoluteUri; |
| | | 467 | | } |
| | | 468 | | } |
| | | 469 | | |
| | 31 | 470 | | ExportWsdlEndpoint(exporter, endpointContext, GetWsdlTransportUri(useWebSocketTransport), address, encodingB |
| | 31 | 471 | | } |
| | | 472 | | |
| | | 473 | | private static WsdlNS.SoapAddressBinding GetSoapAddressBinding(WsdlNS.Port wsdlPort) |
| | | 474 | | { |
| | 0 | 475 | | foreach (object o in wsdlPort.Extensions) |
| | | 476 | | { |
| | 0 | 477 | | if (o is WsdlNS.SoapAddressBinding binding) |
| | | 478 | | { |
| | 0 | 479 | | return binding; |
| | | 480 | | } |
| | | 481 | | } |
| | 0 | 482 | | return null; |
| | 0 | 483 | | } |
| | | 484 | | |
| | | 485 | | private MessageEncodingBindingElement FindMessageEncodingBindingElement(BindingElementCollection bindingElements |
| | | 486 | | { |
| | 71 | 487 | | createdNew = false; |
| | 71 | 488 | | MessageEncodingBindingElement encodingBindingElement = bindingElements.Find<MessageEncodingBindingElement>() |
| | 71 | 489 | | if (encodingBindingElement == null) |
| | | 490 | | { |
| | 0 | 491 | | createdNew = true; |
| | 0 | 492 | | encodingBindingElement = new BinaryMessageEncodingBindingElement(); |
| | | 493 | | } |
| | 71 | 494 | | return encodingBindingElement; |
| | | 495 | | } |
| | | 496 | | |
| | | 497 | | private MessageEncodingBindingElement FindMessageEncodingBindingElement(WsdlEndpointConversionContext endpointCo |
| | | 498 | | { |
| | 31 | 499 | | BindingElementCollection bindingElements = endpointContext.Endpoint.Binding.CreateBindingElements(); |
| | 31 | 500 | | return FindMessageEncodingBindingElement(bindingElements, out createdNew); |
| | | 501 | | } |
| | | 502 | | } |
| | | 503 | | |
| | | 504 | | internal static class TransportPolicyConstants |
| | | 505 | | { |
| | | 506 | | public const string BasicHttpAuthenticationName = "BasicAuthentication"; |
| | | 507 | | public const string CompositeDuplex = "CompositeDuplex"; |
| | | 508 | | public const string CompositeDuplexNamespace = "http://schemas.microsoft.com/net/2006/06/duplex"; |
| | | 509 | | public const string CompositeDuplexPrefix = "cdp"; |
| | | 510 | | public const string DigestHttpAuthenticationName = "DigestAuthentication"; |
| | | 511 | | public const string HttpTransportNamespace = "http://schemas.microsoft.com/ws/06/2004/policy/http"; |
| | | 512 | | public const string HttpTransportPrefix = "http"; |
| | | 513 | | public const string HttpTransportUri = "http://schemas.xmlsoap.org/soap/http"; |
| | | 514 | | public const string NegotiateHttpAuthenticationName = "NegotiateAuthentication"; |
| | | 515 | | public const string NtlmHttpAuthenticationName = "NtlmAuthentication"; |
| | | 516 | | public const string ProtectionLevelName = "ProtectionLevel"; |
| | | 517 | | public const string RequireClientCertificateName = "RequireClientCertificate"; |
| | | 518 | | public const string SslTransportSecurityName = "SslTransportSecurity"; |
| | | 519 | | public const string StreamedName = "Streamed"; |
| | | 520 | | public const string WebSocketPolicyPrefix = "mswsp"; |
| | | 521 | | public const string WebSocketPolicyNamespace = "http://schemas.microsoft.com/soap/websocket/policy"; |
| | | 522 | | public const string WebSocketTransportUri = "http://schemas.microsoft.com/soap/websocket"; |
| | | 523 | | public const string WebSocketEnabled = "WebSocketEnabled"; |
| | | 524 | | public const string WindowsTransportSecurityName = "WindowsTransportSecurity"; |
| | | 525 | | } |
| | | 526 | | } |