Exemplo n.º 1
0
 public void Write(Exception exception, RequestInformation info)
 {
     if (!(exception is WebException))
         Debug.WriteLine(
             string.Format("{0} - {1}: {2}",
             info.Method,
             info.Uri.ToString(),
             exception.Message));
 }
        private static void InternalHandleError(Exception error)
        {
            var behavior = GetWebErrorHandlerConfiguration();

            if (behavior == null || behavior.LogHandler == null) return;

            RequestInformation info;

            if (OperationContext.Current.OutgoingMessageProperties.ContainsKey(
                ErrorHandlerBehavior.HttpRequestInformationProperty))
                info = (RequestInformation)OperationContext.Current.OutgoingMessageProperties[
                    ErrorHandlerBehavior.HttpRequestInformationProperty];
            else info = new RequestInformation();

            behavior.LogHandler.Write(error, info);
        }
Exemplo n.º 3
0
            // ────────────────────────── IDispatchMessageInspector Members ──────────────────────────
            public object AfterReceiveRequest(ref Message request, 
                IClientChannel channel, InstanceContext instanceContext)
            {
                if (OperationContext.Current.OutgoingMessageProperties.ContainsKey(
                        HttpRequestInformationProperty)) return null;

                var info = new RequestInformation();

                var contentLengthHeader =
                    WebOperationContext.Current.IncomingRequest.Headers[HttpRequestHeader.ContentLength];

                long contentLength;
                if (!string.IsNullOrEmpty(contentLengthHeader))
                    long.TryParse(contentLengthHeader, out contentLength);
                else
                    contentLength = -1;

                info.ContentLength = contentLength;
                info.Uri = OperationContext.Current.IncomingMessageHeaders.To;
                info.Method = WebOperationContext.Current.IncomingRequest.Method;
                info.ContentType = WebOperationContext.Current.IncomingRequest.ContentType;
                info.Accept = WebOperationContext.Current.IncomingRequest.Accept;
                info.UserAgent = WebOperationContext.Current.IncomingRequest.UserAgent;
                info.Headers = WebOperationContext.Current.IncomingRequest.Headers;

                OperationContext.Current.OutgoingMessageProperties.Add(
                    HttpRequestInformationProperty, info);
                return null;
            }