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);
                }
            }
        }
Beispiel #2
0
        private void ApplyInstancing(System.ServiceModel.Description.ServiceDescription description, ServiceHostBase serviceHostBase)
        {
            System.Type     serviceType = description.ServiceType;
            InstanceContext context     = null;

            for (int i = 0; i < serviceHostBase.ChannelDispatchers.Count; i++)
            {
                ChannelDispatcher dispatcher = serviceHostBase.ChannelDispatchers[i] as ChannelDispatcher;
                if (dispatcher != null)
                {
                    foreach (EndpointDispatcher dispatcher2 in dispatcher.Endpoints)
                    {
                        if (!dispatcher2.IsSystemEndpoint)
                        {
                            DispatchRuntime dispatchRuntime = dispatcher2.DispatchRuntime;
                            if (dispatchRuntime.InstanceProvider == null)
                            {
                                if (this.instanceProvider == null)
                                {
                                    if ((serviceType == null) && (this.wellKnownSingleton == null))
                                    {
                                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("InstanceSettingsMustHaveTypeOrWellKnownObject0")));
                                    }
                                    if ((this.instanceMode != System.ServiceModel.InstanceContextMode.Single) && (this.wellKnownSingleton != null))
                                    {
                                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxWellKnownNonSingleton0")));
                                    }
                                }
                                else
                                {
                                    dispatchRuntime.InstanceProvider = this.instanceProvider;
                                }
                            }
                            dispatchRuntime.Type = serviceType;
                            dispatchRuntime.InstanceContextProvider = InstanceContextProviderBase.GetProviderForMode(this.instanceMode, dispatchRuntime);
                            if ((this.instanceMode == System.ServiceModel.InstanceContextMode.Single) && (dispatchRuntime.SingletonInstanceContext == null))
                            {
                                if (context == null)
                                {
                                    if (this.wellKnownSingleton != null)
                                    {
                                        context = new InstanceContext(serviceHostBase, this.wellKnownSingleton, true, false);
                                    }
                                    else if (this.hiddenSingleton != null)
                                    {
                                        context = new InstanceContext(serviceHostBase, this.hiddenSingleton, false, false);
                                    }
                                    else
                                    {
                                        context = new InstanceContext(serviceHostBase, false);
                                    }
                                    context.AutoClose = false;
                                }
                                dispatchRuntime.SingletonInstanceContext = context;
                            }
                        }
                    }
                }
            }
        }
Beispiel #3
0
        private void ApplyInstancing(ServiceDescription description, ServiceHostBase serviceHostBase)
        {
            System.Type     serviceType     = description.ServiceType;
            InstanceContext instanceContext = (InstanceContext)null;

            for (int index = 0; index < serviceHostBase.ChannelDispatchers.Count; ++index)
            {
                ChannelDispatcher channelDispatcher = serviceHostBase.ChannelDispatchers[index] as ChannelDispatcher;
                if (channelDispatcher != null)
                {
                    foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints)
                    {
                        if (!endpointDispatcher.IsSystemEndpoint)
                        {
                            DispatchRuntime dispatchRuntime = endpointDispatcher.DispatchRuntime;
                            if (dispatchRuntime.InstanceProvider == null)
                            {
                                if (this.instanceProvider == null)
                                {
                                    if (serviceType == (System.Type)null && this.wellKnownSingleton == null)
                                    {
                                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError((Exception) new InvalidOperationException(System.ServiceModel.SR.GetString("InstanceSettingsMustHaveTypeOrWellKnownObject0")));
                                    }
                                    if (this.instanceMode != InstanceContextMode.Single && this.wellKnownSingleton != null)
                                    {
                                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError((Exception) new InvalidOperationException(System.ServiceModel.SR.GetString("SFxWellKnownNonSingleton0")));
                                    }
                                }
                                else
                                {
                                    dispatchRuntime.InstanceProvider = this.instanceProvider;
                                }
                            }
                            dispatchRuntime.Type = serviceType;
                            dispatchRuntime.InstanceContextProvider = InstanceContextProviderBase.GetProviderForMode(this.instanceMode, dispatchRuntime);
                            if (this.instanceMode == InstanceContextMode.Single && dispatchRuntime.SingletonInstanceContext == null)
                            {
                                if (instanceContext == null)
                                {
                                    instanceContext           = this.wellKnownSingleton == null ? (this.hiddenSingleton == null ? new InstanceContext(serviceHostBase, false) : new InstanceContext(serviceHostBase, this.hiddenSingleton, false, false)) : new InstanceContext(serviceHostBase, this.wellKnownSingleton, true, false);
                                    instanceContext.AutoClose = false;
                                }
                                dispatchRuntime.SingletonInstanceContext = instanceContext;
                            }
                        }
                    }
                }
            }
        }
        private void ApplyInstancing(ServiceDescription description, ServiceHostBase serviceHostBase)
        {
            Type            serviceType = description.ServiceType;
            InstanceContext singleton   = null;

            for (int i = 0; i < serviceHostBase.ChannelDispatchers.Count; i++)
            {
                if (serviceHostBase.ChannelDispatchers[i] is ChannelDispatcher channelDispatcher)
                {
                    foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints)
                    {
                        if (endpointDispatcher.IsSystemEndpoint)
                        {
                            continue;
                        }
                        DispatchRuntime dispatch = endpointDispatcher.DispatchRuntime;
                        if (dispatch.InstanceProvider == null)
                        {
                            if (_instanceProvider == null)
                            {
                                if (serviceType == null && _wellKnownSingleton == null)
                                {
                                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.InstanceSettingsMustHaveTypeOrWellKnownObject0));
                                }

                                if (_instanceMode != InstanceContextMode.Single && _wellKnownSingleton != null)
                                {
                                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxWellKnownNonSingleton0));
                                }
                            }
                            else
                            {
                                dispatch.InstanceProvider = _instanceProvider;
                            }
                        }
                        dispatch.Type = serviceType;
                        dispatch.InstanceContextProvider = InstanceContextProviderBase.GetProviderForMode(_instanceMode, dispatch);

                        if ((_instanceMode == InstanceContextMode.Single) &&
                            (dispatch.SingletonInstanceContext == null))
                        {
                            if (singleton == null)
                            {
                                if (_wellKnownSingleton != null)
                                {
                                    singleton = new InstanceContext(serviceHostBase, _wellKnownSingleton, true, false);
                                }
                                else if (_hiddenSingleton != null)
                                {
                                    singleton = new InstanceContext(serviceHostBase, _hiddenSingleton, false, false);
                                }
                                else
                                {
                                    singleton = new InstanceContext(serviceHostBase, false);
                                }

                                singleton.AutoClose = false;
                            }
                            dispatch.SingletonInstanceContext = singleton;
                        }
                    }
                }
            }
        }