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
- XmlCountingReader.cs
- _TimerThread.cs
- safePerfProviderHandle.cs
- HandleRef.cs
- AutoCompleteStringCollection.cs
- WeakEventManager.cs
- UserControl.cs
- BufferedResponseStream.cs
- DependencyPropertyValueSerializer.cs
- RuleSetDialog.cs
- URI.cs
- DropShadowBitmapEffect.cs
- PathFigureCollectionValueSerializer.cs
- SchemaEntity.cs
- ThicknessAnimation.cs
- EndpointFilterProvider.cs
- XmlNodeReader.cs
- GraphicsState.cs
- ModelPropertyCollectionImpl.cs
- RegexStringValidator.cs
- AffineTransform3D.cs
- DisableDpiAwarenessAttribute.cs
- BaseTemplateBuildProvider.cs
- SmiEventSink.cs
- Ref.cs
- dbenumerator.cs
- MatrixKeyFrameCollection.cs
- DataBindingExpressionBuilder.cs
- EntitySqlQueryState.cs
- SqlGenericUtil.cs
- DataGridViewButtonCell.cs
- SqlTriggerContext.cs
- ObjectDataProvider.cs
- QuaternionAnimationBase.cs
- WmlControlAdapter.cs
- CommandField.cs
- TrustManager.cs
- WorkflowPageSetupDialog.cs
- NavigationExpr.cs
- Msec.cs
- WebServiceHandler.cs
- SupportingTokenListenerFactory.cs
- Activity.cs
- XmlDataDocument.cs
- MarkupExtensionReturnTypeAttribute.cs
- ObjectDataProvider.cs
- NativeActivityFaultContext.cs
- FontStretches.cs
- controlskin.cs
- MsmqProcessProtocolHandler.cs
- SafeMILHandleMemoryPressure.cs
- ScriptIgnoreAttribute.cs
- TextElementEnumerator.cs
- XmlSchemaInferenceException.cs
- RenderContext.cs
- ReferentialConstraint.cs
- WebBrowserDocumentCompletedEventHandler.cs
- NavigatingCancelEventArgs.cs
- WebEvents.cs
- SafeFileMapViewHandle.cs
- StoragePropertyMapping.cs
- RemotingSurrogateSelector.cs
- WhitespaceRuleReader.cs
- NativeCppClassAttribute.cs
- StorageEndPropertyMapping.cs
- WebRequestModuleElement.cs
- GeometryHitTestResult.cs
- ListManagerBindingsCollection.cs
- RefreshResponseInfo.cs
- LineGeometry.cs
- ViewUtilities.cs
- SystemResourceKey.cs
- XmlSchemaValidator.cs
- DynamicActivityXamlReader.cs
- Int64Storage.cs
- ProfileSettingsCollection.cs
- JsonCollectionDataContract.cs
- CodeAttributeDeclaration.cs
- PropertyMap.cs
- EditorZone.cs
- SerializationObjectManager.cs
- CultureTableRecord.cs
- ObjectStateManagerMetadata.cs
- TypeReference.cs
- DataRowView.cs
- TreeNodeBindingCollection.cs
- SchemaTypeEmitter.cs
- SHA1Managed.cs
- FileUpload.cs
- Hyperlink.cs
- WsdlInspector.cs
- DropSource.cs
- XmlValidatingReaderImpl.cs
- QueryCreatedEventArgs.cs
- RtfNavigator.cs
- Visual3D.cs
- _FtpDataStream.cs
- TextBoxView.cs
- SqlClientFactory.cs
- KeyPressEvent.cs