Esempio n. 1
0
        static internal void MessageFlowAtMessageReceived(Message message, OperationContext context, EventTraceActivity eventTraceActivity, bool createNewActivityId)
        {
            if (TraceUtility.MessageFlowTracing)
            {
                Guid activityId;
                Guid correlationId;
                bool activityIdFound = ActivityIdHeader.ExtractActivityAndCorrelationId(message, out activityId, out correlationId);
                if (TraceUtility.MessageFlowTracingOnly)
                {
                    if (createNewActivityId)
                    {
                        if (!activityIdFound)
                        {
                            activityId      = Guid.NewGuid();
                            activityIdFound = true;
                        }
                        //message flow tracing only - start fresh
                        DiagnosticTraceBase.ActivityId = Guid.Empty;
                    }

                    if (activityIdFound)
                    {
                        FxTrace.Trace.SetAndTraceTransfer(activityId, !createNewActivityId);
                    }
                }
                if (WcfEventSource.Instance.MessageReceivedFromTransportIsEnabled())
                {
                    if (context == null)
                    {
                        context = OperationContext.Current;
                    }

                    WcfEventSource.Instance.MessageReceivedFromTransport(eventTraceActivity, correlationId, TraceUtility.GetAnnotation(context));
                }
            }
        }
Esempio n. 2
0
 static TraceUtility()
 {
     //Maintain the order of calls
     TraceUtility.SetEtwProviderId();
     TraceUtility.SetEndToEndTracingFlags();
 }
Esempio n. 3
0
 internal static ArgumentNullException ThrowHelperArgumentNull(string paramName, Message message)
 {
     return((ArgumentNullException)TraceUtility.ThrowHelperError(new ArgumentNullException(paramName), message));
 }
Esempio n. 4
0
 internal static ArgumentException ThrowHelperArgument(string paramName, string message, Message msg)
 {
     return((ArgumentException)TraceUtility.ThrowHelperError(new ArgumentException(message, paramName), msg));
 }
        // If EnsureUniquePerformanceCounterInstanceName is enabled, PerformanceCountersBase.cs will be checking if instances
        // exist in each of these categories, so we need to ensure the categories all exist. This works around System.Diagnostics
        // calls using PerformanceCounterLib to cache which categories do/don't exist.
        private static void EnsureCategoriesExistIfNeeded()
        {
            if (categoriesExist || !ServiceModelAppSettings.EnsureUniquePerformanceCounterInstanceNames)
            {
                return;
            }

            OperationPerformanceCountersV2 operationCounter = null;
            EndpointPerformanceCountersV2  endpointCounter  = null;
            ServicePerformanceCountersV2   serviceCounter   = null;

            try
            {
                if (PerformanceCounterCategory.Exists(PerformanceCounterStrings.SERVICEMODELOPERATION.OperationPerfCounters) &&
                    PerformanceCounterCategory.Exists(PerformanceCounterStrings.SERVICEMODELENDPOINT.EndpointPerfCounters) &&
                    PerformanceCounterCategory.Exists(PerformanceCounterStrings.SERVICEMODELSERVICE.ServicePerfCounters))
                {
                    categoriesExist = true;
                    return;
                }

                // Categories do not exist. Update PerformanceCounterLib's cache using dummy counters.
                const string dummyValue = "_WCF_Admin";


                // Older operating systems (such as windows 7) report the category as not existing unless a counter instance
                // has been created in it. Create one instance in each of the categories to ensure they will exist in the cache
                // that System.Diagnostics calls use.
                ServiceHost dummyServiceHost = new ServiceHost(typeof(object), new Uri("http://" + dummyValue));
                operationCounter = new OperationPerformanceCountersV2(dummyValue, dummyValue, dummyValue, dummyValue);
                endpointCounter  = new EndpointPerformanceCountersV2(dummyValue, dummyValue, dummyValue);
                serviceCounter   = new ServicePerformanceCountersV2(dummyServiceHost);

                // Throw away cached categories, then read from the categories to cause the cache to be repopulated.
                PerformanceCounter.CloseSharedResources();
                PerformanceCounterCategory.Exists(dummyValue);
            }
            catch (UnauthorizedAccessException)
            {
                // Don't have permission to read performance counters. Trace a warning.
                if (DiagnosticUtility.ShouldTraceWarning)
                {
                    TraceUtility.TraceEvent(TraceEventType.Warning,
                                            TraceCode.PerformanceCountersFailedForService,
                                            SR.GetString(SR.EnsureCategoriesExistFailedPermission));
                }
            }
            catch
            {
                // Failed to ensure all of the categories exist. Catch the exception and try to create the counter anyway.
            }
            finally
            {
                // Delete the dummy counters, we don't need them anymore.
                if (operationCounter != null)
                {
                    operationCounter.DeleteInstance();
                }

                if (endpointCounter != null)
                {
                    endpointCounter.DeleteInstance();
                }

                if (serviceCounter != null)
                {
                    serviceCounter.DeleteInstance();
                }

                categoriesExist = true;
            }
        }
