| | | 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; |
| | | 6 | | using System.Collections.ObjectModel; |
| | | 7 | | using System.ComponentModel; |
| | | 8 | | using System.Diagnostics; |
| | | 9 | | using CoreWCF.Channels; |
| | | 10 | | using CoreWCF.Diagnostics; |
| | | 11 | | using CoreWCF.Dispatcher; |
| | | 12 | | |
| | | 13 | | namespace CoreWCF.Description |
| | | 14 | | { |
| | | 15 | | public class ServiceDebugBehavior : IServiceBehavior |
| | | 16 | | { |
| | | 17 | | private Uri _httpHelpPageUrl; |
| | | 18 | | private Uri _httpsHelpPageUrl; |
| | | 19 | | |
| | 2849 | 20 | | public bool HttpHelpPageEnabled { get; set; } = true; |
| | | 21 | | |
| | | 22 | | public Uri HttpHelpPageUrl |
| | | 23 | | { |
| | 0 | 24 | | get { return _httpHelpPageUrl; } |
| | | 25 | | set |
| | | 26 | | { |
| | 0 | 27 | | if (value != null && value.IsAbsoluteUri && value.Scheme != Uri.UriSchemeHttp) |
| | | 28 | | { |
| | 0 | 29 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.Format(SR.SFxServiceMetadataBehavior |
| | 0 | 30 | | nameof(HttpHelpPageUrl), Uri.UriSchemeHttp, value.ToString(), value.Scheme)); |
| | | 31 | | } |
| | | 32 | | |
| | 0 | 33 | | _httpHelpPageUrl = value; |
| | 0 | 34 | | } |
| | | 35 | | } |
| | | 36 | | |
| | 1732 | 37 | | public bool HttpsHelpPageEnabled { get; set; } = true; |
| | | 38 | | |
| | | 39 | | public Uri HttpsHelpPageUrl |
| | | 40 | | { |
| | 0 | 41 | | get { return _httpsHelpPageUrl; } |
| | | 42 | | set |
| | | 43 | | { |
| | 0 | 44 | | if (value != null && value.IsAbsoluteUri && value.Scheme != Uri.UriSchemeHttps) |
| | | 45 | | { |
| | 0 | 46 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.Format(SR.SFxServiceMetadataBehavior |
| | 0 | 47 | | nameof(HttpsHelpPageUrl), Uri.UriSchemeHttps, value.ToString(), value.Scheme)); |
| | | 48 | | } |
| | | 49 | | |
| | 0 | 50 | | _httpsHelpPageUrl = value; |
| | 0 | 51 | | } |
| | | 52 | | } |
| | | 53 | | |
| | | 54 | | [DefaultValue(false)] |
| | 587 | 55 | | public bool IncludeExceptionDetailInFaults { get; set; } = false; |
| | | 56 | | |
| | 576 | 57 | | void IServiceBehavior.Validate(ServiceDescription description, ServiceHostBase serviceHostBase) { } |
| | | 58 | | |
| | | 59 | | void IServiceBehavior.AddBindingParameters(ServiceDescription description, ServiceHostBase serviceHostBase, Coll |
| | | 60 | | { |
| | 664 | 61 | | if (parameters == null) |
| | | 62 | | { |
| | 0 | 63 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(parameters)); |
| | | 64 | | } |
| | | 65 | | |
| | 664 | 66 | | ServiceDebugBehavior param = parameters.Find<ServiceDebugBehavior>(); |
| | 664 | 67 | | if (param == null) |
| | | 68 | | { |
| | 664 | 69 | | parameters.Add(this); |
| | | 70 | | } |
| | 664 | 71 | | } |
| | | 72 | | |
| | | 73 | | void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase) |
| | | 74 | | { |
| | 576 | 75 | | if (IncludeExceptionDetailInFaults) |
| | | 76 | | { |
| | 62 | 77 | | for (int i = 0; i < serviceHostBase.ChannelDispatchers.Count; i++) |
| | | 78 | | { |
| | 20 | 79 | | ChannelDispatcher channelDispatcher = serviceHostBase.ChannelDispatchers[i] as ChannelDispatcher; |
| | 20 | 80 | | if (channelDispatcher != null) |
| | | 81 | | { |
| | 20 | 82 | | channelDispatcher.IncludeExceptionDetailInFaults = true; |
| | | 83 | | } |
| | | 84 | | } |
| | | 85 | | } |
| | | 86 | | |
| | 576 | 87 | | if (!(HttpHelpPageEnabled || HttpsHelpPageEnabled)) |
| | | 88 | | { |
| | 0 | 89 | | return; |
| | | 90 | | } |
| | | 91 | | |
| | 576 | 92 | | ServiceMetadataExtension mex = ServiceMetadataExtension.EnsureServiceMetadataExtension(serviceHostBase); |
| | 576 | 93 | | SetExtensionProperties(mex, serviceHostBase); |
| | 576 | 94 | | } |
| | | 95 | | |
| | | 96 | | private void SetExtensionProperties(ServiceMetadataExtension mex, ServiceHostBase host) |
| | | 97 | | { |
| | 576 | 98 | | mex.HttpHelpPageEnabled = HttpHelpPageEnabled; |
| | 576 | 99 | | mex.HttpHelpPageUrl = host.GetVia(Uri.UriSchemeHttp, _httpHelpPageUrl == null ? new Uri(string.Empty, UriKin |
| | | 100 | | |
| | 576 | 101 | | mex.HttpsHelpPageEnabled = HttpsHelpPageEnabled; |
| | 576 | 102 | | mex.HttpsHelpPageUrl = host.GetVia(Uri.UriSchemeHttps, _httpsHelpPageUrl == null ? new Uri(string.Empty, Uri |
| | 576 | 103 | | } |
| | | 104 | | } |
| | | 105 | | } |