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
- EdmRelationshipNavigationPropertyAttribute.cs
- IndentTextWriter.cs
- ByteAnimationBase.cs
- Pkcs7Signer.cs
- MailHeaderInfo.cs
- StorageBasedPackageProperties.cs
- HttpHandlersSection.cs
- CreateParams.cs
- DataRelation.cs
- GZipStream.cs
- DataTable.cs
- Label.cs
- FontCacheLogic.cs
- AppModelKnownContentFactory.cs
- HtmlWindowCollection.cs
- IsolatedStorageException.cs
- RequestCachePolicyConverter.cs
- TreeSet.cs
- BitmapMetadataBlob.cs
- DesignerCategoryAttribute.cs
- ByteBufferPool.cs
- BackgroundWorker.cs
- cryptoapiTransform.cs
- ListParaClient.cs
- FontWeights.cs
- UxThemeWrapper.cs
- IdnElement.cs
- HeaderCollection.cs
- XmlElementList.cs
- PasswordDeriveBytes.cs
- DSASignatureDeformatter.cs
- InstanceData.cs
- JsonReaderWriterFactory.cs
- DoubleKeyFrameCollection.cs
- StrokeRenderer.cs
- ClientTargetSection.cs
- TrailingSpaceComparer.cs
- Translator.cs
- XmlKeywords.cs
- SimpleMailWebEventProvider.cs
- DetailsView.cs
- Internal.cs
- AgileSafeNativeMemoryHandle.cs
- ControlType.cs
- ObfuscationAttribute.cs
- FileVersionInfo.cs
- SegmentInfo.cs
- ControlParameter.cs
- RegisteredScript.cs
- PenLineCapValidation.cs
- MetadataPropertyvalue.cs
- WebControlAdapter.cs
- Evidence.cs
- _LocalDataStoreMgr.cs
- ClientSideProviderDescription.cs
- ComponentResourceManager.cs
- FlowNode.cs
- FilePresentation.cs
- thaishape.cs
- TemplateComponentConnector.cs
- Rule.cs
- XmlEncodedRawTextWriter.cs
- PackagePartCollection.cs
- KnownTypes.cs
- CodeArgumentReferenceExpression.cs
- WebConfigurationHostFileChange.cs
- InternalCache.cs
- DataGridItemCollection.cs
- SelfSignedCertificate.cs
- SafeCryptContextHandle.cs
- ObfuscationAttribute.cs
- RoleProviderPrincipal.cs
- UserControlBuildProvider.cs
- DeferredSelectedIndexReference.cs
- SnapLine.cs
- XmlReaderSettings.cs
- Ref.cs
- ColorDialog.cs
- NativeMethods.cs
- EntryPointNotFoundException.cs
- SmiRequestExecutor.cs
- ComboBox.cs
- TransformGroup.cs
- RegexMatch.cs
- SafeFileMappingHandle.cs
- XmlSerializerAssemblyAttribute.cs
- TextCompositionManager.cs
- LongPath.cs
- GroupAggregateExpr.cs
- ConfigurationLocation.cs
- DynamicRenderer.cs
- TextBoxBase.cs
- ExpressionBuilderContext.cs
- PackageDigitalSignatureManager.cs
- TypeDependencyAttribute.cs
- WhitespaceRuleReader.cs
- SyntaxCheck.cs
- AttachedPropertyBrowsableWhenAttributePresentAttribute.cs
- TypeForwardedFromAttribute.cs
- ImportCatalogPart.cs