Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / ServiceModel / Channels / HttpStreamMessageEncoderFactory.cs / 1 / 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 (BufferedOutputStream stream = new BufferedOutputStream(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 (BufferedOutputStream stream = new BufferedOutputStream(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. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- BaseCodeDomTreeGenerator.cs
- XPathNodeHelper.cs
- IgnoreDataMemberAttribute.cs
- ValidationErrorCollection.cs
- EventProviderWriter.cs
- PropertyChangeTracker.cs
- CodeTypeReferenceExpression.cs
- OrderPreservingPipeliningSpoolingTask.cs
- SqlInternalConnectionSmi.cs
- DoubleCollectionValueSerializer.cs
- TypedReference.cs
- BindingMemberInfo.cs
- RequestStatusBarUpdateEventArgs.cs
- Size.cs
- BoundColumn.cs
- PeerInputChannelListener.cs
- PointAnimationUsingKeyFrames.cs
- CodePageUtils.cs
- TimelineGroup.cs
- VBCodeProvider.cs
- StreamInfo.cs
- WebPartZone.cs
- ToolboxItemAttribute.cs
- XmlStringTable.cs
- PointHitTestResult.cs
- Transactions.cs
- QilFunction.cs
- x509store.cs
- OrthographicCamera.cs
- SqlFlattener.cs
- ProviderCollection.cs
- DbConnectionPoolOptions.cs
- sqlpipe.cs
- EntitySetBaseCollection.cs
- HtmlLink.cs
- TypeLoadException.cs
- RadioButtonBaseAdapter.cs
- RelationshipNavigation.cs
- MarkupCompilePass2.cs
- ClientTargetCollection.cs
- SHA512.cs
- Message.cs
- PathSegment.cs
- CodeBlockBuilder.cs
- MatrixAnimationUsingPath.cs
- TimeStampChecker.cs
- ServicePointManagerElement.cs
- ScrollEvent.cs
- MetaData.cs
- VirtualPathProvider.cs
- KeySplineConverter.cs
- SelectionPatternIdentifiers.cs
- AliasedSlot.cs
- CheckBoxBaseAdapter.cs
- BCLDebug.cs
- DataGridViewComboBoxCell.cs
- BuildResultCache.cs
- BooleanSwitch.cs
- ThrowOnMultipleAssignment.cs
- ExtensionSurface.cs
- WebResourceUtil.cs
- Span.cs
- MouseEventArgs.cs
- XsdCachingReader.cs
- MemberExpression.cs
- XAMLParseException.cs
- TextTreeTextNode.cs
- DropSourceBehavior.cs
- ConfigXmlDocument.cs
- RawStylusInputReport.cs
- SqlClientMetaDataCollectionNames.cs
- TextEmbeddedObject.cs
- TextEffect.cs
- _ShellExpression.cs
- PageTextBox.cs
- DataView.cs
- CellParagraph.cs
- SQLResource.cs
- RegexBoyerMoore.cs
- TextSegment.cs
- InlineCollection.cs
- HTMLTextWriter.cs
- CancellationHandler.cs
- MouseBinding.cs
- WindowsRebar.cs
- HttpListenerRequestTraceRecord.cs
- SmiContext.cs
- StylusPointPropertyInfoDefaults.cs
- HierarchicalDataTemplate.cs
- DBSchemaRow.cs
- AddingNewEventArgs.cs
- NumericUpDown.cs
- BooleanFacetDescriptionElement.cs
- DrawItemEvent.cs
- BaseTypeViewSchema.cs
- ListDesigner.cs
- ShimAsPublicXamlType.cs
- DbParameterCollectionHelper.cs
- GacUtil.cs
- TimeoutException.cs