public System.ServiceModel.ServiceHost CreateServiceHost(Type typeContract) { Type contractInterface = typeContract.GetInterfaces().First(); var contractInterfaceName = contractInterface.FullName; var subServiceName = GetSubServiceName(contractInterfaceName); var serviceHost = new System.ServiceModel.ServiceHost(typeContract, new Uri($"net.tcp://{Environment.MachineName}:{Port}/{subServiceName}", UriKind.RelativeOrAbsolute)); EndpointAddress endpointAdress = null; var binding = GetBinding(); var endpoint = new ServiceEndpoint(new ContractDescription(contractInterfaceName), binding, endpointAdress); serviceHost.SetEndpointAddress(endpoint, String.Empty); serviceHost.Description.Behaviors.Add(new ServiceMetadataBehavior() { HttpGetEnabled = IsDebug }); return(serviceHost); }