Пример #1
0
        private Dictionary <Type, ServiceHostInfo> FindAllHosts()
        {
            var hosts = new Dictionary <Type, ServiceHostInfo>();

            foreach (Type type in TypeLocator.FindTypes(_dllSearchPattern, typeof(IServiceHost)))
            {
                ServiceHostInfo info = new ServiceHostInfo();

                Type interfaceType = (Type)type.GetMethod("GetInterfaceType", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy).Invoke(null, null);

                info.InterfaceType = interfaceType;
                info.Logger        = _logger;
                info.Host          = new ServiceHost(type);

                info.Host.Description.Behaviors.Add(new HostErrorHandlerBehavior(info));
                info.Host.Authorization.ServiceAuthorizationManager = new RoleBasedAuthorizationManager();

                ContractDescription contract = ContractDescription.GetContract(interfaceType);

                EndpointAddress endpoint = EndpointInformation.BuildEndpoint(new EndpointInformation(), ServerConnectionInformation.Instance, interfaceType);
                Binding         binding  = BindingInformation.BuildBinding(new BindingInformation(), ServerConnectionInformation.Instance);
                ServiceEndpoint service  = new ServiceEndpoint(contract, binding, endpoint);
                info.Host.AddServiceEndpoint(service);

                hosts.Add(interfaceType, info);
            }

            return(hosts);
        }
Пример #2
0
 public HostErrorHandlerBehavior(ServiceHostInfo info)
 {
     _info = info;
 }