Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Description / TypedMessageConverter.cs / 1 / TypedMessageConverter.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Description { using System; using System.ServiceModel.Channels; using System.ServiceModel.Dispatcher; using System.ServiceModel; using System.Runtime.Serialization; using System.Collections; using System.Diagnostics; public abstract class TypedMessageConverter { public static TypedMessageConverter Create(Type messageContract, string action) { return Create(messageContract, action, null, TypeLoader.DefaultDataContractFormatAttribute); } public static TypedMessageConverter Create(Type messageContract, string action, string defaultNamespace) { return Create(messageContract, action, defaultNamespace, TypeLoader.DefaultDataContractFormatAttribute); } public static TypedMessageConverter Create(Type messageContract, string action, XmlSerializerFormatAttribute formatterAttribute) { return Create(messageContract, action, null, formatterAttribute); } public static TypedMessageConverter Create(Type messageContract, string action, DataContractFormatAttribute formatterAttribute) { return Create(messageContract, action, null, formatterAttribute); } public static TypedMessageConverter Create(Type messageContract, String action, String defaultNamespace, XmlSerializerFormatAttribute formatterAttribute) { if (messageContract == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("messageContract")); if (defaultNamespace == null) defaultNamespace = NamingHelper.DefaultNamespace; return new XmlMessageConverter(GetOperationFormatter(messageContract, formatterAttribute, defaultNamespace, action)); } public static TypedMessageConverter Create(Type messageContract, String action, String defaultNamespace, DataContractFormatAttribute formatterAttribute) { if (messageContract == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("messageContract")); if (!messageContract.IsDefined(typeof(MessageContractAttribute), false)) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.SFxMessageContractAttributeRequired, messageContract), "messageContract")); if (defaultNamespace == null) defaultNamespace = NamingHelper.DefaultNamespace; return new XmlMessageConverter(GetOperationFormatter(messageContract, formatterAttribute, defaultNamespace, action)); } public abstract Message ToMessage(Object typedMessage); public abstract Message ToMessage(Object typedMessage, MessageVersion version); public abstract Object FromMessage(Message message); static OperationFormatter GetOperationFormatter(Type t, Attribute formatAttribute, string defaultNS, string action) { bool isXmlSerializer = (formatAttribute is XmlSerializerFormatAttribute); TypeLoader typeLoader = new TypeLoader(); MessageDescription message = typeLoader.CreateTypedMessageDescription(t, null, null, defaultNS, action, MessageDirection.Output); ContractDescription contract = new ContractDescription("dummy_contract", defaultNS); OperationDescription operation = new OperationDescription(NamingHelper.XmlName(t.Name), contract, false); operation.Messages.Add(message); if (isXmlSerializer) return XmlSerializerOperationBehavior.CreateOperationFormatter(operation, (XmlSerializerFormatAttribute)formatAttribute); else return new DataContractSerializerOperationFormatter(operation, (DataContractFormatAttribute)formatAttribute, null); } } internal class XmlMessageConverter : TypedMessageConverter { OperationFormatter formatter; internal XmlMessageConverter(OperationFormatter formatter) { this.formatter = formatter; } internal string Action { get { return formatter.RequestAction; } } public override Message ToMessage(Object typedMessage) { return ToMessage(typedMessage, MessageVersion.Soap12WSAddressing10); } public override Message ToMessage(Object typedMessage, MessageVersion version) { if (typedMessage == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("typedMessage")); return formatter.SerializeRequest(version, new object[] { typedMessage }); } public override Object FromMessage(Message message) { DiagnosticUtility.DebugAssert(message.Headers != null, ""); if (this.Action != null && message.Headers.Action != null && message.Headers.Action != this.Action) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxActionMismatch, this.Action, message.Headers.Action))); object[] result = new object[1]; formatter.DeserializeRequest(message, result); return result[0]; } } } // 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
- BitmapSource.cs
- WeakReadOnlyCollection.cs
- TraceSwitch.cs
- XmlNullResolver.cs
- ListViewSortEventArgs.cs
- CommonDialog.cs
- ItemDragEvent.cs
- __ComObject.cs
- TemplatedMailWebEventProvider.cs
- StaticResourceExtension.cs
- BaseValidator.cs
- EastAsianLunisolarCalendar.cs
- RemoteTokenFactory.cs
- VariantWrapper.cs
- InitialServerConnectionReader.cs
- PageStatePersister.cs
- OuterGlowBitmapEffect.cs
- InputLanguageProfileNotifySink.cs
- SchemaInfo.cs
- ManualResetEventSlim.cs
- GorillaCodec.cs
- RealizationDrawingContextWalker.cs
- EventProviderTraceListener.cs
- UnmanagedMemoryStream.cs
- RadioButtonPopupAdapter.cs
- __Filters.cs
- ExpressionWriter.cs
- CodePageUtils.cs
- SuppressIldasmAttribute.cs
- AccessText.cs
- TextBoxDesigner.cs
- RequestCachingSection.cs
- ClientUIRequest.cs
- TcpConnectionPool.cs
- AutomationTextAttribute.cs
- MaskInputRejectedEventArgs.cs
- GenerateTemporaryTargetAssembly.cs
- ReferenceEqualityComparer.cs
- InstanceDescriptor.cs
- BaseAsyncResult.cs
- Effect.cs
- SetterBase.cs
- EntityViewGenerationAttribute.cs
- RC2.cs
- MetaForeignKeyColumn.cs
- TabControlEvent.cs
- XslVisitor.cs
- InternalSafeNativeMethods.cs
- TextElementCollectionHelper.cs
- PropertyMapper.cs
- HttpApplicationFactory.cs
- TransactionCache.cs
- ComponentRenameEvent.cs
- ModulesEntry.cs
- CacheRequest.cs
- ObjectToken.cs
- EventLogPropertySelector.cs
- TextEditorDragDrop.cs
- DebugViewWriter.cs
- Substitution.cs
- DateTimeStorage.cs
- RijndaelManaged.cs
- Control.cs
- PointCollection.cs
- BitmapDownload.cs
- AnnotationAdorner.cs
- ProgressBarBrushConverter.cs
- FilteredAttributeCollection.cs
- ADConnectionHelper.cs
- DesignTimeHTMLTextWriter.cs
- DispatchWrapper.cs
- RegistryPermission.cs
- FloatUtil.cs
- CachedFontFace.cs
- Int16Storage.cs
- OutputCacheProfile.cs
- WrappedDispatcherException.cs
- DesignerDataParameter.cs
- TemplatePropertyEntry.cs
- TypeCodeDomSerializer.cs
- SqlDependency.cs
- Geometry.cs
- TraceHelpers.cs
- PropertyEmitterBase.cs
- RowToParametersTransformer.cs
- SwitchExpression.cs
- PolyLineSegment.cs
- DataGridColumnHeader.cs
- NativeMethods.cs
- DataGridViewCell.cs
- ReadOnlyHierarchicalDataSourceView.cs
- DesignTimeVisibleAttribute.cs
- CreateUserWizard.cs
- ProviderSettings.cs
- CheckBoxFlatAdapter.cs
- XmlConvert.cs
- ObjectStateEntryOriginalDbUpdatableDataRecord.cs
- ErrorActivity.cs
- UnionCodeGroup.cs
- oledbmetadatacolumnnames.cs