public void BeforeSendReply(ref Message reply, object correlationState)
        {
            WebBodyFormatMessageProperty property;
            JavascriptCallbackResponseMessageProperty property2 = null;

            if ((reply.Properties.TryGetValue <WebBodyFormatMessageProperty>("WebBodyFormatMessageProperty", out property) && (property != null)) && (property.Format == WebContentFormat.Json))
            {
                HttpResponseMessageProperty property3;
                if (!reply.Properties.TryGetValue <JavascriptCallbackResponseMessageProperty>(JavascriptCallbackResponseMessageProperty.Name, out property2) || (property2 == null))
                {
                    property2 = JavascriptCallbackMessageInspectorExUtilities.TrySetupJavascriptCallback(this.CallbackParameterName);
                    if (property2 != null)
                    {
                        reply.Properties.Add(JavascriptCallbackResponseMessageProperty.Name, property2);
                    }
                }
                if (((property2 != null) && reply.Properties.TryGetValue <HttpResponseMessageProperty>(HttpResponseMessageProperty.Name, out property3)) && (property3 != null))
                {
                    property3.Headers[HttpResponseHeader.ContentType] = applicationJavaScriptMediaType;
                    if (!property2.StatusCode.HasValue)
                    {
                        property2.StatusCode = new HttpStatusCode?(property3.StatusCode);
                    }
                    property3.StatusCode = HttpStatusCode.OK;
                    if (property3.SuppressEntityBody)
                    {
                        property3.SuppressEntityBody = false;
                        Message message = WebOperationContext.Current.CreateJsonResponse <object>(null);
                        message.Properties.CopyProperties(reply.Properties);
                        reply = message;
                    }
                }
            }
        }
        public void BeforeSendReply(ref Message reply, object correlationState)
        {
            WebBodyFormatMessageProperty formatProperty;
            JavascriptCallbackResponseMessageProperty javascriptCallbackResponseMessageProperty = null;

            if (reply.Properties.TryGetValue <WebBodyFormatMessageProperty>(WebBodyFormatMessageProperty.Name, out formatProperty) &&
                formatProperty != null &&
                formatProperty.Format == WebContentFormat.Json)
            {
                if (!reply.Properties.TryGetValue <JavascriptCallbackResponseMessageProperty>(JavascriptCallbackResponseMessageProperty.Name, out javascriptCallbackResponseMessageProperty) ||
                    javascriptCallbackResponseMessageProperty == null)
                {
                    javascriptCallbackResponseMessageProperty = WebHttpBehavior.TrySetupJavascriptCallback(this.CallbackParameterName);
                    if (javascriptCallbackResponseMessageProperty != null)
                    {
                        reply.Properties.Add(JavascriptCallbackResponseMessageProperty.Name, javascriptCallbackResponseMessageProperty);
                    }
                }
                if (javascriptCallbackResponseMessageProperty != null)
                {
                    HttpResponseMessageProperty property;
                    if (reply.Properties.TryGetValue <HttpResponseMessageProperty>(HttpResponseMessageProperty.Name, out property) &&
                        property != null)
                    {
                        property.Headers[HttpResponseHeader.ContentType] = applicationJavaScriptMediaType;
                        if (javascriptCallbackResponseMessageProperty.StatusCode == null)
                        {
                            javascriptCallbackResponseMessageProperty.StatusCode = property.StatusCode;
                        }
                        property.StatusCode = HttpStatusCode.OK;

                        if (property.SuppressEntityBody)
                        {
                            property.SuppressEntityBody = false;
                            Message nullJsonMessage = WebOperationContext.Current.CreateJsonResponse <object>(null);
                            nullJsonMessage.Properties.CopyProperties(reply.Properties);
                            reply = nullJsonMessage;
                        }
                    }
                }
            }
        }
        internal static JavascriptCallbackResponseMessageProperty TrySetupJavascriptCallback(string callbackParameterName)
        {
            JavascriptCallbackResponseMessageProperty property = null;

            if (!string.IsNullOrEmpty(callbackParameterName) && !OperationContext.Current.OutgoingMessageProperties.TryGetValue <JavascriptCallbackResponseMessageProperty>(JavascriptCallbackResponseMessageProperty.Name, out property))
            {
                UriTemplateMatch uriTemplateMatch = WebOperationContext.Current.IncomingRequest.UriTemplateMatch;
                if ((uriTemplateMatch != null) && uriTemplateMatch.QueryParameters.AllKeys.Contains <string>(callbackParameterName))
                {
                    string str = uriTemplateMatch.QueryParameters[callbackParameterName];
                    if (!string.IsNullOrEmpty(str))
                    {
                        JavascriptCallbackResponseMessageProperty property2 = new JavascriptCallbackResponseMessageProperty();
                        property2.CallbackFunctionName = str;
                        property = property2;
                        OperationContext.Current.OutgoingMessageProperties.Add(JavascriptCallbackResponseMessageProperty.Name, property);
                    }
                }
            }
            return(property);
        }