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
- Normalization.cs
- Solver.cs
- DirtyTextRange.cs
- EncoderParameter.cs
- ActiveDocumentEvent.cs
- SessionParameter.cs
- LinearKeyFrames.cs
- ContainerControlDesigner.cs
- UnsafePeerToPeerMethods.cs
- DeadCharTextComposition.cs
- MatcherBuilder.cs
- XmlCountingReader.cs
- PeerNameResolver.cs
- SafeBitVector32.cs
- ExecutionEngineException.cs
- OlePropertyStructs.cs
- PagerSettings.cs
- ImageDrawing.cs
- WebReferencesBuildProvider.cs
- BamlTreeUpdater.cs
- SystemIPGlobalProperties.cs
- HashCodeCombiner.cs
- ToRequest.cs
- TableLayoutColumnStyleCollection.cs
- _HeaderInfoTable.cs
- NamedPipeTransportSecurityElement.cs
- HtmlHistory.cs
- PositiveTimeSpanValidator.cs
- ReflectionServiceProvider.cs
- NotifyInputEventArgs.cs
- ExtensionQuery.cs
- BStrWrapper.cs
- BamlLocalizableResourceKey.cs
- RepeaterCommandEventArgs.cs
- DictionaryEntry.cs
- Sentence.cs
- ProcessManager.cs
- ColumnCollectionEditor.cs
- DrawingGroup.cs
- CryptoProvider.cs
- EntitySqlException.cs
- SrgsSubset.cs
- UriParserTemplates.cs
- BaseCollection.cs
- SqlDataSourceView.cs
- AxHost.cs
- XmlConvert.cs
- ArrayConverter.cs
- PtsHost.cs
- MessageHeaderException.cs
- PointLight.cs
- XamlSerializerUtil.cs
- XmlCharCheckingWriter.cs
- PreloadedPackages.cs
- FixedStringLookup.cs
- XPathNavigatorKeyComparer.cs
- MailAddressCollection.cs
- CombinedGeometry.cs
- SmiEventStream.cs
- DictionaryEntry.cs
- ControlIdConverter.cs
- EdmItemCollection.OcAssemblyCache.cs
- Int64Storage.cs
- WarningException.cs
- TextTreeRootNode.cs
- WinInet.cs
- Publisher.cs
- CreateUserWizardStep.cs
- PageContentCollection.cs
- _ListenerRequestStream.cs
- DeferredReference.cs
- InstanceLockedException.cs
- ExtensibleSyndicationObject.cs
- PerformanceCounterLib.cs
- ModelFunctionTypeElement.cs
- RoutingUtilities.cs
- ProtocolsConfiguration.cs
- RegistryPermission.cs
- formatter.cs
- FormsAuthenticationUserCollection.cs
- PersistenceMetadataNamespace.cs
- SecureEnvironment.cs
- SymbolEqualComparer.cs
- HttpCacheParams.cs
- AssemblyInfo.cs
- TextRunProperties.cs
- SpeakInfo.cs
- Vector3DCollectionValueSerializer.cs
- ResourcePool.cs
- FontNameEditor.cs
- MenuItemBindingCollection.cs
- GACMembershipCondition.cs
- HostedHttpTransportManager.cs
- SoapExtensionReflector.cs
- JobInputBins.cs
- StreamAsIStream.cs
- ToolStripDropDownMenu.cs
- TextureBrush.cs
- PolyQuadraticBezierSegmentFigureLogic.cs
- OleDbParameter.cs