From c2a7f082f64a24546d4f28b280a571a853ce6041 Mon Sep 17 00:00:00 2001 From: Matt Connew Date: Tue, 13 Oct 2020 23:49:47 -0700 Subject: [PATCH] Enable ETW error logging for S.SM.Federation --- .../src/Internals/System}/FxTrace.cs | 54 ++-- .../Internals/System/Runtime/AssertHelper.cs | 17 ++ .../System/Runtime/DiagnosticStrings.cs | 19 ++ .../Diagnostics/DiagnosticTraceBase.cs | 97 ++++++ .../Runtime/Diagnostics/EtwDiagnosticTrace.cs | 226 ++++++++++++++ .../System/Runtime/ExceptionTrace.cs | 54 ++++ src/Common/src/Internals/System/Runtime/Fx.cs | 27 ++ .../System/Runtime/WcfEventSource.cs | 106 +++++++ .../System/ServiceModel/AddressingStrings.cs | 20 ++ .../System/ServiceModel/DiagnosticUtility.cs | 38 +++ .../Diagnostics/ExceptionUtility.cs | 23 ++ .../ServiceModel/DotNetSecurityStrings.cs | 19 ++ .../ServiceModel/Security/SecurityUtils.cs | 50 ++++ .../Internals/System/Runtime/AssertHelper.cs | 68 ----- .../System/Runtime/DiagnosticStrings.cs | 13 +- .../Diagnostics/DiagnosticTraceBase.cs | 101 +------ .../Runtime/Diagnostics/EtwDiagnosticTrace.cs | 277 +----------------- .../System/Runtime/ExceptionTrace.cs | 56 +--- .../src/Internals/System/Runtime/Fx.cs | 22 +- .../src/Internals/WcfEventSource.cs | 92 +----- .../src/SMDiagnostics/DiagnosticUtility.cs | 32 +- .../Diagnostics/ExceptionUtility.cs | 27 +- .../src/System.Private.ServiceModel.csproj | 10 +- .../ServiceModel/Diagnostics/TraceUtility.cs | 1 + .../ServiceModel/Security/SecurityUtils.cs | 25 +- .../src/System/ServiceModel/XD.cs | 26 +- .../src/Resources/Strings.resx | 126 ++++++++ .../src/System.ServiceModel.Federation.csproj | 24 ++ 28 files changed, 895 insertions(+), 755 deletions(-) rename src/{System.Private.ServiceModel/src/Internals => Common/src/Internals/System}/FxTrace.cs (59%) create mode 100644 src/Common/src/Internals/System/Runtime/AssertHelper.cs create mode 100644 src/Common/src/Internals/System/Runtime/DiagnosticStrings.cs create mode 100644 src/Common/src/Internals/System/Runtime/Diagnostics/DiagnosticTraceBase.cs create mode 100644 src/Common/src/Internals/System/Runtime/Diagnostics/EtwDiagnosticTrace.cs create mode 100644 src/Common/src/Internals/System/Runtime/ExceptionTrace.cs create mode 100644 src/Common/src/Internals/System/Runtime/Fx.cs create mode 100644 src/Common/src/Internals/System/Runtime/WcfEventSource.cs create mode 100644 src/Common/src/System/ServiceModel/AddressingStrings.cs create mode 100644 src/Common/src/System/ServiceModel/DiagnosticUtility.cs create mode 100644 src/Common/src/System/ServiceModel/Diagnostics/ExceptionUtility.cs create mode 100644 src/Common/src/System/ServiceModel/DotNetSecurityStrings.cs create mode 100644 src/Common/src/System/ServiceModel/Security/SecurityUtils.cs delete mode 100644 src/System.Private.ServiceModel/src/Internals/System/Runtime/AssertHelper.cs create mode 100644 src/System.ServiceModel.Federation/src/Resources/Strings.resx diff --git a/src/System.Private.ServiceModel/src/Internals/FxTrace.cs b/src/Common/src/Internals/System/FxTrace.cs similarity index 59% rename from src/System.Private.ServiceModel/src/Internals/FxTrace.cs rename to src/Common/src/Internals/System/FxTrace.cs index b9aa919987e..ae8609b4c88 100644 --- a/src/System.Private.ServiceModel/src/Internals/FxTrace.cs +++ b/src/Common/src/Internals/System/FxTrace.cs @@ -2,28 +2,20 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. - -using System.Diagnostics.CodeAnalysis; using System.Runtime; using System.Runtime.Diagnostics; namespace System { - internal static partial class FxTrace + internal static class FxTrace { + private static ExceptionTrace s_exceptionTrace; private const string baseEventSourceName = "System.ServiceModel"; private const string EventSourceVersion = "4.0.0.0"; - - private static Guid s_etwProviderId; private static string s_eventSourceName; private static EtwDiagnosticTrace s_diagnosticTrace; - private static ExceptionTrace s_exceptionTrace; private static readonly object s_lockObject = new object(); - [SuppressMessage(FxCop.Category.Performance, FxCop.Rule.AvoidUncalledPrivateCode, - Justification = "This template is shared across all assemblies, some of which use this accessor.")] - - public static ExceptionTrace Exception { get @@ -38,18 +30,6 @@ public static ExceptionTrace Exception } } - [SuppressMessage(FxCop.Category.Performance, FxCop.Rule.AvoidUncalledPrivateCode, - Justification = "This template is shared across all assemblies, some of which use this accessor.")] - public static EtwDiagnosticTrace Trace - { - get - { - EnsureEtwProviderInitialized(); - return FxTrace.s_diagnosticTrace; - } - } - - private static string EventSourceName { get @@ -63,31 +43,33 @@ private static string EventSourceName } } - [SuppressMessage(FxCop.Category.ReliabilityBasic, FxCop.Rule.UseNewGuidHelperRule, - Justification = "This is a method that creates ETW provider passing Guid Provider ID.")] - private static EtwDiagnosticTrace InitializeTracing() + public static EtwDiagnosticTrace Trace { - //Etw tracing is switched off by not enabling the session - s_etwProviderId = EtwDiagnosticTrace.DefaultEtwProviderId; - - EtwDiagnosticTrace trace = new EtwDiagnosticTrace(baseEventSourceName, s_etwProviderId); - - return trace; + get + { + EnsureEtwProviderInitialized(); + return s_diagnosticTrace; + } } - private static void EnsureEtwProviderInitialized() { - if (null == FxTrace.s_diagnosticTrace) + if (null == s_diagnosticTrace) { - lock (FxTrace.s_lockObject) + lock (s_lockObject) { - if (null == FxTrace.s_diagnosticTrace) + if (null == s_diagnosticTrace) { - FxTrace.s_diagnosticTrace = InitializeTracing(); + s_diagnosticTrace = InitializeTracing(); } } } } + + private static EtwDiagnosticTrace InitializeTracing() + { + EtwDiagnosticTrace trace = new EtwDiagnosticTrace(); + return trace; + } } } diff --git a/src/Common/src/Internals/System/Runtime/AssertHelper.cs b/src/Common/src/Internals/System/Runtime/AssertHelper.cs new file mode 100644 index 00000000000..e494ef74d4a --- /dev/null +++ b/src/Common/src/Internals/System/Runtime/AssertHelper.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Diagnostics; + +namespace System.Runtime +{ + internal static class AssertHelper + { + internal static void FireAssert(string message) + { + Debug.Assert(false, message); + } + } +} + diff --git a/src/Common/src/Internals/System/Runtime/DiagnosticStrings.cs b/src/Common/src/Internals/System/Runtime/DiagnosticStrings.cs new file mode 100644 index 00000000000..b4fbaeb9a0d --- /dev/null +++ b/src/Common/src/Internals/System/Runtime/DiagnosticStrings.cs @@ -0,0 +1,19 @@ +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Runtime +{ + internal static partial class DiagnosticStrings + { + internal const string DataTag = "Data"; + internal const string DataItemsTag = "DataItems"; + internal const string ExceptionStringTag = "ExceptionString"; + internal const string ExceptionTag = "Exception"; + internal const string ExceptionTypeTag = "ExceptionType"; + internal const string KeyTag = "Key"; + internal const string InnerExceptionTag = "InnerException"; + internal const string MessageTag = "Message"; + internal const string StackTraceTag = "StackTrace"; + internal const string ValueTag = "Value"; + } +} diff --git a/src/Common/src/Internals/System/Runtime/Diagnostics/DiagnosticTraceBase.cs b/src/Common/src/Internals/System/Runtime/Diagnostics/DiagnosticTraceBase.cs new file mode 100644 index 00000000000..8e557434926 --- /dev/null +++ b/src/Common/src/Internals/System/Runtime/Diagnostics/DiagnosticTraceBase.cs @@ -0,0 +1,97 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Diagnostics; +using System.Text; + +namespace System.Runtime.Diagnostics +{ + internal abstract partial class DiagnosticTraceBase + { + public DiagnosticTraceBase() + { + } + + //only used for exceptions, perf is not important + public static string XmlEncode(string text) + { + if (string.IsNullOrEmpty(text)) + { + return text; + } + + int len = text.Length; + StringBuilder encodedText = new StringBuilder(len + 8); //perf optimization, expecting no more than 2 > characters + + for (int i = 0; i < len; ++i) + { + char ch = text[i]; + switch (ch) + { + case '<': + encodedText.Append("<"); + break; + case '>': + encodedText.Append(">"); + break; + case '&': + encodedText.Append("&"); + break; + default: + encodedText.Append(ch); + break; + } + } + return encodedText.ToString(); + } + + protected static string StackTraceString(Exception exception) + { + string retval = exception.StackTrace; + if (string.IsNullOrEmpty(retval)) + { + // This means that the exception hasn't been thrown yet. We need to manufacture the stack then. + StackTrace stackTrace = new StackTrace(false); + // Figure out how many frames should be throw away + StackFrame[] stackFrames = stackTrace.GetFrames(); + + int frameCount = 0; + bool breakLoop = false; + foreach (StackFrame frame in stackFrames) + { + string methodName = frame.GetMethod().Name; + switch (methodName) + { + case "StackTraceString": + case "AddExceptionToTraceString": + case "BuildTrace": + case "TraceEvent": + case "TraceException": + case "GetAdditionalPayload": + ++frameCount; + break; + default: + if (methodName.StartsWith("ThrowHelper", StringComparison.Ordinal)) + { + ++frameCount; + } + else + { + breakLoop = true; + } + break; + } + if (breakLoop) + { + break; + } + } + + stackTrace = new StackTrace(frameCount, false); + retval = stackTrace.ToString(); + } + return retval; + } + } +} diff --git a/src/Common/src/Internals/System/Runtime/Diagnostics/EtwDiagnosticTrace.cs b/src/Common/src/Internals/System/Runtime/Diagnostics/EtwDiagnosticTrace.cs new file mode 100644 index 00000000000..6b024f1eb3b --- /dev/null +++ b/src/Common/src/Internals/System/Runtime/Diagnostics/EtwDiagnosticTrace.cs @@ -0,0 +1,226 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Text; +using System.Xml; + +namespace System.Runtime.Diagnostics +{ + internal sealed partial class EtwDiagnosticTrace : DiagnosticTraceBase + { + private const int MaxExceptionDepth = 64; + private const int XmlBracketsLength = 5; // "<>".Length; + + public EtwDiagnosticTrace() : base() + { + } + + internal static string ExceptionToTraceString(Exception exception, int maxTraceStringLength) + { + StringBuilder sb = StringBuilderPool.Take(); + try + { + using (StringWriter stringWriter = new StringWriter(sb, CultureInfo.CurrentCulture)) + { + using (XmlWriter xml = XmlWriter.Create(stringWriter)) + { + WriteExceptionToTraceString(xml, exception, maxTraceStringLength, MaxExceptionDepth); + xml.Flush(); + stringWriter.Flush(); + + return sb.ToString(); + } + } + } + finally + { + StringBuilderPool.Return(sb); + } + } + + private static void WriteExceptionToTraceString(XmlWriter xml, Exception exception, int remainingLength, int remainingAllowedRecursionDepth) + { + if (remainingAllowedRecursionDepth < 1) + { + return; + } + + if (!WriteStartElement(xml, DiagnosticStrings.ExceptionTag, ref remainingLength)) + { + return; + } + + try + { + IList> exceptionInfo = new List>() + { + new Tuple (DiagnosticStrings.ExceptionTypeTag, XmlEncode(exception.GetType().AssemblyQualifiedName)), + new Tuple (DiagnosticStrings.MessageTag, XmlEncode(exception.Message)), + new Tuple (DiagnosticStrings.StackTraceTag, XmlEncode(StackTraceString(exception))), // Stack trace is sometimes null + new Tuple (DiagnosticStrings.ExceptionStringTag, XmlEncode(exception.ToString())), + }; + + foreach (Tuple item in exceptionInfo) + { + if (!WriteXmlElementString(xml, item.Item1, item.Item2, ref remainingLength)) + { + return; + } + } + + if (exception.Data != null && exception.Data.Count > 0) + { + string exceptionData = GetExceptionData(exception); + if (exceptionData.Length < remainingLength) + { + xml.WriteRaw(exceptionData); + remainingLength -= exceptionData.Length; + } + } + + if (exception.InnerException != null) + { + string innerException = GetInnerException(exception, remainingLength, remainingAllowedRecursionDepth - 1); + if (!string.IsNullOrEmpty(innerException) && innerException.Length < remainingLength) + { + xml.WriteRaw(innerException); + } + } + } + finally + { + xml.WriteEndElement(); + } + } + + private static bool WriteStartElement(XmlWriter xml, string localName, ref int remainingLength) + { + int minXmlLength = (localName.Length * 2) + XmlBracketsLength; + if (minXmlLength <= remainingLength) + { + xml.WriteStartElement(localName); + remainingLength -= minXmlLength; + return true; + } + return false; + } + + private static bool WriteXmlElementString(XmlWriter xml, string localName, string value, ref int remainingLength) + { + int xmlElementLength = (localName.Length * 2) + XmlBracketsLength + (value != null ? value.Length : 0); + if (xmlElementLength <= remainingLength) + { + xml.WriteElementString(localName, value); + remainingLength -= xmlElementLength; + return true; + } + return false; + } + + private static string GetExceptionData(Exception exception) + { + StringBuilder sb = StringBuilderPool.Take(); + try + { + using (StringWriter stringWriter = new StringWriter(sb, CultureInfo.CurrentCulture)) + { + using (XmlWriter xml = XmlWriter.Create(stringWriter)) + { + xml.WriteStartElement(DiagnosticStrings.DataItemsTag); + foreach (object dataItem in exception.Data.Keys) + { + xml.WriteStartElement(DiagnosticStrings.DataTag); + xml.WriteElementString(DiagnosticStrings.KeyTag, XmlEncode(dataItem.ToString())); + if (exception.Data[dataItem] == null) + { + xml.WriteElementString(DiagnosticStrings.ValueTag, string.Empty); + } + else + { + xml.WriteElementString(DiagnosticStrings.ValueTag, XmlEncode(exception.Data[dataItem].ToString())); + } + + xml.WriteEndElement(); + } + xml.WriteEndElement(); + xml.Flush(); + stringWriter.Flush(); + + return sb.ToString(); + } + } + } + finally + { + StringBuilderPool.Return(sb); + } + } + + private static string GetInnerException(Exception exception, int remainingLength, int remainingAllowedRecursionDepth) + { + if (remainingAllowedRecursionDepth < 1) + { + return null; + } + + StringBuilder sb = StringBuilderPool.Take(); + try + { + using (StringWriter stringWriter = new StringWriter(sb, CultureInfo.CurrentCulture)) + { + using (XmlWriter xml = XmlWriter.Create(stringWriter)) + { + if (!WriteStartElement(xml, DiagnosticStrings.InnerExceptionTag, ref remainingLength)) + { + return null; + } + + WriteExceptionToTraceString(xml, exception.InnerException, remainingLength, remainingAllowedRecursionDepth); + xml.WriteEndElement(); + xml.Flush(); + stringWriter.Flush(); + + return sb.ToString(); + } + } + } + finally + { + StringBuilderPool.Return(sb); + } + } + + internal static class StringBuilderPool + { + private const int maxPooledStringBuilders = 64; + private static readonly ConcurrentQueue s_freeStringBuilders = new ConcurrentQueue(); + + public static StringBuilder Take() + { + StringBuilder sb = null; + if (s_freeStringBuilders.TryDequeue(out sb)) + { + return sb; + } + + return new StringBuilder(); + } + + public static void Return(StringBuilder sb) + { + Fx.Assert(sb != null, "'sb' MUST NOT be NULL."); + if (s_freeStringBuilders.Count <= maxPooledStringBuilders) + { + // There is a race condition here so the count could be off a little bit (but insignificantly) + sb.Clear(); + s_freeStringBuilders.Enqueue(sb); + } + } + } + } +} diff --git a/src/Common/src/Internals/System/Runtime/ExceptionTrace.cs b/src/Common/src/Internals/System/Runtime/ExceptionTrace.cs new file mode 100644 index 00000000000..b37061da562 --- /dev/null +++ b/src/Common/src/Internals/System/Runtime/ExceptionTrace.cs @@ -0,0 +1,54 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Diagnostics.Tracing; +using System.Runtime.Diagnostics; + +namespace System.Runtime +{ + internal partial class ExceptionTrace + { + private string _eventSourceName; + private readonly EtwDiagnosticTrace _diagnosticTrace; + + public ExceptionTrace(string eventSourceName, EtwDiagnosticTrace diagnosticTrace) + { + Fx.Assert(diagnosticTrace != null, "'diagnosticTrace' MUST NOT be NULL."); + + _eventSourceName = eventSourceName; + _diagnosticTrace = diagnosticTrace; + } + + + public void TraceEtwException(Exception exception, EventLevel eventLevel) + { + switch (eventLevel) + { + case EventLevel.Error: + case EventLevel.Warning: + if (WcfEventSource.Instance.ThrowingEtwExceptionIsEnabled()) + { + string serializedException = EtwDiagnosticTrace.ExceptionToTraceString(exception, int.MaxValue); + WcfEventSource.Instance.ThrowingEtwException(_eventSourceName, exception != null ? exception.ToString() : string.Empty, serializedException); + } + break; + case EventLevel.Critical: + if (WcfEventSource.Instance.EtwUnhandledExceptionIsEnabled()) + { + string serializedException = EtwDiagnosticTrace.ExceptionToTraceString(exception, int.MaxValue); + WcfEventSource.Instance.EtwUnhandledException(exception != null ? exception.ToString() : string.Empty, serializedException); + } + break; + default: + if (WcfEventSource.Instance.ThrowingEtwExceptionVerboseIsEnabled()) + { + string serializedException = EtwDiagnosticTrace.ExceptionToTraceString(exception, int.MaxValue); + WcfEventSource.Instance.ThrowingEtwExceptionVerbose(_eventSourceName, exception != null ? exception.ToString() : string.Empty, serializedException); + } + + break; + } + } + } +} diff --git a/src/Common/src/Internals/System/Runtime/Fx.cs b/src/Common/src/Internals/System/Runtime/Fx.cs new file mode 100644 index 00000000000..9512f129296 --- /dev/null +++ b/src/Common/src/Internals/System/Runtime/Fx.cs @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Diagnostics; + +namespace System.Runtime +{ + internal static partial class Fx + { + [Conditional("DEBUG")] + public static void Assert(bool condition, string description) + { + if (!condition) + { + Assert(description); + } + } + + [Conditional("DEBUG")] + public static void Assert(string description) + { + AssertHelper.FireAssert(description); + } + + } +} diff --git a/src/Common/src/Internals/System/Runtime/WcfEventSource.cs b/src/Common/src/Internals/System/Runtime/WcfEventSource.cs new file mode 100644 index 00000000000..911981b27df --- /dev/null +++ b/src/Common/src/Internals/System/Runtime/WcfEventSource.cs @@ -0,0 +1,106 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Diagnostics.Tracing; + +namespace System.Runtime +{ + [EventSource(Name = "Microsoft-Windows-Application Server-Applications", Guid = "c651f5f6-1c0d-492e-8ae1-b4efd7c9d503")] + internal sealed partial class WcfEventSource : EventSource + { + public static WcfEventSource Instance = new WcfEventSource(); +#pragma warning disable CS0414 // The field is assigned but its value is never used - Not used in Federation but is in S.P.SM + private bool _canTransferActivityId = false; +#pragma warning restore CS0414 // The field is assigned but its value is never used + + internal WcfEventSource() +#if DEBUG + : base(throwOnEventWriteErrors: true) +#endif // DEBUG + { + if (Environment.Version.Major >= 5) + { + _canTransferActivityId = true; + } + } + + public bool ThrowingEtwExceptionIsEnabled() + { + return base.IsEnabled(EventLevel.Warning, Keywords.Infrastructure, EventChannel.Analytic); + } + + [Event(EventIds.ThrowingEtwException, Level = EventLevel.Warning, Channel = EventChannel.Analytic, Opcode = EventOpcode.Info, Keywords = Keywords.Infrastructure | ChannelKeywords.Analytic, + Message = "Throwing an exception. Source: {0}. Exception details: {1}")] + public void ThrowingEtwException(string data1, string data2, string SerializedException, string AppDomain) + { + WriteEvent(EventIds.ThrowingEtwException, data1, data2, SerializedException, AppDomain); + } + + [NonEvent] + public void ThrowingEtwException(string data1, string data2, string SerializedException) + { + ThrowingEtwException(data1, data2, SerializedException, ""); + } + + public bool EtwUnhandledExceptionIsEnabled() + { + return base.IsEnabled(EventLevel.Critical, Keywords.Infrastructure, EventChannel.Operational); + } + + [Event(EventIds.EtwUnhandledException, Level = EventLevel.Critical, Channel = EventChannel.Operational, Opcode = EventOpcode.Info, Keywords = Keywords.Infrastructure | ChannelKeywords.Operational, + Message = "Unhandled exception. Exception details: {0}")] + public void EtwUnhandledException(string data1, string SerializedException, string AppDomain) + { + WriteEvent(EventIds.EtwUnhandledException, data1, SerializedException, AppDomain); + } + + [NonEvent] + public void EtwUnhandledException(string data1, string SerializedException) + { + EtwUnhandledException(data1, SerializedException, ""); + } + + public bool ThrowingEtwExceptionVerboseIsEnabled() + { + return base.IsEnabled(EventLevel.Verbose, Keywords.Infrastructure, EventChannel.Analytic); + } + + [Event(EventIds.ThrowingEtwExceptionVerbose, Level = EventLevel.Verbose, Channel = EventChannel.Analytic, Opcode = EventOpcode.Info, Keywords = Keywords.Infrastructure | ChannelKeywords.Analytic, + Message = "Throwing an exception. Source: {0}. Exception details: {1}")] + public void ThrowingEtwExceptionVerbose(string data1, string data2, string SerializedException, string AppDomain) + { + WriteEvent(EventIds.ThrowingEtwExceptionVerbose, data1, data2, SerializedException, AppDomain); + } + + [NonEvent] + public void ThrowingEtwExceptionVerbose(string data1, string data2, string SerializedException) + { + ThrowingEtwExceptionVerbose(data1, data2, SerializedException, ""); + } + + #region Keywords / Tasks / Opcodes + + public partial class EventIds + { + public const int EtwUnhandledException = 57408; + public const int ThrowingEtwExceptionVerbose = 57409; + public const int ThrowingEtwException = 57410; + } + + public partial class Keywords + { + public const EventKeywords Infrastructure = (EventKeywords)0x10000; + + } + + public class ChannelKeywords + { + public const EventKeywords Admin = unchecked((EventKeywords)0x8000000000000000); + public const EventKeywords Operational = unchecked((EventKeywords)0x4000000000000000); + public const EventKeywords Analytic = unchecked((EventKeywords)0x2000000000000000); + public const EventKeywords Debug = unchecked((EventKeywords)0x1000000000000000); + } + #endregion + } +} diff --git a/src/Common/src/System/ServiceModel/AddressingStrings.cs b/src/Common/src/System/ServiceModel/AddressingStrings.cs new file mode 100644 index 00000000000..3823e47863c --- /dev/null +++ b/src/Common/src/System/ServiceModel/AddressingStrings.cs @@ -0,0 +1,20 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.ServiceModel +{ + internal static partial class AddressingStrings + { + // String constants + public const string EndpointUnavailable = "EndpointUnavailable"; + public const string ActionNotSupported = "ActionNotSupported"; + public const string EndpointReferenceType = "EndpointReferenceType"; + public const string Request = "Request"; + public const string DestinationUnreachable = "DestinationUnreachable"; + public const string AnonymousUri = "http://schemas.microsoft.com/2005/12/ServiceModel/Addressing/Anonymous"; + public const string NoneUri = "http://schemas.microsoft.com/2005/12/ServiceModel/Addressing/None"; + public const string IndigoNamespace = "http://schemas.microsoft.com/serviceModel/2004/05/addressing"; + public const string ChannelTerminated = "ChannelTerminated"; + } +} diff --git a/src/Common/src/System/ServiceModel/DiagnosticUtility.cs b/src/Common/src/System/ServiceModel/DiagnosticUtility.cs new file mode 100644 index 00000000000..b17eccd002a --- /dev/null +++ b/src/Common/src/System/ServiceModel/DiagnosticUtility.cs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.ServiceModel.Diagnostics; + +namespace System.ServiceModel +{ + internal static partial class DiagnosticUtility + { + private const string TraceSourceName = "TraceSourceNameToReplace"; + internal const string EventSourceName = TraceSourceName + " [COR_BUILD_MAJOR].[COR_BUILD_MINOR].[CLR_OFFICIAL_ASSEMBLY_NUMBER].0"; + + private static ExceptionUtility s_exceptionUtility = null; + private static object s_lockObject = new object(); + + public static ExceptionUtility ExceptionUtility + { + get + { + return s_exceptionUtility ?? GetExceptionUtility(); + } + } + + private static ExceptionUtility GetExceptionUtility() + { + lock (s_lockObject) + { + if (s_exceptionUtility == null) + { + s_exceptionUtility = new ExceptionUtility(); + } + } + + return s_exceptionUtility; + } + } +} diff --git a/src/Common/src/System/ServiceModel/Diagnostics/ExceptionUtility.cs b/src/Common/src/System/ServiceModel/Diagnostics/ExceptionUtility.cs new file mode 100644 index 00000000000..3dc54b813d8 --- /dev/null +++ b/src/Common/src/System/ServiceModel/Diagnostics/ExceptionUtility.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Diagnostics.Tracing; + +namespace System.ServiceModel.Diagnostics +{ + internal partial class ExceptionUtility + { + public Exception ThrowHelperError(Exception exception) + { + return ThrowHelper(exception, EventLevel.Error); + } + + internal Exception ThrowHelper(Exception exception, EventLevel eventLevel) + { + FxTrace.Exception.TraceEtwException(exception, eventLevel); + return exception; + } + + } +} diff --git a/src/Common/src/System/ServiceModel/DotNetSecurityStrings.cs b/src/Common/src/System/ServiceModel/DotNetSecurityStrings.cs new file mode 100644 index 00000000000..04e1756a7e1 --- /dev/null +++ b/src/Common/src/System/ServiceModel/DotNetSecurityStrings.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.ServiceModel +{ + internal static class DotNetSecurityStrings + { + // Main dictionary strings + public const string Namespace = "http://schemas.microsoft.com/ws/2006/05/security"; // ServiceModelStringsVersion1.String162; + public const string Prefix = "dnse"; // ServiceModelStringsVersion1.String163; + // String constants + public const string KeyRenewalNeededFault = "ExpiredSecurityContextTokenKey"; + public const string SecuritySessionAbortedFault = "SecuritySessionAborted"; + public const string SecurityServerTooBusyFault = "ServerTooBusy"; + public const string SecuritySessionFaultAction = "http://schemas.microsoft.com/ws/2006/05/security/SecureConversationFault"; + public const string SecureConversationCancelNotAllowedFault = "SecureConversationCancellationNotAllowed"; + } +} diff --git a/src/Common/src/System/ServiceModel/Security/SecurityUtils.cs b/src/Common/src/System/ServiceModel/Security/SecurityUtils.cs new file mode 100644 index 00000000000..a9cb4cf4aaf --- /dev/null +++ b/src/Common/src/System/ServiceModel/Security/SecurityUtils.cs @@ -0,0 +1,50 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.ServiceModel.Channels; +using System.ServiceModel.Diagnostics; + +namespace System.ServiceModel.Security +{ + internal static partial class SecurityUtils + { + // Copied from TransportDefaults + public const int MaxSecurityFaultSize = 16384; + + internal static void ThrowIfNegotiationFault(Message message, EndpointAddress target) + { + if (message.IsFault) + { + MessageFault fault = MessageFault.CreateFault(message, MaxSecurityFaultSize); + Exception faultException = new FaultException(fault, message.Headers.Action); + if (fault.Code != null && fault.Code.IsReceiverFault && fault.Code.SubCode != null) + { + FaultCode subCode = fault.Code.SubCode; + if (subCode.Name == DotNetSecurityStrings.SecurityServerTooBusyFault && subCode.Namespace == DotNetSecurityStrings.Namespace) + { + throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ServerTooBusyException(SR.Format(SR.SecurityServerTooBusy, target), faultException)); + } + else if (subCode.Name == AddressingStrings.EndpointUnavailable && subCode.Namespace == message.Version.Addressing.Namespace()) + { + throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new EndpointNotFoundException(SR.Format(SR.SecurityEndpointNotFound, target), faultException)); + } + } + + throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(faultException); + } + } + } + + internal static class AddressingVersionExtensions + { + public static string Namespace(this AddressingVersion addressingVersion) + { + // AddressingVersion.ToString() returns the string "{addressing name} ({addressing namespace})" so we can + // extract the namespace out easily. + var addressingVersionString = AddressingVersion.WSAddressingAugust2004.ToString(); + int pos = addressingVersionString.IndexOf('('); + return addressingVersionString.Substring(pos + 1, addressingVersionString.Length - pos - 2); + } + } +} diff --git a/src/System.Private.ServiceModel/src/Internals/System/Runtime/AssertHelper.cs b/src/System.Private.ServiceModel/src/Internals/System/Runtime/AssertHelper.cs deleted file mode 100644 index 5690aa184cf..00000000000 --- a/src/System.Private.ServiceModel/src/Internals/System/Runtime/AssertHelper.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - - -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; -using System.Security; - -namespace System.Runtime -{ - internal static class AssertHelper - { - [SuppressMessage(FxCop.Category.ReliabilityBasic, FxCop.Rule.InvariantAssertRule, Justification = "Assert implementation")] - internal static void FireAssert(string message) - { - try - { - InternalFireAssert(ref message); - } - finally - { - Debug.Assert(false, message); - } - } - - [SuppressMessage(FxCop.Category.Globalization, FxCop.Rule.DoNotPassLiteralsAsLocalizedParameters, Justification = "Debug Only")] - [Fx.Tag.SecurityNote(Critical = "Calls into various critical methods", - Safe = "Exists only on debug versions")] - [SecuritySafeCritical] - private static void InternalFireAssert(ref string message) - { - try - { - if (Fx.AssertsFailFast) - { - try - { - Fx.Exception.TraceFailFast(message); - } - finally - { - Environment.FailFast(message); - } - } - } - catch (Exception exception) - { - if (Fx.IsFatal(exception)) - { - throw; - } - - string newMessage = "Exception during FireAssert!"; - try - { - newMessage = string.Concat(newMessage, " [", exception.GetType().Name, ": ", exception.Message, "] --> ", message); - } - finally - { - message = newMessage; - } - throw; - } - } - } -} - diff --git a/src/System.Private.ServiceModel/src/Internals/System/Runtime/DiagnosticStrings.cs b/src/System.Private.ServiceModel/src/Internals/System/Runtime/DiagnosticStrings.cs index 94cc368d302..403477287b1 100644 --- a/src/System.Private.ServiceModel/src/Internals/System/Runtime/DiagnosticStrings.cs +++ b/src/System.Private.ServiceModel/src/Internals/System/Runtime/DiagnosticStrings.cs @@ -2,33 +2,22 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. - namespace System.Runtime { - internal static class DiagnosticStrings + internal static partial class DiagnosticStrings { internal const string AppDomain = "AppDomain"; internal const string ChannelTag = "Channel"; internal const string Description = "Description"; - internal const string DataTag = "Data"; - internal const string DataItemsTag = "DataItems"; internal const string DescriptionTag = "Description"; - internal const string ExceptionTag = "Exception"; - internal const string ExceptionTypeTag = "ExceptionType"; - internal const string ExceptionStringTag = "ExceptionString"; internal const string ExtendedDataTag = "ExtendedData"; - internal const string InnerExceptionTag = "InnerException"; - internal const string KeyTag = "Key"; - internal const string MessageTag = "Message"; internal const string NamespaceTag = "xmlns"; internal const string NativeErrorCodeTag = "NativeErrorCode"; internal const string Separator = ":"; internal const string SeverityTag = "Severity"; internal const string SourceTag = "Source"; - internal const string StackTraceTag = "StackTrace"; internal const string Task = "Task"; internal const string TraceCodeTag = "TraceIdentifier"; internal const string TraceRecordTag = "TraceRecord"; - internal const string ValueTag = "Value"; } } diff --git a/src/System.Private.ServiceModel/src/Internals/System/Runtime/Diagnostics/DiagnosticTraceBase.cs b/src/System.Private.ServiceModel/src/Internals/System/Runtime/Diagnostics/DiagnosticTraceBase.cs index 7973bc5fec9..440f003599c 100644 --- a/src/System.Private.ServiceModel/src/Internals/System/Runtime/Diagnostics/DiagnosticTraceBase.cs +++ b/src/System.Private.ServiceModel/src/Internals/System/Runtime/Diagnostics/DiagnosticTraceBase.cs @@ -2,17 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. - using System.Globalization; -using System.Security; using System.Text; using System.Xml; -using System.Diagnostics.CodeAnalysis; using System.ServiceModel; namespace System.Runtime.Diagnostics { - internal abstract class DiagnosticTraceBase + internal abstract partial class DiagnosticTraceBase { //Diagnostics trace protected const string DefaultTraceListenerName = "Default"; @@ -22,35 +19,14 @@ internal abstract class DiagnosticTraceBase private const ushort TracingEventLogCategory = 4; - private object _thisLock; - protected string TraceSourceName; - [Fx.Tag.SecurityNote(Critical = "This determines the event source name.")] - [SecurityCritical] - - private string _eventSourceName; - public DiagnosticTraceBase(string traceSourceName) - { - _thisLock = new object(); - TraceSourceName = traceSourceName; - LastFailure = DateTime.MinValue; - } - - protected DateTime LastFailure { get; set; } - protected string EventSourceName { - [Fx.Tag.SecurityNote(Critical = "Access critical eventSourceName field", - Safe = "Doesn't leak info\\resources")] - [SecuritySafeCritical] get { return _eventSourceName; } - - [Fx.Tag.SecurityNote(Critical = "This determines the event source name.")] - [SecurityCritical] set { _eventSourceName = value; @@ -67,23 +43,15 @@ public bool TracingEnabled protected static string ProcessName { - [Fx.Tag.SecurityNote(Critical = "Satisfies a LinkDemand for 'PermissionSetAttribute' on type 'Process' when calling method GetCurrentProcess", - Safe = "Does not leak any resource and has been reviewed")] - [SecuritySafeCritical] get { string retval = null; - - return retval; } } protected static int ProcessId { - [Fx.Tag.SecurityNote(Critical = "Satisfies a LinkDemand for 'PermissionSetAttribute' on type 'Process' when calling method GetCurrentProcess", - Safe = "Does not leak any resource and has been reviewed")] - [SecuritySafeCritical] get { int retval = -1; @@ -91,45 +59,6 @@ protected static int ProcessId } } - - //only used for exceptions, perf is not important - public static string XmlEncode(string text) - { - if (string.IsNullOrEmpty(text)) - { - return text; - } - - int len = text.Length; - StringBuilder encodedText = new StringBuilder(len + 8); //perf optimization, expecting no more than 2 > characters - - for (int i = 0; i < len; ++i) - { - char ch = text[i]; - switch (ch) - { - case '<': - encodedText.Append("<"); - break; - case '>': - encodedText.Append(">"); - break; - case '&': - encodedText.Append("&"); - break; - default: - encodedText.Append(ch); - break; - } - } - return encodedText.ToString(); - } - - [Fx.Tag.SecurityNote(Critical = "Sets global event handlers for the AppDomain", - Safe = "Doesn't leak resources\\Information")] - [SecuritySafeCritical] - [SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotIndirectlyExposeMethodsWithLinkDemands, - Justification = "SecuritySafeCritical method, Does not expose critical resources returned by methods with Link Demands")] protected void AddDomainEventHandlersForCleanup() { } @@ -138,7 +67,6 @@ private void ExitOrUnloadEventHandler(object sender, EventArgs e) { } - protected static string CreateSourceString(object source) { var traceSourceStringProvider = source as ITraceSourceStringProvider; @@ -187,39 +115,12 @@ protected static void AddExceptionToTraceString(XmlWriter xml, Exception excepti } } - protected static string StackTraceString(Exception exception) - { - string retval = exception.StackTrace; - - return retval; - } - - // Duplicate code from System.ServiceModel.Diagnostics - [Fx.Tag.SecurityNote(Critical = "Calls unsafe methods, UnsafeCreateEventLogger and UnsafeLogEvent.", - Safe = "Event identities cannot be spoofed as they are constants determined inside the method, Demands the same permission that is asserted by the unsafe method.")] - [SecuritySafeCritical] - [SuppressMessage(FxCop.Category.Security, FxCop.Rule.SecureAsserts, - Justification = "Should not demand permission that is asserted by the EtwProvider ctor.")] - protected void LogTraceFailure(string traceString, Exception exception) - { - } - - public static Guid ActivityId { - [Fx.Tag.SecurityNote(Critical = "gets the CorrelationManager, which does a LinkDemand for UnmanagedCode", - Safe = "only uses the CM to get the ActivityId, which is not protected data, doesn't leak the CM")] - [SecuritySafeCritical] - [SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotIndirectlyExposeMethodsWithLinkDemands, - Justification = "SecuritySafeCriticial method")] get { throw ExceptionHelper.PlatformNotSupported(); } - - [Fx.Tag.SecurityNote(Critical = "gets the CorrelationManager, which does a LinkDemand for UnmanagedCode", - Safe = "only uses the CM to get the ActivityId, which is not protected data, doesn't leak the CM")] - [SecuritySafeCritical] set { throw ExceptionHelper.PlatformNotSupported(); diff --git a/src/System.Private.ServiceModel/src/Internals/System/Runtime/Diagnostics/EtwDiagnosticTrace.cs b/src/System.Private.ServiceModel/src/Internals/System/Runtime/Diagnostics/EtwDiagnosticTrace.cs index 14e3bd7f67a..6627da5fd86 100644 --- a/src/System.Private.ServiceModel/src/Internals/System/Runtime/Diagnostics/EtwDiagnosticTrace.cs +++ b/src/System.Private.ServiceModel/src/Internals/System/Runtime/Diagnostics/EtwDiagnosticTrace.cs @@ -2,69 +2,21 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. - using System.Globalization; using System.IO; -using System.Security; using System.Text; using System.Xml; -using System.Diagnostics.CodeAnalysis; using System.Collections.Generic; using System.Collections.Concurrent; namespace System.Runtime.Diagnostics { - internal sealed class EtwDiagnosticTrace : DiagnosticTraceBase + internal sealed partial class EtwDiagnosticTrace : DiagnosticTraceBase { - private const int XmlBracketsLength = 5; // "<>".Length; private const int MaxExceptionStringLength = 28 * 1024; - private const int MaxExceptionDepth = 64; - private static Guid s_defaultEtwProviderId = Guid.Empty; - - //Compiler will add all static initializers into the static constructor. Adding an explicit one to mark SecurityCritical. - [Fx.Tag.SecurityNote(Critical = "setting critical field defaultEtwProviderId")] - [SecurityCritical] - [SuppressMessage(FxCop.Category.Performance, FxCop.Rule.InitializeReferenceTypeStaticFieldsInline, - Justification = "SecurityCriticial method")] - static EtwDiagnosticTrace() - { - // In Partial Trust, initialize to Guid.Empty to disable ETW Tracing. - s_defaultEtwProviderId = Guid.Empty; - } - - [Fx.Tag.SecurityNote(Critical = "Access critical etwProvider, eventSourceName field")] - [SecurityCritical] - public EtwDiagnosticTrace(string traceSourceName, Guid etwProviderId) - : base(traceSourceName) - { - } - - static public Guid DefaultEtwProviderId - { - [Fx.Tag.SecurityNote(Critical = "reading critical field defaultEtwProviderId", Safe = "Doesn't leak info\\resources")] - [SecuritySafeCritical] - [SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotIndirectlyExposeMethodsWithLinkDemands, - Justification = "SecuritySafeCriticial method")] - get - { - return EtwDiagnosticTrace.s_defaultEtwProviderId; - } - [Fx.Tag.SecurityNote(Critical = "setting critical field defaultEtwProviderId")] - [SecurityCritical] - [SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotIndirectlyExposeMethodsWithLinkDemands, - Justification = "SecurityCriticial method")] - set - { - EtwDiagnosticTrace.s_defaultEtwProviderId = value; - } - } - public bool IsEtwProviderEnabled { - [Fx.Tag.SecurityNote(Critical = "Access critical etwProvider field", - Safe = "Doesn't leak info\\resources")] - [SecuritySafeCritical] get { return false; @@ -73,9 +25,6 @@ public bool IsEtwProviderEnabled public bool IsEnd2EndActivityTracingEnabled { - [Fx.Tag.SecurityNote(Critical = "Access critical etwProvider field", - Safe = "Doesn't leak resources or information")] - [SecuritySafeCritical] get { return WcfEventSource.Instance.IsEnabled() && @@ -85,24 +34,16 @@ public bool IsEnd2EndActivityTracingEnabled private bool EtwTracingEnabled { - [Fx.Tag.SecurityNote(Critical = "Access critical etwProvider field", - Safe = "Doesn't leak info\\resources")] - [SecuritySafeCritical] get { return false; } } - [Fx.Tag.SecurityNote(Critical = "Accesses the security critical etwProvider field", Safe = "Doesn't leak info\\resources")] - [SecuritySafeCritical] public void SetEnd2EndActivityTracingEnabled(bool isEnd2EndTracingEnabled) { } - - [Fx.Tag.SecurityNote(Critical = "Usage of EventDescriptor, which is protected by a LinkDemand")] - [SecurityCritical] public void Event(ref EventDescriptor eventDescriptor, string description) { if (TracingEnabled) @@ -121,18 +62,14 @@ public void SetAndTraceTransfer(Guid newId, bool emitTransfer) EtwDiagnosticTrace.ActivityId = newId; } - [Fx.Tag.SecurityNote(Critical = "Access critical transferEventDescriptor field, as well as other critical methods", - Safe = "Doesn't leak information or resources")] - [SecuritySafeCritical] public void TraceTransfer(Guid newId) { } - [SecurityCritical] + public void WriteTraceSource(ref EventDescriptor eventDescriptor, string description, TracePayload payload) { } - private static string LookupChannel(TraceChannel traceChannel) { string channelName; @@ -214,17 +151,11 @@ public TracePayload GetSerializedPayload(object source, TraceRecord traceRecord, return new TracePayload(serializedException, eventSource, DiagnosticTraceBase.AppDomainFriendlyName, extendedData, string.Empty); } - [Fx.Tag.SecurityNote(Critical = "Usage of EventDescriptor, which is protected by a LinkDemand", - Safe = "Only queries the status of the provider - does not modify the state")] - [SecuritySafeCritical] public bool IsEtwEventEnabled(ref EventDescriptor eventDescriptor) { return IsEtwEventEnabled(ref eventDescriptor, true); } - [Fx.Tag.SecurityNote(Critical = "Usage of EventDescriptor, which is protected by a LinkDemand", - Safe = "Only queries the status of the provider - does not modify the state")] - [SecuritySafeCritical] public bool IsEtwEventEnabled(ref EventDescriptor eventDescriptor, bool fullCheck) { return false; @@ -235,182 +166,6 @@ public override bool IsEnabled() return false; } - - internal static string ExceptionToTraceString(Exception exception, int maxTraceStringLength) - { - StringBuilder sb = StringBuilderPool.Take(); - try - { - using (StringWriter stringWriter = new StringWriter(sb, CultureInfo.CurrentCulture)) - { - using (XmlWriter xml = XmlWriter.Create(stringWriter)) - { - WriteExceptionToTraceString(xml, exception, maxTraceStringLength, MaxExceptionDepth); - xml.Flush(); - stringWriter.Flush(); - - return sb.ToString(); - } - } - } - finally - { - StringBuilderPool.Return(sb); - } - } - - private static void WriteExceptionToTraceString(XmlWriter xml, Exception exception, int remainingLength, int remainingAllowedRecursionDepth) - { - if (remainingAllowedRecursionDepth < 1) - { - return; - } - - if (!WriteStartElement(xml, DiagnosticStrings.ExceptionTag, ref remainingLength)) - { - return; - } - - try - { - IList> exceptionInfo = new List>() - { - new Tuple (DiagnosticStrings.ExceptionTypeTag, XmlEncode(exception.GetType().AssemblyQualifiedName)), - new Tuple (DiagnosticStrings.MessageTag, XmlEncode(exception.Message)), - new Tuple (DiagnosticStrings.StackTraceTag, XmlEncode(StackTraceString(exception))), // Stack trace is sometimes null - new Tuple (DiagnosticStrings.ExceptionStringTag, XmlEncode(exception.ToString())), - }; - - foreach (Tuple item in exceptionInfo) - { - if (!WriteXmlElementString(xml, item.Item1, item.Item2, ref remainingLength)) - { - return; - } - } - - if (exception.Data != null && exception.Data.Count > 0) - { - string exceptionData = GetExceptionData(exception); - if (exceptionData.Length < remainingLength) - { - xml.WriteRaw(exceptionData); - remainingLength -= exceptionData.Length; - } - } - - if (exception.InnerException != null) - { - string innerException = GetInnerException(exception, remainingLength, remainingAllowedRecursionDepth - 1); - if (!string.IsNullOrEmpty(innerException) && innerException.Length < remainingLength) - { - xml.WriteRaw(innerException); - } - } - } - finally - { - xml.WriteEndElement(); - } - } - - private static string GetInnerException(Exception exception, int remainingLength, int remainingAllowedRecursionDepth) - { - if (remainingAllowedRecursionDepth < 1) - { - return null; - } - - StringBuilder sb = StringBuilderPool.Take(); - try - { - using (StringWriter stringWriter = new StringWriter(sb, CultureInfo.CurrentCulture)) - { - using (XmlWriter xml = XmlWriter.Create(stringWriter)) - { - if (!WriteStartElement(xml, DiagnosticStrings.InnerExceptionTag, ref remainingLength)) - { - return null; - } - - WriteExceptionToTraceString(xml, exception.InnerException, remainingLength, remainingAllowedRecursionDepth); - xml.WriteEndElement(); - xml.Flush(); - stringWriter.Flush(); - - return sb.ToString(); - } - } - } - finally - { - StringBuilderPool.Return(sb); - } - } - - private static string GetExceptionData(Exception exception) - { - StringBuilder sb = StringBuilderPool.Take(); - try - { - using (StringWriter stringWriter = new StringWriter(sb, CultureInfo.CurrentCulture)) - { - using (XmlWriter xml = XmlWriter.Create(stringWriter)) - { - xml.WriteStartElement(DiagnosticStrings.DataItemsTag); - foreach (object dataItem in exception.Data.Keys) - { - xml.WriteStartElement(DiagnosticStrings.DataTag); - xml.WriteElementString(DiagnosticStrings.KeyTag, XmlEncode(dataItem.ToString())); - if (exception.Data[dataItem] == null) - { - xml.WriteElementString(DiagnosticStrings.ValueTag, string.Empty); - } - else - { - xml.WriteElementString(DiagnosticStrings.ValueTag, XmlEncode(exception.Data[dataItem].ToString())); - } - - xml.WriteEndElement(); - } - xml.WriteEndElement(); - xml.Flush(); - stringWriter.Flush(); - - return sb.ToString(); - } - } - } - finally - { - StringBuilderPool.Return(sb); - } - } - - private static bool WriteStartElement(XmlWriter xml, string localName, ref int remainingLength) - { - int minXmlLength = (localName.Length * 2) + EtwDiagnosticTrace.XmlBracketsLength; - if (minXmlLength <= remainingLength) - { - xml.WriteStartElement(localName); - remainingLength -= minXmlLength; - return true; - } - return false; - } - - private static bool WriteXmlElementString(XmlWriter xml, string localName, string value, ref int remainingLength) - { - int xmlElementLength = (localName.Length * 2) + EtwDiagnosticTrace.XmlBracketsLength + (value != null ? value.Length : 0); - if (xmlElementLength <= remainingLength) - { - xml.WriteElementString(localName, value); - remainingLength -= xmlElementLength; - return true; - } - return false; - } - private static class TraceCodes { public const string AppDomainUnload = "AppDomainUnload"; @@ -443,33 +198,5 @@ private static class LegacyTraceEventIds public const int TraceHandledException = LegacyTraceEventIds.Diagnostics | 0X0004; public const int UnhandledException = LegacyTraceEventIds.Diagnostics | 0X0005; } - - internal static class StringBuilderPool - { - private const int maxPooledStringBuilders = 64; - private static readonly ConcurrentQueue s_freeStringBuilders = new ConcurrentQueue(); - - public static StringBuilder Take() - { - StringBuilder sb = null; - if (s_freeStringBuilders.TryDequeue(out sb)) - { - return sb; - } - - return new StringBuilder(); - } - - public static void Return(StringBuilder sb) - { - Fx.Assert(sb != null, "'sb' MUST NOT be NULL."); - if (s_freeStringBuilders.Count <= maxPooledStringBuilders) - { - // There is a race condition here so the count could be off a little bit (but insignificantly) - sb.Clear(); - s_freeStringBuilders.Enqueue(sb); - } - } - } } } diff --git a/src/System.Private.ServiceModel/src/Internals/System/Runtime/ExceptionTrace.cs b/src/System.Private.ServiceModel/src/Internals/System/Runtime/ExceptionTrace.cs index 49ba15a9e01..a759557a80e 100644 --- a/src/System.Private.ServiceModel/src/Internals/System/Runtime/ExceptionTrace.cs +++ b/src/System.Private.ServiceModel/src/Internals/System/Runtime/ExceptionTrace.cs @@ -5,29 +5,15 @@ using System.Collections.ObjectModel; using System.Diagnostics; -using System.Diagnostics.Tracing; using System.Reflection; using System.Runtime.CompilerServices; -using System.Runtime.Diagnostics; -using System.Security; namespace System.Runtime { - internal class ExceptionTrace + internal partial class ExceptionTrace { private const ushort FailFastEventLogCategory = 6; - private string _eventSourceName; - private readonly EtwDiagnosticTrace _diagnosticTrace; - - public ExceptionTrace(string eventSourceName, EtwDiagnosticTrace diagnosticTrace) - { - Fx.Assert(diagnosticTrace != null, "'diagnosticTrace' MUST NOT be NULL."); - - _eventSourceName = eventSourceName; - _diagnosticTrace = diagnosticTrace; - } - public void AsInformation(Exception exception) { //Traces an informational trace message @@ -114,11 +100,11 @@ public Exception AsError(AggregateException aggregateExcept /// including the one returned. The containing /// will not be traced unless there are no inner exceptions. /// - /// The preferred type of inner exception to extract. + /// The preferred type of inner exception to extract. /// Use typeof(Exception) to extract the first exception regardless of type. /// The to examine. /// The event source to trace. - /// The extracted exception. It will not be null + /// The extracted exception. It will not be null /// but it may not be of type . public Exception AsError(AggregateException aggregateException, string eventSource) { @@ -236,44 +222,11 @@ public void TraceUnhandledException(Exception exception) TraceCore.UnhandledException(_diagnosticTrace, exception != null ? exception.ToString() : string.Empty, exception); } - public void TraceEtwException(Exception exception, EventLevel eventLevel) - { - switch (eventLevel) - { - case EventLevel.Error: - case EventLevel.Warning: - if (WcfEventSource.Instance.ThrowingEtwExceptionIsEnabled()) - { - string serializedException = EtwDiagnosticTrace.ExceptionToTraceString(exception, int.MaxValue); - WcfEventSource.Instance.ThrowingEtwException(_eventSourceName, exception != null ? exception.ToString() : string.Empty, serializedException); - } - break; - case EventLevel.Critical: - if (WcfEventSource.Instance.UnhandledExceptionIsEnabled()) - { - string serializedException = EtwDiagnosticTrace.ExceptionToTraceString(exception, int.MaxValue); - WcfEventSource.Instance.EtwUnhandledException(exception != null ? exception.ToString() : string.Empty, serializedException); - } - break; - default: - if (WcfEventSource.Instance.ThrowingExceptionVerboseIsEnabled()) - { - string serializedException = EtwDiagnosticTrace.ExceptionToTraceString(exception, int.MaxValue); - WcfEventSource.Instance.ThrowingEtwExceptionVerbose(_eventSourceName, exception != null ? exception.ToString() : string.Empty, serializedException); - } - - break; - } - } - private TException TraceException(TException exception) where TException : Exception { return TraceException(exception, _eventSourceName); } - [Fx.Tag.SecurityNote(Critical = "Calls 'System.Runtime.Interop.UnsafeNativeMethods.IsDebuggerPresent()' which is a P/Invoke method", - Safe = "Does not leak any resource, needed for debugging")] - [SecuritySafeCritical] private TException TraceException(TException exception, string eventSource) where TException : Exception @@ -287,9 +240,6 @@ private TException TraceException(TException exception, string event return exception; } - [Fx.Tag.SecurityNote(Critical = "Calls into critical method UnsafeNativeMethods.IsDebuggerPresent and UnsafeNativeMethods.DebugBreak", - Safe = "Safe because it's a no-op in retail builds.")] - [SecuritySafeCritical] private void BreakOnException(Exception exception) { diff --git a/src/System.Private.ServiceModel/src/Internals/System/Runtime/Fx.cs b/src/System.Private.ServiceModel/src/Internals/System/Runtime/Fx.cs index c6bac3c15eb..94c72e3f12e 100644 --- a/src/System.Private.ServiceModel/src/Internals/System/Runtime/Fx.cs +++ b/src/System.Private.ServiceModel/src/Internals/System/Runtime/Fx.cs @@ -17,7 +17,7 @@ namespace System.Runtime { - public static class Fx + internal static partial class Fx { private const string defaultEventSource = "System.Runtime"; @@ -77,9 +77,7 @@ internal static EtwDiagnosticTrace Trace private static EtwDiagnosticTrace InitializeTracing() { - EtwDiagnosticTrace trace = new EtwDiagnosticTrace(defaultEventSource, EtwDiagnosticTrace.DefaultEtwProviderId); - - return trace; + return new EtwDiagnosticTrace(); } public static ExceptionHandler AsynchronousThreadExceptionHandler @@ -94,22 +92,6 @@ public static ExceptionHandler AsynchronousThreadExceptionHandler } } - // Do not call the parameter "message" or else FxCop thinks it should be localized. - [Conditional("DEBUG")] - public static void Assert(bool condition, string description) - { - if (!condition) - { - Assert(description); - } - } - - [Conditional("DEBUG")] - public static void Assert(string description) - { - AssertHelper.FireAssert(description); - } - public static void AssertAndThrow(bool condition, string description) { if (!condition) diff --git a/src/System.Private.ServiceModel/src/Internals/WcfEventSource.cs b/src/System.Private.ServiceModel/src/Internals/WcfEventSource.cs index 7fd5e3fd4dc..76448cd22ea 100644 --- a/src/System.Private.ServiceModel/src/Internals/WcfEventSource.cs +++ b/src/System.Private.ServiceModel/src/Internals/WcfEventSource.cs @@ -7,23 +7,8 @@ namespace System.Runtime { - [EventSource(Name = "Microsoft-Windows-Application Server-Applications", Guid = "c651f5f6-1c0d-492e-8ae1-b4efd7c9d503")] - internal sealed class WcfEventSource : EventSource + internal sealed partial class WcfEventSource : EventSource { - public static WcfEventSource Instance = new WcfEventSource(); - private bool _canTransferActivityId = false; - - internal WcfEventSource() -#if DEBUG - : base(throwOnEventWriteErrors: true) -#endif // DEBUG - { - if (Environment.Version.Major >= 5) - { - _canTransferActivityId = true; - } - } - public bool BufferPoolAllocationIsEnabled() { return base.IsEnabled(EventLevel.Verbose, Keywords.Infrastructure, EventChannel.Debug); @@ -2078,60 +2063,6 @@ public void ThrowingExceptionVerbose(string data1, string data2, string Serializ ThrowingExceptionVerbose(data1, data2, SerializedException, ""); } - public bool EtwUnhandledExceptionIsEnabled() - { - return base.IsEnabled(EventLevel.Critical, Keywords.Infrastructure, EventChannel.Operational); - } - - [Event(EventIds.EtwUnhandledException, Level = EventLevel.Critical, Channel = EventChannel.Operational, Opcode = EventOpcode.Info, Keywords = Keywords.Infrastructure | ChannelKeywords.Operational, - Message = "Unhandled exception. Exception details: {0}")] - public void EtwUnhandledException(string data1, string SerializedException, string AppDomain) - { - WriteEvent(EventIds.EtwUnhandledException, data1, SerializedException, AppDomain); - } - - [NonEvent] - public void EtwUnhandledException(string data1, string SerializedException) - { - EtwUnhandledException(data1, SerializedException, ""); - } - - public bool ThrowingEtwExceptionVerboseIsEnabled() - { - return base.IsEnabled(EventLevel.Verbose, Keywords.Infrastructure, EventChannel.Analytic); - } - - [Event(EventIds.ThrowingEtwExceptionVerbose, Level = EventLevel.Verbose, Channel = EventChannel.Analytic, Opcode = EventOpcode.Info, Keywords = Keywords.Infrastructure | ChannelKeywords.Analytic, - Message = "Throwing an exception. Source: {0}. Exception details: {1}")] - public void ThrowingEtwExceptionVerbose(string data1, string data2, string SerializedException, string AppDomain) - { - WriteEvent(EventIds.ThrowingEtwExceptionVerbose, data1, data2, SerializedException, AppDomain); - } - - [NonEvent] - public void ThrowingEtwExceptionVerbose(string data1, string data2, string SerializedException) - { - ThrowingEtwExceptionVerbose(data1, data2, SerializedException, ""); - } - - public bool ThrowingEtwExceptionIsEnabled() - { - return base.IsEnabled(EventLevel.Warning, Keywords.Infrastructure, EventChannel.Analytic); - } - - [Event(EventIds.ThrowingEtwException, Level = EventLevel.Warning, Channel = EventChannel.Analytic, Opcode = EventOpcode.Info, Keywords = Keywords.Infrastructure | ChannelKeywords.Analytic, - Message = "Throwing an exception. Source: {0}. Exception details: {1}")] - public void ThrowingEtwException(string data1, string data2, string SerializedException, string AppDomain) - { - WriteEvent(EventIds.ThrowingEtwException, data1, data2, SerializedException, AppDomain); - } - - [NonEvent] - public void ThrowingEtwException(string data1, string data2, string SerializedException) - { - ThrowingEtwException(data1, data2, SerializedException, ""); - } - [NonEvent] private void SetActivityId(EventTraceActivity eventTraceActivity) { @@ -2153,7 +2084,7 @@ private void TransferActivityId(EventTraceActivity eventTraceActivity) #region Keywords / Tasks / Opcodes - public class EventIds + public partial class EventIds { public const int WorkflowInstanceRecord = 100; public const int WorkflowInstanceUnhandledExceptionRecord = 101; @@ -2632,9 +2563,9 @@ public class EventIds public const int HandledExceptionError = 57405; public const int HandledExceptionVerbose = 57406; public const int ThrowingExceptionVerbose = 57407; - public const int EtwUnhandledException = 57408; - public const int ThrowingEtwExceptionVerbose = 57409; - public const int ThrowingEtwException = 57410; + //public const int EtwUnhandledException = 57408; + //public const int ThrowingEtwExceptionVerbose = 57409; + //public const int ThrowingEtwException = 57410; public const int HttpHandlerPickedForUrl = 62326; } @@ -2904,7 +2835,7 @@ public class Opcodes public const EventOpcode RoutingServiceReceiveContextAbandoning = (EventOpcode)99; } - public class Keywords + public partial class Keywords { public const EventKeywords ServiceHost = (EventKeywords)0x1; public const EventKeywords Serialization = (EventKeywords)0x2; @@ -2922,7 +2853,7 @@ public class Keywords public const EventKeywords WebHTTP = (EventKeywords)0x2000; public const EventKeywords Discovery = (EventKeywords)0x4000; public const EventKeywords RoutingServices = (EventKeywords)0x8000; - public const EventKeywords Infrastructure = (EventKeywords)0x10000; + //public const EventKeywords Infrastructure = (EventKeywords)0x10000; public const EventKeywords EndToEndMonitoring = (EventKeywords)0x20000; public const EventKeywords HealthMonitoring = (EventKeywords)0x40000; public const EventKeywords Troubleshooting = (EventKeywords)0x80000; @@ -2934,15 +2865,6 @@ public class Keywords public const EventKeywords WFServices = (EventKeywords)0x4000000; public const EventKeywords WFInstanceStore = (EventKeywords)0x8000000; } - - public class ChannelKeywords - { - public const EventKeywords Admin = unchecked((EventKeywords)0x8000000000000000); - public const EventKeywords Operational = unchecked((EventKeywords)0x4000000000000000); - public const EventKeywords Analytic = unchecked((EventKeywords)0x2000000000000000); - public const EventKeywords Debug = unchecked((EventKeywords)0x1000000000000000); - } - #endregion } } diff --git a/src/System.Private.ServiceModel/src/SMDiagnostics/DiagnosticUtility.cs b/src/System.Private.ServiceModel/src/SMDiagnostics/DiagnosticUtility.cs index 7655390bb6c..40b54339eeb 100644 --- a/src/System.Private.ServiceModel/src/SMDiagnostics/DiagnosticUtility.cs +++ b/src/System.Private.ServiceModel/src/SMDiagnostics/DiagnosticUtility.cs @@ -15,42 +15,12 @@ namespace System.ServiceModel /// /// This is the Management utility class. /// - public static partial class DiagnosticUtility + internal static partial class DiagnosticUtility { - private const string TraceSourceName = "TraceSourceNameToReplace"; - internal const string EventSourceName = TraceSourceName + " [COR_BUILD_MAJOR].[COR_BUILD_MINOR].[CLR_OFFICIAL_ASSEMBLY_NUMBER].0"; internal const string DefaultTraceListenerName = "Default"; private static bool s_shouldUseActivity = false; - private static object s_lockObject = new object(); - - private static ExceptionUtility s_exceptionUtility = null; - - private static void UpdateLevel() - { - } - - public static ExceptionUtility ExceptionUtility - { - get - { - return DiagnosticUtility.s_exceptionUtility ?? GetExceptionUtility(); - } - } - - private static ExceptionUtility GetExceptionUtility() - { - lock (DiagnosticUtility.s_lockObject) - { - if (DiagnosticUtility.s_exceptionUtility == null) - { - DiagnosticUtility.s_exceptionUtility = new ExceptionUtility(DiagnosticUtility.TraceSourceName, DiagnosticUtility.EventSourceName, FxTrace.Exception); - } - } - return DiagnosticUtility.s_exceptionUtility; - } - internal static void TraceHandledException(Exception exception, TraceEventType traceEventType) { FxTrace.Exception.TraceHandledException(exception, traceEventType); diff --git a/src/System.Private.ServiceModel/src/SMDiagnostics/System/ServiceModel/Diagnostics/ExceptionUtility.cs b/src/System.Private.ServiceModel/src/SMDiagnostics/System/ServiceModel/Diagnostics/ExceptionUtility.cs index 076683de5d6..bf3a6afedc2 100644 --- a/src/System.Private.ServiceModel/src/SMDiagnostics/System/ServiceModel/Diagnostics/ExceptionUtility.cs +++ b/src/System.Private.ServiceModel/src/SMDiagnostics/System/ServiceModel/Diagnostics/ExceptionUtility.cs @@ -2,35 +2,22 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. - using System.Diagnostics.Tracing; using System.Runtime; using System.Xml; namespace System.ServiceModel.Diagnostics { - public class ExceptionUtility + internal partial class ExceptionUtility { private const string ExceptionStackAsStringKey = "System.ServiceModel.Diagnostics.ExceptionUtility.ExceptionStackAsString"; // This field should be only used for debug build. internal static ExceptionUtility mainInstance; - private ExceptionTrace _exceptionTrace; - private string _name; - private string _eventSourceName; - [ThreadStatic] private static Guid s_activityId; - internal ExceptionUtility(string name, string eventSourceName, object exceptionTrace) - { - _exceptionTrace = (ExceptionTrace)exceptionTrace; - _name = name; - _eventSourceName = eventSourceName; - } - - public ArgumentException ThrowHelperArgument(string message) { return (ArgumentException)ThrowHelperError(new ArgumentException(message)); @@ -86,23 +73,11 @@ public Exception ThrowHelperCritical(Exception exception) return ThrowHelper(exception, EventLevel.Critical); } - public Exception ThrowHelperError(Exception exception) - { - return ThrowHelper(exception, EventLevel.Error); - } - public Exception ThrowHelperWarning(Exception exception) { return ThrowHelper(exception, EventLevel.Warning); } - internal Exception ThrowHelper(Exception exception, EventLevel eventLevel) - { - FxTrace.Exception.TraceEtwException(exception, eventLevel); - - return exception; - } - internal Exception ThrowHelperXml(XmlReader reader, string message) { return ThrowHelperXml(reader, message, null); diff --git a/src/System.Private.ServiceModel/src/System.Private.ServiceModel.csproj b/src/System.Private.ServiceModel/src/System.Private.ServiceModel.csproj index e7a9cc315cc..4b52b781ecf 100644 --- a/src/System.Private.ServiceModel/src/System.Private.ServiceModel.csproj +++ b/src/System.Private.ServiceModel/src/System.Private.ServiceModel.csproj @@ -44,7 +44,7 @@ $(DefineConstants);FEATURE_NETNATIVE - + $(DefineConstants);FEATURE_CORECLR @@ -92,6 +92,14 @@ Common\System\SR.cs + + true + Common\System\ServiceModel\%(RecursiveDir)%(Filename)%(Extension) + + + true + Common\Internals\%(RecursiveDir)%(Filename)%(Extension) + diff --git a/src/System.Private.ServiceModel/src/System/ServiceModel/Diagnostics/TraceUtility.cs b/src/System.Private.ServiceModel/src/System/ServiceModel/Diagnostics/TraceUtility.cs index 870a03b9596..b037619e600 100644 --- a/src/System.Private.ServiceModel/src/System/ServiceModel/Diagnostics/TraceUtility.cs +++ b/src/System.Private.ServiceModel/src/System/ServiceModel/Diagnostics/TraceUtility.cs @@ -232,6 +232,7 @@ private static string GenerateMsdnTraceCode(int traceCode) internal static Exception ThrowHelperError(Exception exception, Message message) { + DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception); return exception; } diff --git a/src/System.Private.ServiceModel/src/System/ServiceModel/Security/SecurityUtils.cs b/src/System.Private.ServiceModel/src/System/ServiceModel/Security/SecurityUtils.cs index 52dc7f88908..ac096fbf560 100755 --- a/src/System.Private.ServiceModel/src/System/ServiceModel/Security/SecurityUtils.cs +++ b/src/System.Private.ServiceModel/src/System/ServiceModel/Security/SecurityUtils.cs @@ -26,7 +26,7 @@ namespace System.ServiceModel.Security { - public static class ProtectionLevelHelper + internal static class ProtectionLevelHelper { public static bool IsDefined(ProtectionLevel value) { @@ -240,7 +240,7 @@ public static IdentityModel.DictionaryManager Instance } } - internal static class SecurityUtils + internal static partial class SecurityUtils { public const string Principal = "Principal"; public const string Identities = "Identities"; @@ -1243,28 +1243,7 @@ internal static void FixNetworkCredential(ref NetworkCredential credential) } } - internal static void ThrowIfNegotiationFault(Message message, EndpointAddress target) - { - if (message.IsFault) - { - MessageFault fault = MessageFault.CreateFault(message, TransportDefaults.MaxSecurityFaultSize); - Exception faultException = new FaultException(fault, message.Headers.Action); - if (fault.Code != null && fault.Code.IsReceiverFault && fault.Code.SubCode != null) - { - FaultCode subCode = fault.Code.SubCode; - if (subCode.Name == DotNetSecurityStrings.SecurityServerTooBusyFault && subCode.Namespace == DotNetSecurityStrings.Namespace) - { - throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ServerTooBusyException(SR.Format(SR.SecurityServerTooBusy, target), faultException)); - } - else if (subCode.Name == AddressingStrings.EndpointUnavailable && subCode.Namespace == message.Version.Addressing.Namespace) - { - throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new EndpointNotFoundException(SR.Format(SR.SecurityEndpointNotFound, target), faultException)); - } - } - throw TraceUtility.ThrowHelperError(faultException, message); - } - } internal static bool IsSecurityFault(MessageFault fault, SecurityStandardsManager standardsManager) { diff --git a/src/System.Private.ServiceModel/src/System/ServiceModel/XD.cs b/src/System.Private.ServiceModel/src/System/ServiceModel/XD.cs index b91bce4c0ec..ce10cc06b43 100644 --- a/src/System.Private.ServiceModel/src/System/ServiceModel/XD.cs +++ b/src/System.Private.ServiceModel/src/System/ServiceModel/XD.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. - // NOTE: this file was generated from 'xd.xml' using System.Xml; @@ -971,7 +970,7 @@ internal static class ActivityIdFlowStrings public const string ActivityIdNamespace = ServiceModelStringsVersion1.String426; } - internal static class AddressingStrings + internal static partial class AddressingStrings { // Main dictionary strings public const string Action = ServiceModelStringsVersion1.String5; @@ -1000,16 +999,6 @@ internal static class AddressingStrings public const string X509v3Certificate = ServiceModelStringsVersion1.String98; public const string ReferenceParameters = ServiceModelStringsVersion1.String100; public const string IsReferenceParameter = ServiceModelStringsVersion1.String101; - // String constants - public const string EndpointUnavailable = "EndpointUnavailable"; - public const string ActionNotSupported = "ActionNotSupported"; - public const string EndpointReferenceType = "EndpointReferenceType"; - public const string Request = "Request"; - public const string DestinationUnreachable = "DestinationUnreachable"; - public const string AnonymousUri = "http://schemas.microsoft.com/2005/12/ServiceModel/Addressing/Anonymous"; - public const string NoneUri = "http://schemas.microsoft.com/2005/12/ServiceModel/Addressing/None"; - public const string IndigoNamespace = "http://schemas.microsoft.com/serviceModel/2004/05/addressing"; - public const string ChannelTerminated = "ChannelTerminated"; } internal static class Addressing10Strings @@ -1161,19 +1150,6 @@ internal static class DotNetOneWayStrings public const string HeaderName = ServiceModelStringsVersion1.String438; } - internal static class DotNetSecurityStrings - { - // Main dictionary strings - public const string Namespace = ServiceModelStringsVersion1.String162; - public const string Prefix = ServiceModelStringsVersion1.String163; - // String constants - public const string KeyRenewalNeededFault = "ExpiredSecurityContextTokenKey"; - public const string SecuritySessionAbortedFault = "SecuritySessionAborted"; - public const string SecurityServerTooBusyFault = "ServerTooBusy"; - public const string SecuritySessionFaultAction = "http://schemas.microsoft.com/ws/2006/05/security/SecureConversationFault"; - public const string SecureConversationCancelNotAllowedFault = "SecureConversationCancellationNotAllowed"; - } - class DotNetSecurityDictionary { public XmlDictionaryString Namespace; diff --git a/src/System.ServiceModel.Federation/src/Resources/Strings.resx b/src/System.ServiceModel.Federation/src/Resources/Strings.resx new file mode 100644 index 00000000000..30e93e165f0 --- /dev/null +++ b/src/System.ServiceModel.Federation/src/Resources/Strings.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Server '{0}' sent back a fault indicating it is in the process of shutting down. Please see the inner exception for fault details. + + + Server '{0}' sent back a fault indicating it is too busy to process the request. Please retry later. Please see the inner exception for fault details. + + \ No newline at end of file diff --git a/src/System.ServiceModel.Federation/src/System.ServiceModel.Federation.csproj b/src/System.ServiceModel.Federation/src/System.ServiceModel.Federation.csproj index ff9c2ac900b..960973b63e2 100644 --- a/src/System.ServiceModel.Federation/src/System.ServiceModel.Federation.csproj +++ b/src/System.ServiceModel.Federation/src/System.ServiceModel.Federation.csproj @@ -24,4 +24,28 @@ + + + + + true + FxResources.$(AssemblyName).SR + false + System.SR + + + + + + Common\System\SR.cs + + + true + Common\System\ServiceModel\%(RecursiveDir)%(Filename)%(Extension) + + + true + Common\Internals\%(RecursiveDir)%(Filename)%(Extension) + +