Exemple #1
0
        /// <summary>
        /// Creates a service connection to the service behind the specified service interface.
        /// Please prefer <see cref="M:GetServiceWrapper{T}()"/> method!
        /// See documentation for further information.
        /// </summary>
        /// <remarks>Use this method only if you need to keep a connection to a service open longer than possible with <see cref="M:GetServiceWrapper{T}()"/>.
        /// When finished with the work (or it is safe to release the instance), make a call to <see cref="M:CloseServiceInstance(object)"/> to safely close and dispose the service connection.</remarks>
        /// <typeparam name="T">The service interface type.</typeparam>
        /// <returns>A service connection to the service behind the specified service interface.</returns>
        public static T GetServiceInstance <T>() where T : class, IExposedService
        {
            AssertContractTypeCorrect(typeof(T));

            Binding            binding = ServiceBindingCache.GetBindingForContractType(typeof(T));
            ChannelFactory <T> d       = new ChannelFactory <T>(binding, GetEndpointAddress(typeof(T), binding));

            T channel = d.CreateChannel();

            channel.Ping();
            return(channel);
        }
Exemple #2
0
        /// <summary>
        /// Creates a service connection to the callback service behind the specified service interface.
        /// Please prefer <see cref="M:GetServiceWrapper{T}()"/> method!
        /// See documentation for further information.
        /// </summary>
        /// <remarks>Use this method only if you need to keep a connection to a service open longer than possible with <see cref="M:GetServiceWrapper{T}()"/>.
        /// When finished with the work (or it is safe to release the instance), make a call to <see cref="M:CloseServiceInstance(object)"/> to safely close and dispose the service connection.</remarks>
        /// <typeparam name="T">The service interface type.</typeparam>
        /// <param name="callbackObject">The object representing the callback to use. Must not be null.</param>
        /// <returns>A service connection to the service behind the specified service interface.</returns>
        public static T GetCallbackServiceInstance <T>(object callbackObject) where T : class, IExposedService
        {
            AssertContractTypeCorrect(typeof(T));
            Assertions.AssertNotNull(callbackObject, "callbackObject");

            Binding binding            = ServiceBindingCache.GetBindingForContractType(typeof(T));
            DuplexChannelFactory <T> d = new DuplexChannelFactory <T>(callbackObject, binding, GetEndpointAddress(typeof(T), binding));

            T channel = d.CreateChannel();

            channel.Ping();
            return(channel);
        }