Esempio n. 6
0
        internal override void WriteTo(XmlWriter xml)
        {
            if ((this.message != null) &&
                (this.message.State != MessageState.Closed) &&
                (this.message.Headers != null))
            {
                try
                {
                    xml.WriteStartElement("MessageProperties");
                    if (message.Properties.Encoder != null)
                    {
                        xml.WriteElementString("Encoder", message.Properties.Encoder.ToString());
                    }
                    xml.WriteElementString("AllowOutputBatching", message.Properties.AllowOutputBatching.ToString());
                    if (message.Properties.Security != null && message.Properties.Security.ServiceSecurityContext != null)
                    {
                        xml.WriteStartElement("Security");
                        xml.WriteElementString("IsAnonymous", message.Properties.Security.ServiceSecurityContext.IsAnonymous.ToString());
                        bool windowsIdentityUsed = message.Properties.Security.ServiceSecurityContext.WindowsIdentity != null &&
                                                   !string.IsNullOrEmpty(message.Properties.Security.ServiceSecurityContext.WindowsIdentity.Name);
                        xml.WriteElementString("WindowsIdentityUsed", windowsIdentityUsed.ToString());
                        if (DiagnosticUtility.ShouldTraceVerbose)
                        {
                            xml.WriteStartElement("Claims");
                            AuthorizationContext authContext = message.Properties.Security.ServiceSecurityContext.AuthorizationContext;
                            for (int i = 0; i < authContext.ClaimSets.Count; ++i)
                            {
                                ClaimSet claimSet = authContext.ClaimSets[i];
                                xml.WriteStartElement("ClaimSet");
                                xml.WriteAttributeString("ClrType", base.XmlEncode(claimSet.GetType().AssemblyQualifiedName));

                                for (int j = 0; j < claimSet.Count; ++j)
                                {
                                    Fx.Assert(null != claimSet[j], "Claim cannot be null");
                                    SecurityTraceRecordHelper.WriteClaim(xml, claimSet[j]);
                                }
                                xml.WriteEndElement();
                            }
                            xml.WriteEndElement();
                        }
                        xml.WriteEndElement();
                    }

                    if (message.Properties.Via != null)
                    {
                        xml.WriteElementString("Via", message.Properties.Via.ToString());
                    }

                    xml.WriteEndElement();

                    xml.WriteStartElement(MessageLogTraceRecord.MessageHeadersElementName);
                    for (int i = 0; i < this.message.Headers.Count; i++)
                    {
                        this.message.Headers.WriteHeader(i, xml);
                    }

                    xml.WriteEndElement();
                }
                catch (CommunicationException e)
                {
                    if (DiagnosticUtility.ShouldTraceInformation)
                    {
                        TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.DiagnosticsFailedMessageTrace,
                                                SR.GetString(SR.TraceCodeDiagnosticsFailedMessageTrace), e, message);
                    }
                }
            }
        }