Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / System.ServiceModel.Activation / System / ServiceModel / Activation / ApplyHostConfigurationBehavior.cs / 1305376 / ApplyHostConfigurationBehavior.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel.Activation { using System.Collections.Generic; using System.Collections.ObjectModel; using System.ServiceModel; using System.ServiceModel.Description; using System.ServiceModel.Dispatcher; using System.ServiceModel.Channels; //This is the behavior is intended to auto apply IIS/AspNet configuration to WCF post design time class ApplyHostConfigurationBehavior : IServiceBehavior { internal ApplyHostConfigurationBehavior() { } void IServiceBehavior.Validate(ServiceDescription description, ServiceHostBase service) { if (service.Description.Endpoints != null && ServiceHostingEnvironment.MultipleSiteBindingsEnabled) { FailActivationIfEndpointsHaveAbsoluteAddress(service); } } void IServiceBehavior.AddBindingParameters(ServiceDescription description, ServiceHostBase service, Collectionendpoints, BindingParameterCollection parameters) { } void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase service) { if (ServiceHostingEnvironment.MultipleSiteBindingsEnabled) { SetEndpointAddressFilterToIgnorePort(service); } } void SetEndpointAddressFilterToIgnorePort(ServiceHostBase service) { for (int i = 0; i < service.ChannelDispatchers.Count; i++) { ChannelDispatcher channelDispatcher = service.ChannelDispatchers[i] as ChannelDispatcher; if (channelDispatcher != null) { if (IsSchemeHttpOrHttps(channelDispatcher.Listener.Uri.Scheme)) { for (int j = 0; j < channelDispatcher.Endpoints.Count; j++) { EndpointDispatcher endpointDispatcher = channelDispatcher.Endpoints[j]; EndpointAddressMessageFilter endpointAddressMessageFilter = endpointDispatcher.AddressFilter as EndpointAddressMessageFilter; if (endpointAddressMessageFilter != null) { endpointAddressMessageFilter.ComparePort = false; } } } } } } void FailActivationIfEndpointsHaveAbsoluteAddress(ServiceHostBase service) { foreach (ServiceEndpoint endpoint in service.Description.Endpoints) { if (IsSchemeHttpOrHttps(endpoint.Binding.Scheme)) { if (endpoint.UnresolvedListenUri != null) { ThrowIfAbsolute(endpoint.UnresolvedListenUri); } else { //If the listen URI is not null, we shouldn't care about address. Because there are //customers who have following config (for load balancer scenarios) - Note ExtraFolder and https //listen URI - http://localhost/App1/x.svc //Address - https://externalhost/ExtranFolder/App1/x.svc ThrowIfAbsolute(endpoint.UnresolvedAddress); } } } ServiceDebugBehavior debugBehavior = service.Description.Behaviors.Find (); if (debugBehavior != null) { if (debugBehavior.HttpHelpPageEnabled) { ThrowIfAbsolute(debugBehavior.HttpHelpPageUrl); } if (debugBehavior.HttpsHelpPageEnabled) { ThrowIfAbsolute(debugBehavior.HttpsHelpPageUrl); } } ServiceMetadataBehavior metadataBehavior = service.Description.Behaviors.Find (); if (metadataBehavior != null) { if (metadataBehavior.HttpGetEnabled) { ThrowIfAbsolute(metadataBehavior.HttpGetUrl); } if (metadataBehavior.HttpsGetEnabled) { ThrowIfAbsolute(metadataBehavior.HttpsGetUrl); } } } static void ThrowIfAbsolute(Uri uri) { if (uri != null && uri.IsAbsoluteUri) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.Hosting_SharedEndpointRequiresRelativeEndpoint(uri.ToString()))); } } static bool IsSchemeHttpOrHttps(string scheme) { return string.Compare(scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(scheme, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase) == 0; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel.Activation { using System.Collections.Generic; using System.Collections.ObjectModel; using System.ServiceModel; using System.ServiceModel.Description; using System.ServiceModel.Dispatcher; using System.ServiceModel.Channels; //This is the behavior is intended to auto apply IIS/AspNet configuration to WCF post design time class ApplyHostConfigurationBehavior : IServiceBehavior { internal ApplyHostConfigurationBehavior() { } void IServiceBehavior.Validate(ServiceDescription description, ServiceHostBase service) { if (service.Description.Endpoints != null && ServiceHostingEnvironment.MultipleSiteBindingsEnabled) { FailActivationIfEndpointsHaveAbsoluteAddress(service); } } void IServiceBehavior.AddBindingParameters(ServiceDescription description, ServiceHostBase service, Collection endpoints, BindingParameterCollection parameters) { } void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase service) { if (ServiceHostingEnvironment.MultipleSiteBindingsEnabled) { SetEndpointAddressFilterToIgnorePort(service); } } void SetEndpointAddressFilterToIgnorePort(ServiceHostBase service) { for (int i = 0; i < service.ChannelDispatchers.Count; i++) { ChannelDispatcher channelDispatcher = service.ChannelDispatchers[i] as ChannelDispatcher; if (channelDispatcher != null) { if (IsSchemeHttpOrHttps(channelDispatcher.Listener.Uri.Scheme)) { for (int j = 0; j < channelDispatcher.Endpoints.Count; j++) { EndpointDispatcher endpointDispatcher = channelDispatcher.Endpoints[j]; EndpointAddressMessageFilter endpointAddressMessageFilter = endpointDispatcher.AddressFilter as EndpointAddressMessageFilter; if (endpointAddressMessageFilter != null) { endpointAddressMessageFilter.ComparePort = false; } } } } } } void FailActivationIfEndpointsHaveAbsoluteAddress(ServiceHostBase service) { foreach (ServiceEndpoint endpoint in service.Description.Endpoints) { if (IsSchemeHttpOrHttps(endpoint.Binding.Scheme)) { if (endpoint.UnresolvedListenUri != null) { ThrowIfAbsolute(endpoint.UnresolvedListenUri); } else { //If the listen URI is not null, we shouldn't care about address. Because there are //customers who have following config (for load balancer scenarios) - Note ExtraFolder and https //listen URI - http://localhost/App1/x.svc //Address - https://externalhost/ExtranFolder/App1/x.svc ThrowIfAbsolute(endpoint.UnresolvedAddress); } } } ServiceDebugBehavior debugBehavior = service.Description.Behaviors.Find (); if (debugBehavior != null) { if (debugBehavior.HttpHelpPageEnabled) { ThrowIfAbsolute(debugBehavior.HttpHelpPageUrl); } if (debugBehavior.HttpsHelpPageEnabled) { ThrowIfAbsolute(debugBehavior.HttpsHelpPageUrl); } } ServiceMetadataBehavior metadataBehavior = service.Description.Behaviors.Find (); if (metadataBehavior != null) { if (metadataBehavior.HttpGetEnabled) { ThrowIfAbsolute(metadataBehavior.HttpGetUrl); } if (metadataBehavior.HttpsGetEnabled) { ThrowIfAbsolute(metadataBehavior.HttpsGetUrl); } } } static void ThrowIfAbsolute(Uri uri) { if (uri != null && uri.IsAbsoluteUri) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.Hosting_SharedEndpointRequiresRelativeEndpoint(uri.ToString()))); } } static bool IsSchemeHttpOrHttps(string scheme) { return string.Compare(scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(scheme, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase) == 0; } } } // 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
- iisPickupDirectory.cs
- TreeNodeMouseHoverEvent.cs
- x509utils.cs
- DataGridLinkButton.cs
- Regex.cs
- SendOperation.cs
- PointAnimationClockResource.cs
- MarkupWriter.cs
- MessageRpc.cs
- DbMetaDataFactory.cs
- IdleTimeoutMonitor.cs
- OneWayChannelListener.cs
- NameValueCollection.cs
- ServiceMetadataPublishingElement.cs
- CapacityStreamGeometryContext.cs
- KeyValueConfigurationElement.cs
- MenuAdapter.cs
- WebResourceAttribute.cs
- LowerCaseStringConverter.cs
- MimePart.cs
- ScriptResourceAttribute.cs
- Listbox.cs
- URLMembershipCondition.cs
- MaskedTextProvider.cs
- EpmSourcePathSegment.cs
- httpstaticobjectscollection.cs
- ProcessModuleCollection.cs
- ContractListAdapter.cs
- PngBitmapEncoder.cs
- ObjectViewQueryResultData.cs
- SamlAction.cs
- TerminatingOperationBehavior.cs
- GraphicsContext.cs
- NativeActivityAbortContext.cs
- EventProviderBase.cs
- EventLogPermissionEntry.cs
- CssTextWriter.cs
- ClientTarget.cs
- RSAOAEPKeyExchangeDeformatter.cs
- ViewSimplifier.cs
- DbProviderFactories.cs
- InstanceDataCollection.cs
- CheckBoxRenderer.cs
- MissingFieldException.cs
- ListViewItem.cs
- EntityDataSourceReferenceGroup.cs
- XmlSchemaSimpleTypeUnion.cs
- EncryptedKey.cs
- XmlChildEnumerator.cs
- TreeNodeBindingDepthConverter.cs
- FlowDocumentReaderAutomationPeer.cs
- SoapFaultCodes.cs
- SizeValueSerializer.cs
- BaseParaClient.cs
- ToolStripGripRenderEventArgs.cs
- RadioButtonFlatAdapter.cs
- AppDomain.cs
- IdentitySection.cs
- RoutedEventValueSerializer.cs
- Int32CAMarshaler.cs
- SystemParameters.cs
- DataGrid.cs
- ReversePositionQuery.cs
- OutOfMemoryException.cs
- DataRecordInternal.cs
- _LoggingObject.cs
- GraphicsState.cs
- WsatConfiguration.cs
- UnsettableComboBox.cs
- ConfigPathUtility.cs
- FontUnitConverter.cs
- NavigationHelper.cs
- RawTextInputReport.cs
- HandlerFactoryWrapper.cs
- ClientEventManager.cs
- SqlClientPermission.cs
- FixedPageStructure.cs
- ContentPresenter.cs
- EventLogger.cs
- CodeCompileUnit.cs
- ToolStripOverflow.cs
- AncestorChangedEventArgs.cs
- BitConverter.cs
- Margins.cs
- QilPatternVisitor.cs
- UniqueIdentifierService.cs
- Stackframe.cs
- SqlBulkCopyColumnMappingCollection.cs
- PropertyChangingEventArgs.cs
- RecordsAffectedEventArgs.cs
- ViewStateModeByIdAttribute.cs
- SqlComparer.cs
- DbDataReader.cs
- EventDescriptor.cs
- ThicknessConverter.cs
- UTF8Encoding.cs
- WebRequestModuleElement.cs
- lengthconverter.cs
- NetworkInformationException.cs
- JavascriptCallbackResponseProperty.cs