Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / ServiceModel / Dispatcher / ContentTypeSettingDispatchMessageFormatter.cs / 1 / ContentTypeSettingDispatchMessageFormatter.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.ServiceModel.Dispatcher
{
using System.Collections;
using System.ServiceModel.Channels;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reflection;
using System.Xml;
using System.ServiceModel.Diagnostics;
using System.Net;
using System.ServiceModel.Web;
class ContentTypeSettingDispatchMessageFormatter : IDispatchMessageFormatter
{
IDispatchMessageFormatter innerFormatter;
string outgoingContentType;
public ContentTypeSettingDispatchMessageFormatter(string outgoingContentType, IDispatchMessageFormatter innerFormatter)
{
if (outgoingContentType == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("outgoingContentType");
}
if (innerFormatter == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("innerFormatter");
}
this.outgoingContentType = outgoingContentType;
this.innerFormatter = innerFormatter;
}
public void DeserializeRequest(Message message, object[] parameters)
{
this.innerFormatter.DeserializeRequest(message, parameters);
}
public Message SerializeReply(MessageVersion messageVersion, object[] parameters, object result)
{
Message message = this.innerFormatter.SerializeReply(messageVersion, parameters, result);
if (message != null)
{
AddResponseContentTypeProperty(message, this.outgoingContentType);
}
return message;
}
static void AddResponseContentTypeProperty(Message message, string contentType)
{
if (message == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
}
if (contentType == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contentType");
}
if (OperationContext.Current != null && OperationContext.Current.HasOutgoingMessageProperties)
{
if (string.IsNullOrEmpty(WebOperationContext.Current.OutgoingResponse.ContentType))
{
WebOperationContext.Current.OutgoingResponse.ContentType = contentType;
}
}
else
{
object prop;
message.Properties.TryGetValue(HttpResponseMessageProperty.Name, out prop);
HttpResponseMessageProperty httpProperty;
if (prop != null)
{
httpProperty = (HttpResponseMessageProperty) prop;
}
else
{
httpProperty = new HttpResponseMessageProperty();
message.Properties.Add(HttpResponseMessageProperty.Name, httpProperty);
}
if (string.IsNullOrEmpty(httpProperty.Headers[HttpResponseHeader.ContentType]))
{
httpProperty.Headers[HttpResponseHeader.ContentType] = contentType;
}
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CollectionChangeEventArgs.cs
- CallbackHandler.cs
- ReflectionPermission.cs
- EntityContainer.cs
- PageThemeBuildProvider.cs
- FilterElement.cs
- OracleDataReader.cs
- ReadOnlyAttribute.cs
- HttpSessionStateBase.cs
- CodeDefaultValueExpression.cs
- CanExecuteRoutedEventArgs.cs
- WebBrowserNavigatedEventHandler.cs
- CodeAttributeDeclaration.cs
- _SingleItemRequestCache.cs
- XPathQueryGenerator.cs
- DBCSCodePageEncoding.cs
- ImageIndexConverter.cs
- SpanIndex.cs
- ConfigurationException.cs
- WorkflowViewService.cs
- Pkcs9Attribute.cs
- ConfigurationElementProperty.cs
- CacheSection.cs
- XmlAttribute.cs
- Deflater.cs
- GACIdentityPermission.cs
- TcpConnectionPoolSettingsElement.cs
- SystemKeyConverter.cs
- FormatSettings.cs
- XsltLoader.cs
- XmlAnyElementAttribute.cs
- XhtmlTextWriter.cs
- XmlConverter.cs
- XmlLanguageConverter.cs
- Win32Native.cs
- BamlLocalizer.cs
- ConstructorNeedsTagAttribute.cs
- versioninfo.cs
- Serializer.cs
- StackOverflowException.cs
- PageAsyncTask.cs
- DbConnectionStringCommon.cs
- NullableDecimalSumAggregationOperator.cs
- ListParagraph.cs
- UnsafeNativeMethodsTablet.cs
- HijriCalendar.cs
- LocalIdKeyIdentifierClause.cs
- QueryOutputWriter.cs
- TraversalRequest.cs
- DesignerOptions.cs
- ScrollChrome.cs
- BridgeDataReader.cs
- TailCallAnalyzer.cs
- CustomAttributeFormatException.cs
- SystemIcmpV6Statistics.cs
- SoapParser.cs
- MetadataCache.cs
- ExpressionPrinter.cs
- BitmapEncoder.cs
- TypeHelper.cs
- ProxyHwnd.cs
- RowToFieldTransformer.cs
- DateTimeUtil.cs
- RectangleGeometry.cs
- ViewStateChangedEventArgs.cs
- CultureTable.cs
- LogicalTreeHelper.cs
- HitTestResult.cs
- PropertyChangingEventArgs.cs
- SoapSchemaMember.cs
- StatementContext.cs
- LoadedOrUnloadedOperation.cs
- FocusTracker.cs
- StagingAreaInputItem.cs
- AutoFocusStyle.xaml.cs
- PageContentAsyncResult.cs
- PersonalizationStateInfo.cs
- XmlSignatureProperties.cs
- _AuthenticationState.cs
- NativeMethods.cs
- CodePageUtils.cs
- RowUpdatingEventArgs.cs
- ValidationContext.cs
- PassportPrincipal.cs
- Journal.cs
- DetailsViewUpdatedEventArgs.cs
- RestHandler.cs
- ContentElement.cs
- CacheForPrimitiveTypes.cs
- ConstructorBuilder.cs
- BrowserCapabilitiesCompiler.cs
- XhtmlConformanceSection.cs
- InputGestureCollection.cs
- ObjectItemCachedAssemblyLoader.cs
- XmlSchemaDocumentation.cs
- ImageBrush.cs
- PerformanceCounterTraceRecord.cs
- FlowDocumentScrollViewer.cs
- ADConnectionHelper.cs
- EntityCommandDefinition.cs