Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / MaxMessageSizeStream.cs / 1 / MaxMessageSizeStream.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Channels { using System.IO; using System.ServiceModel; using System.Diagnostics; class MaxMessageSizeStream : DelegatingStream { long maxMessageSize; long totalBytesRead; long bytesWritten; public MaxMessageSizeStream(Stream stream, long maxMessageSize) : base(stream) { this.maxMessageSize = maxMessageSize; } public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { count = PrepareRead(count); return base.BeginRead(buffer, offset, count, callback, state); } public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { PrepareWrite(count); return base.BeginWrite(buffer, offset, count, callback, state); } public override int EndRead(IAsyncResult result) { return FinishRead(base.EndRead(result)); } public override int Read(byte[] buffer, int offset, int count) { count = PrepareRead(count); return FinishRead(base.Read(buffer, offset, count)); } public override int ReadByte() { PrepareRead(1); int i = base.ReadByte(); if (i != -1) FinishRead(1); return i; } public override void Write(byte[] buffer, int offset, int count) { PrepareWrite(count); base.Write(buffer, offset, count); } public override void WriteByte(byte value) { PrepareWrite(1); base.WriteByte(value); } internal static Exception CreateMaxReceivedMessageSizeExceededException(long maxMessageSize) { string message = SR.GetString(SR.MaxReceivedMessageSizeExceeded, maxMessageSize); Exception inner = new QuotaExceededException(message); return new CommunicationException(message, inner); } internal static Exception CreateMaxSentMessageSizeExceededException(long maxMessageSize) { string message = SR.GetString(SR.MaxSentMessageSizeExceeded, maxMessageSize); Exception inner = new QuotaExceededException(message); return new CommunicationException(message, inner); } int PrepareRead(int bytesToRead) { if (totalBytesRead >= maxMessageSize) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateMaxReceivedMessageSizeExceededException(maxMessageSize)); } long bytesRemaining = maxMessageSize - totalBytesRead; if (bytesRemaining > int.MaxValue) { return bytesToRead; } else { return Math.Min(bytesToRead, (int)(maxMessageSize - totalBytesRead)); } } int FinishRead(int bytesRead) { totalBytesRead += bytesRead; return bytesRead; } void PrepareWrite(int bytesToWrite) { if (bytesWritten + bytesToWrite > maxMessageSize) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateMaxSentMessageSizeExceededException(maxMessageSize)); } bytesWritten += bytesToWrite; } } } // 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
- GridViewCommandEventArgs.cs
- DesignerActionUIService.cs
- InputScopeAttribute.cs
- RenderCapability.cs
- DistributedTransactionPermission.cs
- AuthenticationConfig.cs
- BaseTemplatedMobileComponentEditor.cs
- NameValueCache.cs
- SQLMoney.cs
- SafeSecurityHelper.cs
- CatalogZone.cs
- Timer.cs
- ValueTypeFixupInfo.cs
- DriveNotFoundException.cs
- SystemColorTracker.cs
- HwndTarget.cs
- DoubleLinkList.cs
- QueryCoreOp.cs
- TranslateTransform3D.cs
- PublisherIdentityPermission.cs
- IntPtr.cs
- ClientApiGenerator.cs
- CellParaClient.cs
- XmlEntity.cs
- CTreeGenerator.cs
- TextProperties.cs
- ServiceOperation.cs
- XmlSchemas.cs
- WebBrowser.cs
- FilterableAttribute.cs
- WsatEtwTraceListener.cs
- CompositeTypefaceMetrics.cs
- Lasso.cs
- ADConnectionHelper.cs
- SocketStream.cs
- Imaging.cs
- ListBox.cs
- DataIdProcessor.cs
- PlatformCulture.cs
- ConstantSlot.cs
- BufferedWebEventProvider.cs
- SqlSupersetValidator.cs
- BindingSource.cs
- WebException.cs
- HttpModuleAction.cs
- SSmlParser.cs
- CreateParams.cs
- TreeBuilderBamlTranslator.cs
- PropertyKey.cs
- GenericTypeParameterBuilder.cs
- Validator.cs
- ToolboxItemAttribute.cs
- SplitterEvent.cs
- DirectionalLight.cs
- SettingsAttributeDictionary.cs
- TextBox.cs
- FormsAuthenticationTicket.cs
- LinkButton.cs
- InputBinding.cs
- EmptyStringExpandableObjectConverter.cs
- Accessible.cs
- HotCommands.cs
- GradientStopCollection.cs
- CodeExpressionStatement.cs
- PackageRelationshipCollection.cs
- SmiEventStream.cs
- WindowsIdentity.cs
- MachineSettingsSection.cs
- ScriptControlDescriptor.cs
- KeyPressEvent.cs
- QilDataSource.cs
- BookmarkList.cs
- ConnectionsZone.cs
- FlowDocumentFormatter.cs
- GridViewItemAutomationPeer.cs
- FixedPageProcessor.cs
- GregorianCalendarHelper.cs
- ResourceIDHelper.cs
- ButtonColumn.cs
- NestPullup.cs
- ExternalFile.cs
- WindowsGraphics2.cs
- CalculatedColumn.cs
- iisPickupDirectory.cs
- EditBehavior.cs
- AnyAllSearchOperator.cs
- CatalogZone.cs
- WebPartsPersonalizationAuthorization.cs
- MaterialCollection.cs
- mediaeventshelper.cs
- ReadContentAsBinaryHelper.cs
- ForEachAction.cs
- CompressedStack.cs
- HttpRequest.cs
- DataObjectAttribute.cs
- TextEffectCollection.cs
- IdentityValidationException.cs
- ConfigurationManagerHelperFactory.cs
- _ListenerResponseStream.cs
- DBSchemaRow.cs