void IServiceBehavior.ApplyDispatchBehavior (
ServiceDescription description,
ServiceHostBase serviceHostBase)
{
if (singleton != null && InstanceContextMode != InstanceContextMode.Single)
throw new InvalidOperationException ("When creating a Service host with a service instance, use InstanceContextMode.Single in the ServiceBehaviorAttribute.");
foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers) {
ChannelDispatcher cd = cdb as ChannelDispatcher;
if (cd == null)
continue;
if (IncludeExceptionDetailInFaults) // may be set also in ServiceDebugBehaviorAttribute
cd.IncludeExceptionDetailInFaults = true;
foreach (EndpointDispatcher ed in cd.Endpoints) {
var dr = ed.DispatchRuntime;
if (dr.SingletonInstanceContext == null && InstanceContextMode == InstanceContextMode.Single)
dr.SingletonInstanceContext = CreateSingletonInstanceContext (serviceHostBase);
if (dr.InstanceContextProvider == null)
dr.InstanceContextProvider = CreateInstanceContextProvider (serviceHostBase, dr);
}
}
}