public static WcfServiceClient <TClient> Create(string key) { Type clientType = typeof(TClient); var configItem = Config.GetServiceConfig(clientType); if (null != configItem) { NetTcpBinding tcpBinding = TcpBindingUtility.CreateNetTcpBinding(); EndpointAddress endpointAddress = TcpBindingUtility.CreateEndpointAddress( configItem.Item.ServiceAddressPort + "/" + configItem.Item.EndpointName); WcfServiceClient <TClient> client = new WcfServiceClient <TClient>(tcpBinding, endpointAddress); return(client); } throw new Exception("Type " + clientType.AssemblyQualifiedName + " not found."); }
public static ServiceHost CreateServiceHost(this WcfServiceConfigElement item) { //start service listener if (string.IsNullOrEmpty(item.ServiceAddressPort) || string.IsNullOrEmpty(item.EndpointName)) { return(null); //no launch will occur if config is not there } 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(); //tcpBinding.PortSharingEnabled = true; //Metada ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15; smb.HttpGetEnabled = false; host.Description.Behaviors.Add(smb); //Metada host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexTcpBinding(), string.Format("net.tcp://{0}/{1}/mex", item.ServiceAddressPort, item.EndpointName)); //Service host.AddServiceEndpoint(contractType, tcpBinding, string.Format("net.tcp://{0}/{1}", item.ServiceAddressPort, item.EndpointName)); //this is the default but good to know host.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.UseWindowsGroups; return(host); }