Ejemplo n.º 1
0
        public void AddHostType <T>(IServiceCommunicationSettings settings, IEnumerable <IServiceBehavior> customBehaviors = null)
        {
            var         hostedType = typeof(T);
            ServiceHost sh         = new ServiceHost(hostedType);

            var binding   = GetBinding(settings);
            var behaviors = GetBehaviors(settings);

            if (customBehaviors != null)
            {
                behaviors = behaviors.Concat(customBehaviors);
            }

            var url = settings.Host.Uri;

            Add(sh, behaviors);

            AddServiceEndpoint <T>(url, sh, binding);

            Log.InfoFormat("hosting {0} using url:{1} with binding:{2} behaviour:{3}", typeof(T), url, binding?.Name, string.Join(";", behaviors?.Select(_ => _.GetType().Name)));

            OpenHost(sh);

            Add(sh);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the binding.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static Binding GetBinding(this IServiceCommunicationSettings settings, EndpointSettings value)
        {
            Binding binding = null;

            if (value.Binding == null)
            {
                return(binding);
            }
            var config = GetSection();

            foreach (var bc in config.Bindings.BindingCollections)
            {
                // In config we can have more configurated Bindings with this code we are forcing the CRM Binding to be first
                foreach (IBindingConfigurationElement element in bc.ConfiguredBindings)
                {
                    if (element.Name.Equals(value.Binding, StringComparison.OrdinalIgnoreCase))
                    {
                        binding      = (Binding)Activator.CreateInstance(bc.BindingType);
                        binding.Name = element.Name;
                        element.ApplyConfiguration(binding);
                        //Log.Debug("value {0} configured with {1}", value.Uri, element.Name);
                        return(binding);
                    }
                }
            }
            return(new WSHttpBinding()
            {
                Name = settings.FallbackBindingName
            });
        }
Ejemplo n.º 3
0
        //ILog log;

        //public WcfHosting(ILog logger)
        //{
        //	log = logger;
        //}

        /// <summary>
        /// Adds the wcf host using instance of interface T and settings.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value">The value of wcf service host.</param>
        /// <param name="settings">The settings.</param>
        /// <returns></returns>
        /// <exception cref="NullReferenceException">
        /// no value to host
        /// or
        /// no value settings to host
        /// </exception>
        public T AddHost <T>(T value, IServiceCommunicationSettings settings)
        {
            if (value == null)
            {
                throw new NullReferenceException("no value");
            }
            if (settings == null)
            {
                throw new NullReferenceException("no settings instance");
            }
            if (settings.Host == null)
            {
                throw new NullReferenceException("no settings.Host instance");
            }
            return(AddHost(value, GetBinding(settings), settings.Host.Uri, GetBehaviors(settings)));
        }
Ejemplo n.º 4
0
 protected virtual IEnumerable <IServiceBehavior> GetBehaviors(IServiceCommunicationSettings s)
 {
     return(s.Host.GetBehavior());
 }
Ejemplo n.º 5
0
 protected virtual Binding GetBinding(IServiceCommunicationSettings s)
 {
     return(s.GetBinding(s.Host));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WcfClient{TRemoteInterface}"/> class.
 /// </summary>
 /// <param name="remoteSettings">The remote service settings.</param>
 /// <param name="logger">The logger.</param>
 public WcfClient(IServiceCommunicationSettings remoteSettings)
 {
     _settings = remoteSettings;
 }