Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / ServiceModel / Dispatcher / JavascriptCallbackMessageInspector.cs / 1305376 / JavascriptCallbackMessageInspector.cs
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
#pragma warning disable 1634, 1691
namespace System.ServiceModel.Dispatcher
{
using System.Net;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Web;
using System.Web;
using System.ServiceModel.Description;
using System.Diagnostics;
using System.ServiceModel.Diagnostics;
class JavascriptCallbackMessageInspector : IDispatchMessageInspector
{
internal static readonly string applicationJavaScriptMediaType = "application/x-javascript";
public JavascriptCallbackMessageInspector(string callbackParameterName)
{
this.CallbackParameterName = callbackParameterName;
if (DiagnosticUtility.ShouldTraceInformation)
{
TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.JsonpCallbackNameSet, SR2.GetString(SR2.TraceCodeJsonpCallbackNameSet, callbackParameterName));
}
}
string CallbackParameterName { get; set; }
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
if (HttpContext.Current != null &&
HttpContext.Current.User != null &&
HttpContext.Current.User.Identity != null &&
HttpContext.Current.User.Identity.IsAuthenticated)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR2.CrossDomainJavascriptAuthNotSupported));
}
return null;
}
public void BeforeSendReply(ref Message reply, object correlationState)
{
WebBodyFormatMessageProperty formatProperty;
JavascriptCallbackResponseMessageProperty javascriptCallbackResponseMessageProperty = null;
if (reply.Properties.TryGetValue(WebBodyFormatMessageProperty.Name, out formatProperty) &&
formatProperty != null &&
formatProperty.Format == WebContentFormat.Json)
{
if (!reply.Properties.TryGetValue(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.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
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TimeSpanSecondsOrInfiniteConverter.cs
- DragStartedEventArgs.cs
- RootBrowserWindow.cs
- ToolboxItemAttribute.cs
- GenerateTemporaryTargetAssembly.cs
- Debug.cs
- DeclarationUpdate.cs
- EntityRecordInfo.cs
- Encoder.cs
- FontEmbeddingManager.cs
- UIElement3DAutomationPeer.cs
- ExcludePathInfo.cs
- TextServicesProperty.cs
- DbConnectionFactory.cs
- AppearanceEditorPart.cs
- PrintingPermissionAttribute.cs
- ParseChildrenAsPropertiesAttribute.cs
- FileStream.cs
- DataGridViewCellMouseEventArgs.cs
- BasicExpandProvider.cs
- DbConnectionStringCommon.cs
- List.cs
- SchemaImporter.cs
- NeutralResourcesLanguageAttribute.cs
- SoapCodeExporter.cs
- HttpCapabilitiesSectionHandler.cs
- Rfc2898DeriveBytes.cs
- ConditionCollection.cs
- sqlnorm.cs
- SqlGatherProducedAliases.cs
- RequestResizeEvent.cs
- QilSortKey.cs
- RenderDataDrawingContext.cs
- ByValueEqualityComparer.cs
- KeyValueConfigurationCollection.cs
- PublishLicense.cs
- DataServiceKeyAttribute.cs
- SocketException.cs
- ColumnPropertiesGroup.cs
- DataListItemCollection.cs
- EntityDataSourceSelectedEventArgs.cs
- DataViewListener.cs
- RuleDefinitions.cs
- ListItem.cs
- ScriptIgnoreAttribute.cs
- ColumnWidthChangingEvent.cs
- DropShadowBitmapEffect.cs
- ArrayExtension.cs
- UserNamePasswordValidator.cs
- JsonWriter.cs
- BindStream.cs
- CompilationUnit.cs
- MimeImporter.cs
- ChannelTraceRecord.cs
- DataGridCommandEventArgs.cs
- RepeatBehaviorConverter.cs
- HttpCapabilitiesBase.cs
- XmlUtf8RawTextWriter.cs
- StrokeNodeOperations.cs
- WorkflowServiceAttributes.cs
- WebContext.cs
- GridViewSelectEventArgs.cs
- ArithmeticException.cs
- AutomationTextAttribute.cs
- Validator.cs
- GridViewAutomationPeer.cs
- VolatileEnlistmentState.cs
- Queue.cs
- HtmlTernaryTree.cs
- HttpConfigurationContext.cs
- mda.cs
- DataGridCommandEventArgs.cs
- RsaElement.cs
- OutputCache.cs
- ImageListUtils.cs
- WindowsTreeView.cs
- prompt.cs
- ZoneIdentityPermission.cs
- SoapFault.cs
- XmlSigningNodeWriter.cs
- SqlDataSourceTableQuery.cs
- TimerElapsedEvenArgs.cs
- UrlAuthFailedErrorFormatter.cs
- QueryReaderSettings.cs
- UInt16Converter.cs
- ProgressChangedEventArgs.cs
- AutomationPattern.cs
- MenuItemCollection.cs
- AttachedPropertyBrowsableWhenAttributePresentAttribute.cs
- FixedHighlight.cs
- cryptoapiTransform.cs
- ImageMetadata.cs
- SystemTcpConnection.cs
- ServiceProviders.cs
- DataGridTable.cs
- RotateTransform.cs
- NotConverter.cs
- DocumentApplicationJournalEntry.cs
- SetIterators.cs
- FontInfo.cs