Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.ServiceModel.Discovery / System / ServiceModel / Discovery / ServiceDiscoveryBehavior.cs / 1305376 / ServiceDiscoveryBehavior.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.ServiceModel.Discovery { using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics.CodeAnalysis; using System.Runtime; using System.ServiceModel.Channels; using System.ServiceModel.Description; using System.ServiceModel.Dispatcher; [Fx.Tag.XamlVisible(false)] public class ServiceDiscoveryBehavior : IServiceBehavior { NonNullItemCollectionannouncementEndpoints; public ServiceDiscoveryBehavior() { this.announcementEndpoints = new NonNullItemCollection (); } public Collection AnnouncementEndpoints { get { return this.announcementEndpoints; } } [SuppressMessage(FxCop.Category.Design, FxCop.Rule.InterfaceMethodsShouldBeCallableByChildTypes)] void IServiceBehavior.AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection endpoints, BindingParameterCollection bindingParameters) { } [SuppressMessage(FxCop.Category.Design, FxCop.Rule.InterfaceMethodsShouldBeCallableByChildTypes)] void IServiceBehavior.Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) { if (serviceDescription == null) { throw FxTrace.Exception.ArgumentNull("serviceDescription"); } if (serviceHostBase == null) { throw FxTrace.Exception.ArgumentNull("serviceHostBase"); } List appEndpoints = this.GetApplicationEndpoints(serviceDescription); DiscoveryServiceExtension discoveryServiceExtension = serviceHostBase.Extensions.Find (); if (discoveryServiceExtension == null) { if (serviceDescription.Endpoints.Count > appEndpoints.Count) { discoveryServiceExtension = new DefaultDiscoveryServiceExtension(DiscoveryDefaults.DuplicateMessageHistoryLength); } else { discoveryServiceExtension = new DefaultDiscoveryServiceExtension(0); } serviceHostBase.Extensions.Add(discoveryServiceExtension); } for (int i = 0; i < appEndpoints.Count; i++) { appEndpoints[i].Behaviors.Add( new EndpointDiscoveryMetadataInitializer( discoveryServiceExtension.InternalPublishedEndpoints)); } } [SuppressMessage(FxCop.Category.Design, FxCop.Rule.InterfaceMethodsShouldBeCallableByChildTypes)] void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) { if (serviceDescription == null) { throw FxTrace.Exception.ArgumentNull("serviceDescription"); } if (serviceHostBase == null) { throw FxTrace.Exception.ArgumentNull("serviceHostBase"); } DiscoveryServiceExtension discoveryServiceExtension = serviceHostBase.Extensions.Find (); if (discoveryServiceExtension != null) { DiscoveryService discoveryService = discoveryServiceExtension.ValidateAndGetDiscoveryService(); ServiceDiscoveryBehavior.SetDiscoveryImplementation(serviceHostBase, discoveryService); if (this.announcementEndpoints.Count > 0) { serviceHostBase.ChannelDispatchers.Add( new OnlineAnnouncementChannelDispatcher( serviceHostBase, this.announcementEndpoints, discoveryServiceExtension.InternalPublishedEndpoints, discoveryService.MessageSequenceGenerator)); serviceHostBase.ChannelDispatchers.Insert(0, new OfflineAnnouncementChannelDispatcher( serviceHostBase, this.announcementEndpoints, discoveryServiceExtension.InternalPublishedEndpoints, discoveryService.MessageSequenceGenerator)); } } } static void SetDiscoveryImplementation(ServiceHostBase host, DiscoveryService discoveryService) { foreach (ChannelDispatcherBase channelDispatcherBase in host.ChannelDispatchers) { ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher; if (channelDispatcher != null) { foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints) { if ((endpointDispatcher != null) && EndpointDiscoveryMetadata.IsDiscoverySystemEndpoint(endpointDispatcher)) { SetDiscoveryImplementation(endpointDispatcher, discoveryService); } } } } } static void SetDiscoveryImplementation(EndpointDispatcher endpointDispatcher, DiscoveryService discoveryService) { DispatchRuntime dispatchRuntime = endpointDispatcher.DispatchRuntime; dispatchRuntime.SynchronizationContext = null; dispatchRuntime.ConcurrencyMode = ConcurrencyMode.Multiple; ServiceDiscoveryInstanceContextProvider provider = new ServiceDiscoveryInstanceContextProvider(discoveryService); dispatchRuntime.InstanceContextProvider = provider; dispatchRuntime.InstanceProvider = provider; dispatchRuntime.Type = discoveryService.GetType(); } List GetApplicationEndpoints(ServiceDescription serviceDescription) { List appEndpoints = new List (serviceDescription.Endpoints.Count); foreach (ServiceEndpoint endpoint in serviceDescription.Endpoints) { if (!EndpointDiscoveryMetadata.IsDiscoverySystemEndpoint(endpoint)) { appEndpoints.Add(endpoint); } } return appEndpoints; } class EndpointDiscoveryMetadataInitializer : IEndpointBehavior { Collection publishedEndpointCollection; internal EndpointDiscoveryMetadataInitializer(Collection publishedEndpointCollection) { this.publishedEndpointCollection = publishedEndpointCollection; } void IEndpointBehavior.AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) { } void IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) { } void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) { EndpointDiscoveryMetadata endpointDiscoveryMetadata = EndpointDiscoveryMetadata.FromServiceEndpoint(endpoint, endpointDispatcher); if (endpointDiscoveryMetadata != null) { this.publishedEndpointCollection.Add(endpointDiscoveryMetadata); } } void IEndpointBehavior.Validate(ServiceEndpoint endpoint) { } } } } // 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
- SafeNativeMethods.cs
- EditableRegion.cs
- TypedElement.cs
- SettingsPropertyValueCollection.cs
- NavigationWindow.cs
- DesignerActionUIService.cs
- LabelEditEvent.cs
- WebPartDisplayModeCollection.cs
- LinqDataSourceUpdateEventArgs.cs
- MessageQueue.cs
- metrodevice.cs
- ResourceDescriptionAttribute.cs
- XmlValidatingReaderImpl.cs
- Soap11ServerProtocol.cs
- AsyncContentLoadedEventArgs.cs
- MessagePropertyVariants.cs
- input.cs
- StylusEventArgs.cs
- TreeViewAutomationPeer.cs
- Models.cs
- RegionInfo.cs
- DesignerInterfaces.cs
- UnmanagedMemoryStream.cs
- BrowsableAttribute.cs
- HttpContextWrapper.cs
- ParseElement.cs
- ColumnBinding.cs
- DesignerActionService.cs
- DataBindingExpressionBuilder.cs
- FilterQuery.cs
- ScalarRestriction.cs
- ConfigsHelper.cs
- DetailsViewDeletedEventArgs.cs
- ContextBase.cs
- ToolStripContainer.cs
- TaskFactory.cs
- UserControlBuildProvider.cs
- OdbcInfoMessageEvent.cs
- CustomAttributeFormatException.cs
- InputDevice.cs
- UriSection.cs
- OdbcFactory.cs
- DescendentsWalkerBase.cs
- KeyConverter.cs
- BrowserDefinition.cs
- GenericTypeParameterBuilder.cs
- XmlSchemaCompilationSettings.cs
- embossbitmapeffect.cs
- TransactionInformation.cs
- TextFormatterContext.cs
- TabControlCancelEvent.cs
- Converter.cs
- PointValueSerializer.cs
- RequestCachingSection.cs
- TreeNodeClickEventArgs.cs
- JpegBitmapEncoder.cs
- HitTestFilterBehavior.cs
- ImageSourceValueSerializer.cs
- FlowSwitch.cs
- DataControlCommands.cs
- BufferModesCollection.cs
- PasswordBoxAutomationPeer.cs
- ExpandSegment.cs
- GetPageNumberCompletedEventArgs.cs
- PeerNodeTraceRecord.cs
- TextWriter.cs
- Size3DConverter.cs
- FrameDimension.cs
- DecimalConstantAttribute.cs
- SimpleHandlerFactory.cs
- BoolExpr.cs
- ScaleTransform.cs
- EventLogPermissionEntry.cs
- ListViewInsertEventArgs.cs
- CalendarTable.cs
- SelectionUIService.cs
- VoiceSynthesis.cs
- SmtpNtlmAuthenticationModule.cs
- CodeRegionDirective.cs
- HandlerWithFactory.cs
- ConstructorArgumentAttribute.cs
- Interfaces.cs
- FactoryGenerator.cs
- ModifierKeysValueSerializer.cs
- ImportContext.cs
- UdpReplyToBehavior.cs
- AgileSafeNativeMemoryHandle.cs
- StrongNameUtility.cs
- BrowserDefinition.cs
- HighlightVisual.cs
- ApplicationServiceHelper.cs
- TabControl.cs
- MissingManifestResourceException.cs
- GridView.cs
- Queue.cs
- SqlRetyper.cs
- AudioBase.cs
- MatrixValueSerializer.cs
- HGlobalSafeHandle.cs
- PrintPreviewGraphics.cs