object IClientMessageInspector.BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            var profilingSession = GetCurrentProfilingSession();
            if (profilingSession == null)
            {
                return null;
            }

            var wcfTiming = new WcfTiming(profilingSession.Profiler, ref request) { ExecuteType = channel.Via.Scheme };

            // we copies tags from the current profiling session to the remote WCF profiling session
            // so that we could group/wire client and server profiling session by tags in the future
            var tags = profilingSession.Profiler.Tags;
            if (tags == null)
            {
                tags = new TagCollection(null);
            }

            // add profiler.Id as a tag of sub WCF call session tags
            // so that we could build the full snapshot of parent profiling session
            tags.Add(profilingSession.Profiler.Id.ToString());

            if (!Equals(request.Headers.MessageVersion, MessageVersion.None))
            {
                var untypedHeader = new MessageHeader<string>(tags.ToString()).GetUntypedHeader(
                    WcfProfilingMessageHeaderConstants.HeaderNameOfProfilingTags
                    , WcfProfilingMessageHeaderConstants.HeaderNamespace);
                request.Headers.Add(untypedHeader);
            }
            else if (WebOperationContext.Current != null || channel.Via.Scheme == "http" || channel.Via.Scheme == "https")
            {
                if (!request.Properties.ContainsKey(WcfProfilingMessageHeaderConstants.HeaderNameOfProfilingTags))
                {
                    request.Properties.Add(
                        WcfProfilingMessageHeaderConstants.HeaderNameOfProfilingTags
                        , new HttpRequestMessageProperty());
                }

                if (request.Properties.ContainsKey(HttpRequestMessageProperty.Name))
                {
                    var httpRequestProperty = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];
                    httpRequestProperty.Headers.Add(
                        WcfProfilingMessageHeaderConstants.HeaderNameOfProfilingTags
                        , WcfProfilingMessageHeaderConstants.HeaderNamespace);
                }
            }

            // return wcfTiming as correlationState of AfterReceiveReply() to stop the WCF timing in AfterReceiveReply()
            return wcfTiming;
        }
Beispiel #2
0
        object IClientMessageInspector.BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            var profilingSession = GetCurrentProfilingSession();

            if (profilingSession == null)
            {
                return(null);
            }

            var wcfTiming = new WcfTiming(profilingSession.Profiler, ref request);

            wcfTiming.Data["remoteAddress"] = channel.RemoteAddress.ToString();

            // add correlationId as a header of sub wcf call
            // so that we could drill down to the wcf profiling session from current profiling session
            if (!Equals(request.Headers.MessageVersion, MessageVersion.None))
            {
                var untypedHeader = new MessageHeader <string>(wcfTiming.CorrelationId).GetUntypedHeader(
                    WcfProfilingMessageHeaderConstants.HeaderNameOfProfilingCorrelationId
                    , WcfProfilingMessageHeaderConstants.HeaderNamespace);
                request.Headers.Add(untypedHeader);
            }
            else if (WebOperationContext.Current != null || channel.Via.Scheme == "http" || channel.Via.Scheme == "https")
            {
                if (!request.Properties.ContainsKey(WcfProfilingMessageHeaderConstants.HeaderNameOfProfilingCorrelationId))
                {
                    request.Properties.Add(
                        WcfProfilingMessageHeaderConstants.HeaderNameOfProfilingCorrelationId
                        , new HttpRequestMessageProperty());
                }

                if (request.Properties.ContainsKey(HttpRequestMessageProperty.Name))
                {
                    var httpRequestProperty = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];
                    httpRequestProperty.Headers.Add(
                        WcfProfilingMessageHeaderConstants.HeaderNameOfProfilingCorrelationId
                        , wcfTiming.CorrelationId);
                }
            }

            // return wcfTiming as correlationState of AfterReceiveReply() to stop the WCF timing in AfterReceiveReply()
            return(wcfTiming);
        }