Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / ServiceModel / Channels / HttpStreamMessageEncoderFactory.cs / 1305376 / HttpStreamMessageEncoderFactory.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Channels { using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Net; using System.Xml; using System.Text; using System.ServiceModel.Dispatcher; class HttpStreamMessageEncoderFactory : MessageEncoderFactory { HttpStreamMessageEncoder encoder; public HttpStreamMessageEncoderFactory(XmlDictionaryReaderQuotas quotas) { this.encoder = new HttpStreamMessageEncoder(quotas); } public override MessageEncoder Encoder { get { return this.encoder; } } public override MessageVersion MessageVersion { get { return MessageVersion.None; } } public override MessageEncoder CreateSessionEncoder() { return this.encoder; } internal class HttpStreamMessageEncoder : MessageEncoder { string maxReceivedMessageSizeExceededResourceString; string maxSentMessageSizeExceededResourceString; XmlDictionaryReaderQuotas quotas; public HttpStreamMessageEncoder(XmlDictionaryReaderQuotas quotas) { this.quotas = quotas; this.maxSentMessageSizeExceededResourceString = SR2.MaxSentMessageSizeExceeded; this.maxReceivedMessageSizeExceededResourceString = SR2.MaxReceivedMessageSizeExceeded; } public override string ContentType { get { return null; } } public override string MediaType { get { return null; } } public override MessageVersion MessageVersion { get { return MessageVersion.None; } } public override bool IsContentTypeSupported(string contentType) { return true; } public override Message ReadMessage(ArraySegmentbuffer, BufferManager bufferManager, string contentType) { if (bufferManager == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bufferManager"); } Message result; using (BufferManagerOutputStream stream = new BufferManagerOutputStream(maxReceivedMessageSizeExceededResourceString, 0, int.MaxValue, bufferManager)) { stream.Write(buffer.Array, 0, buffer.Count); result = ReadMessage(stream.ToMemoryStream(), int.MaxValue, contentType); bufferManager.ReturnBuffer(buffer.Array); return result; } } public override Message ReadMessage(Stream stream, int maxSizeOfHeaders, string contentType) { if (stream == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("stream"); } Message result = Message.CreateMessage(new HttpStreamXmlDictionaryReader(stream, this.quotas), maxSizeOfHeaders, MessageVersion.None); result.Properties.Encoder = this; return result; } public override void WriteMessage(Message message, Stream stream) { if (message == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message"); } if (stream == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("stream"); } message.Properties.Encoder = this; using (HttpStreamXmlDictionaryWriter writer = new HttpStreamXmlDictionaryWriter(stream)) { message.WriteMessage(writer); writer.Flush(); } } public override ArraySegment WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset) { if (message == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message"); } if (bufferManager == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bufferManager"); } if (maxMessageSize < 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("maxMessageSize")); } using (BufferManagerOutputStream stream = new BufferManagerOutputStream(this.maxSentMessageSizeExceededResourceString, 0, maxMessageSize, bufferManager)) { stream.Skip(messageOffset); WriteMessage(message, stream); int size; byte[] buffer = stream.ToArray(out size); return new ArraySegment (buffer, 0, size - messageOffset); } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AutomationIdentifierGuids.cs
- CompleteWizardStep.cs
- XPathNodePointer.cs
- StyleCollection.cs
- RootBrowserWindowAutomationPeer.cs
- BufferBuilder.cs
- WebPartDisplayModeEventArgs.cs
- WebCodeGenerator.cs
- ThreadExceptionDialog.cs
- ProtocolInformationReader.cs
- KnownBoxes.cs
- TypeConstant.cs
- SQLInt32.cs
- BuildProviderAppliesToAttribute.cs
- ToolStripEditorManager.cs
- SettingsPropertyValueCollection.cs
- QueryPageSettingsEventArgs.cs
- FontDriver.cs
- SystemTcpStatistics.cs
- XmlUtilWriter.cs
- SamlAudienceRestrictionCondition.cs
- Viewport2DVisual3D.cs
- StylusButton.cs
- RightNameExpirationInfoPair.cs
- DBConcurrencyException.cs
- OleDbConnectionPoolGroupProviderInfo.cs
- ConfigurationSectionGroupCollection.cs
- CollectionViewGroupInternal.cs
- TriState.cs
- Drawing.cs
- DataPointer.cs
- BidOverLoads.cs
- SqlWebEventProvider.cs
- OletxTransactionFormatter.cs
- GlobalItem.cs
- ProfileModule.cs
- Transform3DCollection.cs
- TextProperties.cs
- ResourceContainer.cs
- TagMapInfo.cs
- XmlNamespaceManager.cs
- XmlEventCache.cs
- DataSourceView.cs
- AttachmentService.cs
- ACE.cs
- EmbeddedMailObjectsCollection.cs
- UrlMappingCollection.cs
- InkCanvasSelectionAdorner.cs
- FixedSOMTableCell.cs
- DataGridSortCommandEventArgs.cs
- TileModeValidation.cs
- PersistenceTypeAttribute.cs
- StructuralType.cs
- PersonalizationAdministration.cs
- BamlResourceDeserializer.cs
- KnownTypes.cs
- FreezableCollection.cs
- AddInIpcChannel.cs
- ReadOnlyObservableCollection.cs
- Compress.cs
- CqlErrorHelper.cs
- JoinCqlBlock.cs
- ByteAnimation.cs
- IndentedWriter.cs
- AppearanceEditorPart.cs
- CacheChildrenQuery.cs
- DrawToolTipEventArgs.cs
- Registry.cs
- ContentFileHelper.cs
- XmlTextReaderImplHelpers.cs
- OletxDependentTransaction.cs
- FontUnit.cs
- ExpandCollapseProviderWrapper.cs
- DomNameTable.cs
- MetafileHeader.cs
- VerificationException.cs
- InkCanvasFeedbackAdorner.cs
- MenuScrollingVisibilityConverter.cs
- DrawingAttributeSerializer.cs
- SqlRecordBuffer.cs
- SmiXetterAccessMap.cs
- SymbolEqualComparer.cs
- ColorAnimation.cs
- ConfigurationValidatorAttribute.cs
- Compiler.cs
- SystemIcmpV6Statistics.cs
- TableCellCollection.cs
- ValidatedMobileControlConverter.cs
- TargetInvocationException.cs
- _DomainName.cs
- ProtocolsSection.cs
- AuthenticatedStream.cs
- PrintingPermission.cs
- MatrixAnimationUsingKeyFrames.cs
- _BasicClient.cs
- LogExtent.cs
- Bits.cs
- RightsManagementLicense.cs
- Vector3DCollection.cs
- EntityModelBuildProvider.cs