예제 #1
0
        public static ServiceHost CreateServiceHost(ServiceConfig item, object serviceHostInstance)
        {
            string addressPort = "localhost:" + item.Port;

            //check configuration, no launch if no config
            if (string.IsNullOrEmpty(item.Port) || string.IsNullOrEmpty(item.Item.EndpointName))
            {
                return(null);
            }

            Type contractType = Type.GetType(item.Item.ContractTypeDeclaration);

            var baseAddress = new Uri(string.Format("net.tcp://{0}/", addressPort));
            var fullAddress = new Uri(string.Format("net.tcp://{0}/{1}", addressPort, item.Item.EndpointName));
            var host        = new ServiceHost(serviceHostInstance, baseAddress);

            var binding = TcpBindingUtility.CreateNetTcpBinding();

            //var binding = HttpBindingUtility.CreateBasicHttpBinding();
            //var binding = HttpBindingUtility.CreateWsDualHttpBinding();

            host.AddServiceEndpoint(contractType, binding, fullAddress);

            //this is the default but good to know if we want to change it later
            //host.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.UseWindowsGroups;

            host.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.None;

            host.Description.Behaviors.Add(new ServiceCallTimerBehavior());

            var debugBehavior = host.Description.Behaviors.OfType <ServiceDebugBehavior>().FirstOrDefault();

            if (debugBehavior == null)
            {
                host.Description.Behaviors.Add(new ServiceDebugBehavior {
                    IncludeExceptionDetailInFaults = true
                });
            }
            else
            {
                debugBehavior.IncludeExceptionDetailInFaults = true;
            }

            return(host);
        }
예제 #2
0
        public static ServiceHost CreateServiceHost(this WcfServiceConfigElement item)
        {
            //check configuration, no launch if no config
            if (string.IsNullOrEmpty(item.ServiceAddressPort) || string.IsNullOrEmpty(item.EndpointName))
            {
                return(null);
            }

            Type hostType     = Type.GetType(item.HostTypeDeclaration);
            Type contractType = Type.GetType(item.ContractTypeDeclaration);

            Uri         tcpBaseAddress = new Uri(string.Format("net.tcp://{0}/", item.ServiceAddressPort));
            ServiceHost host           = new ServiceHost(hostType, tcpBaseAddress);

            NetTcpBinding tcpBinding = TcpBindingUtility.CreateNetTcpBinding();

            host.AddServiceEndpoint(contractType, tcpBinding,
                                    string.Format("net.tcp://{0}/{1}", item.ServiceAddressPort, item.EndpointName));

            //this is the default but good to know if we want to change it later
            host.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.UseWindowsGroups;

            return(host);
        }