Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / ServiceModel / Dispatcher / ContentTypeSettingClientMessageFormatter.cs / 1 / ContentTypeSettingClientMessageFormatter.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.Dispatcher;
using System.ServiceModel.Web;
class ContentTypeSettingClientMessageFormatter : IClientMessageFormatter
{
IClientMessageFormatter innerFormatter;
string outgoingContentType;
public ContentTypeSettingClientMessageFormatter(string outgoingContentType, IClientMessageFormatter innerFormatter)
{
if (outgoingContentType == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("outgoingContentType");
}
if (innerFormatter == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("innerFormatter");
}
this.outgoingContentType = outgoingContentType;
this.innerFormatter = innerFormatter;
}
public object DeserializeReply(Message message, object[] parameters)
{
return this.innerFormatter.DeserializeReply(message, parameters);
}
public Message SerializeRequest(MessageVersion messageVersion, object[] parameters)
{
Message message = this.innerFormatter.SerializeRequest(messageVersion, parameters);
if (message != null)
{
AddRequestContentTypeProperty(message, this.outgoingContentType);
}
return message;
}
static void AddRequestContentTypeProperty(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.OutgoingRequest.ContentType))
{
WebOperationContext.Current.OutgoingRequest.ContentType = contentType;
}
}
else
{
object prop;
message.Properties.TryGetValue(HttpRequestMessageProperty.Name, out prop);
HttpRequestMessageProperty httpProperty;
if (prop != null)
{
httpProperty = (HttpRequestMessageProperty) prop;
}
else
{
httpProperty = new HttpRequestMessageProperty();
message.Properties.Add(HttpRequestMessageProperty.Name, httpProperty);
}
if (string.IsNullOrEmpty(httpProperty.Headers[HttpRequestHeader.ContentType]))
{
httpProperty.Headers[HttpRequestHeader.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
- TerminatorSinks.cs
- webeventbuffer.cs
- Processor.cs
- GenericPrincipal.cs
- DateTimeFormat.cs
- WindowInteropHelper.cs
- ActiveDocumentEvent.cs
- OledbConnectionStringbuilder.cs
- TextElementCollectionHelper.cs
- OlePropertyStructs.cs
- WebBrowserProgressChangedEventHandler.cs
- ParseElement.cs
- PreviewKeyDownEventArgs.cs
- XsdValidatingReader.cs
- EventSinkHelperWriter.cs
- NetPeerTcpBindingCollectionElement.cs
- HtmlTable.cs
- ListViewItem.cs
- WindowsStartMenu.cs
- SamlAssertionKeyIdentifierClause.cs
- UseAttributeSetsAction.cs
- Schema.cs
- SmtpDigestAuthenticationModule.cs
- VersionPair.cs
- GregorianCalendarHelper.cs
- Visual3DCollection.cs
- Brush.cs
- ContainerSelectorGlyph.cs
- PostBackOptions.cs
- FullTrustAssembly.cs
- JournalEntryStack.cs
- MediaCommands.cs
- SafeFileMappingHandle.cs
- IpcChannel.cs
- UpdateExpressionVisitor.cs
- UncommonField.cs
- ArgumentOutOfRangeException.cs
- MetadataImporterQuotas.cs
- AppDomainResourcePerfCounters.cs
- Visual.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- Subordinate.cs
- TimeSpanValidator.cs
- IsolatedStorageSecurityState.cs
- TextSerializer.cs
- HealthMonitoringSection.cs
- UnsafeNativeMethodsTablet.cs
- DataSvcMapFile.cs
- ToggleProviderWrapper.cs
- ProcessModule.cs
- SharedUtils.cs
- MimeWriter.cs
- UniqueCodeIdentifierScope.cs
- CommandManager.cs
- XmlDocumentType.cs
- ResourceExpression.cs
- RemotingException.cs
- PrePrepareMethodAttribute.cs
- WSIdentityFaultException.cs
- RIPEMD160Managed.cs
- Button.cs
- InputMethodStateTypeInfo.cs
- SoapAttributes.cs
- Parser.cs
- XmlDocumentFragment.cs
- VectorCollection.cs
- PermissionSetEnumerator.cs
- BinaryUtilClasses.cs
- RulePatternOps.cs
- PropertyExpression.cs
- HtmlInputReset.cs
- DataGridViewIntLinkedList.cs
- ElementHostPropertyMap.cs
- SQLBinaryStorage.cs
- DataGridViewElement.cs
- InstanceCreationEditor.cs
- TouchPoint.cs
- BlurEffect.cs
- ActivationServices.cs
- UserControlCodeDomTreeGenerator.cs
- PackUriHelper.cs
- StreamUpdate.cs
- FixedStringLookup.cs
- XmlSchemaValidationException.cs
- InputLanguageProfileNotifySink.cs
- SectionUpdates.cs
- ModulesEntry.cs
- DelimitedListTraceListener.cs
- DependentList.cs
- GridViewEditEventArgs.cs
- UniqueIdentifierService.cs
- NetworkAddressChange.cs
- MsmqBindingFilter.cs
- PersonalizationProviderCollection.cs
- CultureTable.cs
- QilReference.cs
- InputBinding.cs
- BitmapEffectInputConnector.cs
- EventLogPropertySelector.cs
- PersonalizationAdministration.cs