void IServiceBehavior.ApplyDispatchBehavior( ServiceDescription description, ServiceHostBase serviceHostBase) { ServiceMetadataExtension sme = ServiceMetadataExtension.EnsureServiceMetadataExtension(serviceHostBase); foreach (ChannelDispatcher dispatcher in serviceHostBase.ChannelDispatchers) { if (IncludeExceptionDetailInFaults) // may be set also in ServiceBehaviorAttribute { dispatcher.IncludeExceptionDetailInFaults = true; } } if (HttpHelpPageEnabled) { Uri uri = serviceHostBase.CreateUri("http", HttpHelpPageUrl); if (uri != null) { // FIXME: wrong. It should add help page sme.EnsureChannelDispatcher(false, "http", uri, HttpHelpPageBinding); } } if (HttpsHelpPageEnabled) { Uri uri = serviceHostBase.CreateUri("https", HttpsHelpPageUrl); if (uri != null) { // FIXME: wrong. It should add help page sme.EnsureChannelDispatcher(false, "https", uri, HttpsHelpPageBinding); } } }
void ApplyBehavior(ServiceDescription description, ServiceHostBase host) { ServiceMetadataExtension mex = ServiceMetadataExtension.EnsureServiceMetadataExtension(description, host); SetExtensionProperties(description, host, mex); CustomizeMetadataEndpoints(description, host, mex); CreateHttpGetEndpoints(description, host, mex); }
private void SetExtensionProperties(ServiceMetadataExtension mex, ServiceHostBase host) { mex.HttpHelpPageEnabled = this.httpHelpPageEnabled; mex.HttpHelpPageUrl = host.GetVia(Uri.UriSchemeHttp, (this.httpHelpPageUrl == null) ? new Uri(string.Empty, UriKind.Relative) : this.httpHelpPageUrl); mex.HttpHelpPageBinding = this.HttpHelpPageBinding; mex.HttpsHelpPageEnabled = this.httpsHelpPageEnabled; mex.HttpsHelpPageUrl = host.GetVia(Uri.UriSchemeHttps, (this.httpsHelpPageUrl == null) ? new Uri(string.Empty, UriKind.Relative) : this.httpsHelpPageUrl); mex.HttpsHelpPageBinding = this.HttpsHelpPageBinding; }
private bool EnsureHelpPageDispatcher(ServiceHostBase host, ServiceMetadataExtension mex, Uri url, string scheme) { Uri via = host.GetVia(scheme, (url == null) ? new Uri(string.Empty, UriKind.Relative) : url); if (via == null) { return(false); } ((ServiceMetadataExtension.HttpGetImpl)mex.EnsureGetDispatcher(via, 1).Endpoints[0].DispatchRuntime.SingletonInstanceContext.UserObject).HelpPageEnabled = true; return(true); }
internal static ServiceMetadataExtension EnsureServiceMetadataExtension(ServiceHostBase serviceHostBase) { ServiceMetadataExtension sme = serviceHostBase.Extensions.Find <ServiceMetadataExtension> (); if (sme == null) { sme = new ServiceMetadataExtension(); serviceHostBase.Extensions.Add(sme); } return(sme); }
void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase) { if (!(this.HttpGetEnabled || this.HttpsGetEnabled)) { return; } ServiceMetadataExtension mex = ServiceMetadataExtension.EnsureServiceMetadataExtension(description, serviceHostBase); CreateHealthEndpoints(description, serviceHostBase, mex); }
static bool EnsureGetDispatcher(ServiceHostBase host, ServiceMetadataExtension mex, Uri url, string scheme) { Uri address = host.GetVia(scheme, url == null ? new Uri(string.Empty, UriKind.Relative) : url); if (address != null) { ChannelDispatcher channelDispatcher = mex.EnsureGetDispatcher(address, false /* isServiceDebugBehavior */); ((ServiceMetadataExtension.HttpGetImpl)channelDispatcher.Endpoints[0].DispatchRuntime.SingletonInstanceContext.UserObject).GetWsdlEnabled = true; return(true); } return(false); }
private static void EnsureGetDispatcher(ServiceHostBase host, ServiceMetadataExtension mex, Uri url, string scheme) { Uri via = host.GetVia(scheme, (url == null) ? new Uri(string.Empty, UriKind.Relative) : url); if (via == null) { if (scheme == Uri.UriSchemeHttp) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxServiceMetadataBehaviorNoHttpBaseAddress"))); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxServiceMetadataBehaviorNoHttpsBaseAddress"))); } ((ServiceMetadataExtension.HttpGetImpl)mex.EnsureGetDispatcher(via, 0).Endpoints[0].DispatchRuntime.SingletonInstanceContext.UserObject).GetWsdlEnabled = true; }
private bool EnsureHealthDispatcher(ServiceHostBase host, ServiceMetadataExtension mex, Uri url, string scheme) { Uri address = host.GetVia(scheme, url == null ? new Uri(string.Empty, UriKind.Relative) : url); if (address == null) { return(false); } ChannelDispatcher channelDispatcher = EnsureGetDispatcher(host, mex, address); ((ServiceMetadataExtension.HttpGetImpl)channelDispatcher.Endpoints[0].DispatchRuntime.SingletonInstanceContext.UserObject).HealthBehavior = this; return(true); }
void IServiceBehavior.ApplyDispatchBehavior( ServiceDescription description, ServiceHostBase serviceHostBase) { ServiceMetadataExtension sme = ServiceMetadataExtension.EnsureServiceMetadataExtension(serviceHostBase); //Find ChannelDispatcher for Mex, and add a MexInstanceContextProvider //to it foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers) { ChannelDispatcher cd = cdb as ChannelDispatcher; if (cd == null) { continue; } foreach (EndpointDispatcher ed in cd.Endpoints) { if (ed.ContractName == MexContractName) { ed.DispatchRuntime.InstanceContextProvider = new MexInstanceContextProvider(serviceHostBase); } } } if (HttpGetEnabled) { Uri uri = serviceHostBase.CreateUri("http", HttpGetUrl); if (uri != null) { sme.EnsureChannelDispatcher(true, "http", uri, HttpGetBinding); } } if (HttpsGetEnabled) { Uri uri = serviceHostBase.CreateUri("https", HttpsGetUrl); if (uri != null) { sme.EnsureChannelDispatcher(true, "https", uri, HttpsGetBinding); } } }
void IServiceBehavior.ApplyDispatchBehavior(System.ServiceModel.Description.ServiceDescription description, ServiceHostBase serviceHostBase) { if (this.includeExceptionDetailInFaults) { for (int i = 0; i < serviceHostBase.ChannelDispatchers.Count; i++) { ChannelDispatcher dispatcher = serviceHostBase.ChannelDispatchers[i] as ChannelDispatcher; if (dispatcher != null) { dispatcher.IncludeExceptionDetailInFaults = true; } } } if (this.httpHelpPageEnabled || this.httpsHelpPageEnabled) { ServiceMetadataExtension mex = ServiceMetadataExtension.EnsureServiceMetadataExtension(description, serviceHostBase); this.SetExtensionProperties(mex, serviceHostBase); this.CreateHelpPageEndpoints(description, serviceHostBase, mex); } }
private ChannelDispatcher EnsureGetDispatcher(ServiceHostBase host, ServiceMetadataExtension mex, Uri listenUri) { const string ServiceHealthBehaviorHttpGetBinding = "ServiceHealthBehaviorHttpGetBinding"; ChannelDispatcher channelDispatcher = mex.FindGetDispatcher(listenUri); Binding binding; if (channelDispatcher == null) { if (listenUri.Scheme == Uri.UriSchemeHttp) { binding = this.HttpGetBinding ?? MetadataExchangeBindings.HttpGet; } else if (listenUri.Scheme == Uri.UriSchemeHttps) { binding = this.HttpsGetBinding ?? MetadataExchangeBindings.HttpsGet; } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.SFxGetChannelDispatcherDoesNotSupportScheme, nameof(ChannelDispatcher), Uri.UriSchemeHttp, Uri.UriSchemeHttps))); } channelDispatcher = mex.CreateGetDispatcher(listenUri, binding, ServiceHealthBehaviorHttpGetBinding); host.ChannelDispatchers.Add(channelDispatcher); } if (host.ServiceThrottle != null) { ServiceThrottle throttle = new ServiceThrottle(host); throttle.MaxConcurrentCalls = host.ServiceThrottle.Calls.Capacity; throttle.MaxConcurrentSessions = host.ServiceThrottle.Sessions.Capacity; throttle.MaxConcurrentInstances = host.ServiceThrottle.InstanceContexts.Capacity; channelDispatcher.ServiceThrottle = throttle; } channelDispatcher.IsServiceThrottleReplaced = true; return(channelDispatcher); }
void IServiceBehavior.ApplyDispatchBehavior( ServiceDescription description, ServiceHostBase serviceHostBase) { ServiceMetadataExtension sme = ServiceMetadataExtension.EnsureServiceMetadataExtension(serviceHostBase); foreach (var dispatcherBase in serviceHostBase.ChannelDispatchers) { var dispatcher = dispatcherBase as ChannelDispatcher; if (dispatcher == null) // non-ChannelDispatcher ChannelDispatcherBase instance. { continue; } if (IncludeExceptionDetailInFaults) // may be set also in ServiceBehaviorAttribute { dispatcher.IncludeExceptionDetailInFaults = true; } } if (HttpHelpPageEnabled) { Uri uri = serviceHostBase.CreateUri("http", HttpHelpPageUrl); if (uri != null) { sme.EnsureChannelDispatcher(false, "http", uri, HttpHelpPageBinding); } } if (HttpsHelpPageEnabled) { Uri uri = serviceHostBase.CreateUri("https", HttpsHelpPageUrl); if (uri != null) { sme.EnsureChannelDispatcher(false, "https", uri, HttpsHelpPageBinding); } } }
private void CreateHelpPageEndpoints(System.ServiceModel.Description.ServiceDescription description, ServiceHostBase host, ServiceMetadataExtension mex) { if (this.httpHelpPageEnabled && !this.EnsureHelpPageDispatcher(host, mex, this.httpHelpPageUrl, Uri.UriSchemeHttp)) { TraceWarning(this.httpHelpPageUrl, "ServiceDebugBehaviorHttpHelpPageUrl", "ServiceDebugBehaviorHttpHelpPageEnabled"); } if (this.httpsHelpPageEnabled && !this.EnsureHelpPageDispatcher(host, mex, this.httpsHelpPageUrl, Uri.UriSchemeHttps)) { TraceWarning(this.httpHelpPageUrl, "ServiceDebugBehaviorHttpsHelpPageUrl", "ServiceDebugBehaviorHttpsHelpPageEnabled"); } }
private void CreateHttpGetEndpoints(ServiceDescription description, ServiceHostBase host, ServiceMetadataExtension mex) { bool httpDispatcherEnabled = false; bool httpsDispatcherEnabled = false; if (this.httpGetEnabled) { httpDispatcherEnabled = EnsureGetDispatcher(host, mex, this.httpGetUrl, Uri.UriSchemeHttp); } if (this.httpsGetEnabled) { httpsDispatcherEnabled = EnsureGetDispatcher(host, mex, this.httpsGetUrl, Uri.UriSchemeHttps); } if (!httpDispatcherEnabled && !httpsDispatcherEnabled) { if (this.httpGetEnabled) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxServiceMetadataBehaviorNoHttpBaseAddress))); } if (this.httpsGetEnabled) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxServiceMetadataBehaviorNoHttpsBaseAddress))); } } }
public HttpGetWsdl(ServiceMetadataExtension ext) { this.ext = ext; }
void SetExtensionProperties(ServiceDescription description, ServiceHostBase host, ServiceMetadataExtension mex) { mex.ExternalMetadataLocation = this.ExternalMetadataLocation; mex.Initializer = new MetadataExtensionInitializer(this, description, host); mex.HttpGetEnabled = this.httpGetEnabled; mex.HttpsGetEnabled = this.httpsGetEnabled; mex.HttpGetUrl = host.GetVia(Uri.UriSchemeHttp, this.httpGetUrl == null ? new Uri(string.Empty, UriKind.Relative) : this.httpGetUrl); mex.HttpsGetUrl = host.GetVia(Uri.UriSchemeHttps, this.httpsGetUrl == null ? new Uri(string.Empty, UriKind.Relative) : this.httpsGetUrl); mex.HttpGetBinding = this.httpGetBinding; mex.HttpsGetBinding = this.httpsGetBinding; UseRequestHeadersForMetadataAddressBehavior dynamicUpdateBehavior = description.Behaviors.Find <UseRequestHeadersForMetadataAddressBehavior>(); if (dynamicUpdateBehavior != null) { mex.UpdateAddressDynamically = true; mex.UpdatePortsByScheme = new Dictionary <string, int>(dynamicUpdateBehavior.DefaultPortsByScheme); } foreach (ChannelDispatcherBase dispatcherBase in host.ChannelDispatchers) { ChannelDispatcher dispatcher = dispatcherBase as ChannelDispatcher; if (dispatcher != null && IsMetadataTransferDispatcher(description, dispatcher)) { mex.MexEnabled = true; mex.MexUrl = dispatcher.Listener.Uri; if (dynamicUpdateBehavior != null) { foreach (EndpointDispatcher endpointDispatcher in dispatcher.Endpoints) { if (!endpointDispatcher.AddressFilterSetExplicit) { endpointDispatcher.AddressFilter = new MatchAllMessageFilter(); } } } break; } } }
private static void CustomizeMetadataEndpoints(ServiceDescription description, ServiceHostBase host, ServiceMetadataExtension mex) { for (int i = 0; i < host.ChannelDispatchers.Count; i++) { ChannelDispatcher channelDispatcher = host.ChannelDispatchers[i] as ChannelDispatcher; if (channelDispatcher != null && ServiceMetadataBehavior.IsMetadataTransferDispatcher(description, channelDispatcher)) { if (channelDispatcher.Endpoints.Count != 1) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new InvalidOperationException(SR.GetString(SR.SFxServiceMetadataBehaviorInstancingError, channelDispatcher.Listener.Uri, channelDispatcher.CreateContractListString()))); } DispatchRuntime dispatcher = channelDispatcher.Endpoints[0].DispatchRuntime; // set instancing dispatcher.InstanceContextProvider = InstanceContextProviderBase.GetProviderForMode(InstanceContextMode.Single, dispatcher); bool isListeningOnHttps = channelDispatcher.Listener.Uri.Scheme == Uri.UriSchemeHttps; Uri listenUri = channelDispatcher.Listener.Uri; ServiceMetadataExtension.WSMexImpl impl = new ServiceMetadataExtension.WSMexImpl(mex, isListeningOnHttps, listenUri); dispatcher.SingletonInstanceContext = new InstanceContext(host, impl, false); } } }
private void CreateHealthEndpoints(ServiceDescription description, ServiceHostBase host, ServiceMetadataExtension mex) { const string ServiceHeathBehaviorHttpHealthUrl = "ServiceHeathBehaviorHttpHealthUrl"; const string ServiceHeathBehaviorHttpHealthEnabled = "ServiceHeathBehaviorHttpHealthEnabled"; const string ServiceHeathBehaviorHttpsHealthUrl = "ServiceHeathBehaviorHttpsHealthUrl"; const string ServiceHeathBehaviorHttpsHealthEnabled = "ServiceHeathBehaviorHttpsHealthEnabled"; if (this.HttpGetEnabled) { if (!EnsureHealthDispatcher(host, mex, this.httpGetUrl, Uri.UriSchemeHttp)) { TraceWarning(this.httpGetUrl, ServiceHeathBehaviorHttpHealthUrl, ServiceHeathBehaviorHttpHealthEnabled); } } if (this.HttpsGetEnabled) { if (!EnsureHealthDispatcher(host, mex, this.httpsGetUrl, Uri.UriSchemeHttps)) { TraceWarning(this.httpsGetUrl, ServiceHeathBehaviorHttpsHealthUrl, ServiceHeathBehaviorHttpsHealthEnabled); } } }
private void CreateHttpGetEndpoints(System.ServiceModel.Description.ServiceDescription description, ServiceHostBase host, ServiceMetadataExtension mex) { if (this.httpGetEnabled) { EnsureGetDispatcher(host, mex, this.httpGetUrl, Uri.UriSchemeHttp); } if (this.httpsGetEnabled) { EnsureGetDispatcher(host, mex, this.httpsGetUrl, Uri.UriSchemeHttps); } }