Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Dispatcher / EndpointAddressMessageFilter.cs / 1 / EndpointAddressMessageFilter.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel.Dispatcher { using System; using System.ServiceModel.Channels; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.ServiceModel.Security; using System.Text; using System.Xml; using QName = System.ServiceModel.Dispatcher.EndpointAddressProcessor.QName; using HeaderBit = System.ServiceModel.Dispatcher.EndpointAddressProcessor.HeaderBit; public class EndpointAddressMessageFilter : MessageFilter { EndpointAddress address; bool includeHostNameInComparison; EndpointAddressMessageFilterHelper helper; EqualityComparercomparer; public EndpointAddressMessageFilter(EndpointAddress address) : this(address, false) { } public EndpointAddressMessageFilter(EndpointAddress address, bool includeHostNameInComparison) { if (address == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("address"); } this.address = address; this.includeHostNameInComparison = includeHostNameInComparison; this.helper = new EndpointAddressMessageFilterHelper(this.address); if (includeHostNameInComparison) { this.comparer = HostUriComparer.Value; } else { this.comparer = NoHostUriComparer.Value; } } public EndpointAddress Address { get { return this.address; } } public bool IncludeHostNameInComparison { get { return this.includeHostNameInComparison; } } protected internal override IMessageFilterTable CreateFilterTable () { return new EndpointAddressMessageFilterTable (); } public override bool Match(MessageBuffer messageBuffer) { if (messageBuffer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("messageBuffer"); } Message msg = messageBuffer.CreateMessage(); try { return Match(msg); } finally { msg.Close(); } } public override bool Match(Message message) { if (message == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message"); } // To #pragma warning suppress 56506 // [....], Message.Headers can never be null Uri to = message.Headers.To; Uri actingAs = this.address.Uri; if (to == null || !this.comparer.Equals(actingAs, to)) { return false; } return this.helper.Match(message); } internal Dictionary HeaderLookup { get { return this.helper.HeaderLookup; } } internal abstract class UriComparer : EqualityComparer { protected UriComparer() { } protected abstract bool CompareHost { get; } public override bool Equals(Uri u1, Uri u2) { return EndpointAddress.UriEquals(u1, u2, true /* ignoreCase */, CompareHost); } public override int GetHashCode(Uri uri) { return EndpointAddress.UriGetHashCode(uri, CompareHost); } } internal sealed class HostUriComparer : UriComparer { internal static readonly EqualityComparer Value = new HostUriComparer(); HostUriComparer() { } protected override bool CompareHost { get { return true; } } } internal sealed class NoHostUriComparer : UriComparer { internal static readonly EqualityComparer Value = new NoHostUriComparer(); NoHostUriComparer() { } protected override bool CompareHost { get { return false; } } } } internal class EndpointAddressMessageFilterHelper { EndpointAddress address; WeakReference processorPool; int size; byte[] mask; Dictionary qnameLookup; Dictionary headerLookup; internal EndpointAddressMessageFilterHelper(EndpointAddress address) { this.address = address; if (this.address.Headers.Count > 0) { CreateMask(); this.processorPool = new WeakReference(null); } else { this.qnameLookup = null; this.headerLookup = null; this.size = 0; this.mask = null; } } void CreateMask() { int nextBit = 0; string key; HeaderBit[] bits; QName qname; this.qnameLookup = new Dictionary (EndpointAddressProcessor.QNameComparer); this.headerLookup = new Dictionary (); StringBuilder builder = null; for (int i = 0; i < this.address.Headers.Count; ++i) { if (builder == null) builder = new StringBuilder(); else builder.Remove(0, builder.Length); key = this.address.Headers[i].GetComparableForm(builder); if (this.headerLookup.TryGetValue(key, out bits)) { Array.Resize(ref bits, bits.Length + 1); bits[bits.Length - 1] = new HeaderBit(nextBit++); this.headerLookup[key] = bits; } else { this.headerLookup.Add(key, new HeaderBit[] { new HeaderBit(nextBit++) }); AddressHeader parameter = this.address.Headers[i]; qname.name = parameter.Name; qname.ns = parameter.Namespace; this.qnameLookup[qname] = 1; } } if (nextBit == 0) { this.size = 0; } else { this.size = (nextBit - 1) / 8 + 1; } if (this.size > 0) { this.mask = new byte[size]; for (int i = 0; i < this.size - 1; ++i) { this.mask[i] = 0xff; } if ((nextBit % 8) == 0) { this.mask[this.size - 1] = 0xff; } else { this.mask[this.size - 1] = (byte)((1 << (nextBit % 8)) - 1); } } } internal Dictionary HeaderLookup { get { if (this.headerLookup == null) this.headerLookup = new Dictionary (); return this.headerLookup; } } EndpointAddressProcessor CreateProcessor(int length) { if (this.processorPool.Target != null) { lock (this.processorPool) { object o = this.processorPool.Target; if (o != null) { EndpointAddressProcessor p = (EndpointAddressProcessor)o; this.processorPool.Target = p.Next; p.Next = null; p.Clear(length); return p; } } } return new EndpointAddressProcessor(length); } internal bool Match(Message message) { if (this.size == 0) { return true; } EndpointAddressProcessor context = CreateProcessor(this.size); context.ProcessHeaders(message, this.qnameLookup, this.headerLookup); bool result = context.TestExact(this.mask); ReleaseProcessor(context); return result; } void ReleaseProcessor(EndpointAddressProcessor context) { lock (this.processorPool) { context.Next = this.processorPool.Target as EndpointAddressProcessor; this.processorPool.Target = context; } } } } // 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
- Quaternion.cs
- CompilationUtil.cs
- ComNativeDescriptor.cs
- CharUnicodeInfo.cs
- DbProviderServices.cs
- SelectionRangeConverter.cs
- DocumentNUp.cs
- newinstructionaction.cs
- GeometryCombineModeValidation.cs
- XmlSchemaAttributeGroupRef.cs
- ExceptionTranslationTable.cs
- Unit.cs
- Screen.cs
- Pair.cs
- MissingMemberException.cs
- KeyConstraint.cs
- BufferModeSettings.cs
- XmlNavigatorFilter.cs
- MatrixAnimationBase.cs
- ipaddressinformationcollection.cs
- ButtonAutomationPeer.cs
- ColumnBinding.cs
- CodeCatchClauseCollection.cs
- MetadataSet.cs
- MemberProjectedSlot.cs
- List.cs
- SchemaEntity.cs
- PeerToPeerException.cs
- SystemInformation.cs
- IBuiltInEvidence.cs
- KeyPullup.cs
- SiteOfOriginContainer.cs
- propertyentry.cs
- HttpRawResponse.cs
- CodeCommentStatement.cs
- StructuralCache.cs
- HtmlContainerControl.cs
- DefaultMemberAttribute.cs
- DefaultValueAttribute.cs
- TransformCollection.cs
- AutomationTextAttribute.cs
- VariableExpressionConverter.cs
- PointF.cs
- CommandBindingCollection.cs
- COM2FontConverter.cs
- DispatcherFrame.cs
- ToggleProviderWrapper.cs
- MimeWriter.cs
- RegexCaptureCollection.cs
- XmlSchemaCompilationSettings.cs
- ComplexLine.cs
- ResourcePart.cs
- IgnoreFlushAndCloseStream.cs
- BitmapDownload.cs
- ProxyFragment.cs
- StylusCaptureWithinProperty.cs
- InkCanvasFeedbackAdorner.cs
- CodeAttributeArgument.cs
- _RegBlobWebProxyDataBuilder.cs
- InteropAutomationProvider.cs
- ReadOnlyHierarchicalDataSourceView.cs
- XmlName.cs
- QueryOperationResponseOfT.cs
- PresentationTraceSources.cs
- RangeValidator.cs
- ItemPager.cs
- GridViewDeletedEventArgs.cs
- UnsafeNativeMethodsPenimc.cs
- FrameworkElement.cs
- SparseMemoryStream.cs
- IdentityReference.cs
- PropertyValueUIItem.cs
- RadioButton.cs
- NopReturnReader.cs
- BamlMapTable.cs
- DbConnectionHelper.cs
- SecurityElement.cs
- ButtonBase.cs
- LineServicesRun.cs
- messageonlyhwndwrapper.cs
- SecurityPolicyVersion.cs
- TemplateControl.cs
- TextTreeObjectNode.cs
- ExeConfigurationFileMap.cs
- SourceItem.cs
- DataGridViewComboBoxEditingControl.cs
- GridLength.cs
- unsafenativemethodsother.cs
- ProtocolsConfigurationHandler.cs
- ColorConvertedBitmap.cs
- LinearGradientBrush.cs
- WarningException.cs
- Int32RectConverter.cs
- ProviderUtil.cs
- Rect3DConverter.cs
- InfiniteIntConverter.cs
- HtmlInputButton.cs
- ActivityCodeDomReferenceService.cs
- TreeViewEvent.cs
- MsmqChannelListenerBase.cs