public abstract partial class ServiceHostBase
: CommunicationObject, IExtensibleObject<ServiceHostBase>, IDisposable
{
+ // It is used for mapping a ServiceHostBase to HttpChannelListener precisely.
+ internal static ServiceHostBase CurrentServiceHostHack;
+
ServiceCredentials credentials;
ServiceDescription description;
UriSchemeKeyedCollection base_addresses;
//can change the collection in the description during the behaviors events.
ServiceEndpoint[] endPoints = new ServiceEndpoint[Description.Endpoints.Count];
Description.Endpoints.CopyTo (endPoints, 0);
- var builder = new DispatcherBuilder ();
+ var builder = new DispatcherBuilder (this);
foreach (ServiceEndpoint se in endPoints) {
var commonParams = new BindingParameterCollection ();
/// <remarks>Will re-use ChannelDispatchers when two endpoint uris are the same</remarks>
partial class DispatcherBuilder
{
+ ServiceHostBase host;
+
+ public DispatcherBuilder (ServiceHostBase host)
+ {
+ this.host = host;
+ }
+
List<ChannelDispatcher> built_dispatchers = new List<ChannelDispatcher> ();
Dictionary<ServiceEndpoint, EndpointDispatcher> ep_to_dispatcher_ep = new Dictionary<ServiceEndpoint, EndpointDispatcher> ();
-
+
+ internal static Action<ChannelDispatcher> ChannelDispatcherSetter;
+
internal ChannelDispatcher BuildChannelDispatcher (Type serviceType, ServiceEndpoint se, BindingParameterCollection commonParams)
{
//Let all behaviors add their binding parameters
ep = cd.InitializeServiceEndpoint (serviceType, se);
} else {
// Use the binding parameters to build the channel listener and Dispatcher.
- IChannelListener lf = BuildListener (se, commonParams);
- cd = new ChannelDispatcher (
- lf, se.Binding.Name);
+ lock (HttpTransportBindingElement.ListenerBuildLock) {
+ ServiceHostBase.CurrentServiceHostHack = host;
+ IChannelListener lf = BuildListener (se, commonParams);
+ cd = new ChannelDispatcher (lf, se.Binding.Name);
+ if (ChannelDispatcherSetter != null) {
+ ChannelDispatcherSetter (cd);
+ ChannelDispatcherSetter = null;
+ }
+ ServiceHostBase.CurrentServiceHostHack = null;
+ }
ep = cd.InitializeServiceEndpoint (serviceType, se);
built_dispatchers.Add (cd);
}