static void Main(string[] args) { Uri baseAddress = new Uri("http://localhost:8080/Service"); // Create the ServiceHost. using (ServiceHost host = new ServiceHost(typeof(CounterService), baseAddress)) { // Enable metadata publishing. //ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); //smb.HttpGetEnabled = true; //smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15; //host.Description.Behaviors.Add(smb); host.AddDefaultEndpoints(); //var wsContract = new ContractDescription("WSHttpDefault"); //var wsEndpoint = new ServiceEndpoint( // Open the ServiceHost to start listening for messages. Since // no endpoints are explicitly configured, the runtime will create // one endpoint per base address for each service contract implemented // by the service. host.Open(); Console.WriteLine("The service is ready at {0}", baseAddress); Console.WriteLine("Press <Enter> to stop the service."); Console.ReadLine(); // Close the ServiceHost. host.Close(); } }
static void Main(string[] args) { //ServiceHost myHost = new ServiceHost(typeof(WCFService)); ServiceHost myHost = new ServiceHost(typeof(WCFService), new Uri("http://localhost:9003/AI3"), new Uri("net.tcp://localhost:9004/AI4")); myHost.AddDefaultEndpoints(); myHost.AddServiceEndpoint(typeof(IWCFService), new BasicHttpBinding(), "http://localhost:9001/AI"); myHost.AddServiceEndpoint(typeof(IWCFService), new NetTcpBinding(), "net.tcp://localhost:9002/"); ServiceMetadataBehavior behavior = new ServiceMetadataBehavior(); behavior.HttpGetUrl = new Uri("http://localhost:8090/WCFService"); behavior.HttpGetEnabled = true; myHost.Description.Behaviors.Add(behavior); try { myHost.Open(); Console.WriteLine("Service is worked ! Status : " + myHost.State); foreach (ServiceEndpoint ep in myHost.Description.Endpoints) { Console.WriteLine("A : {0} - B : {1} - C : {2}", ep.Address, ep.Binding.Name, ep.Contract.Name); } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadLine(); }
private void GameServerForm_Load(object sender, EventArgs e) { statusList.Items.Clear(); statusList.Items.Add("Initializing"); host = new ServiceHost(typeof(GameService), baseAddress); host.AddDefaultEndpoints(); statusList.Items.Add("Host started"); }
private ServiceHost start(Type wcfType) { Type interfaceType = getContractType(wcfType); String protocolPrefix = null; ServiceMetadataBehavior serviceBehavior = new ServiceMetadataBehavior(); Binding mexBinding = null; if (baseAddress.StartsWith("http://")) { serviceBehavior.HttpGetEnabled = true; mexBinding = MetadataExchangeBindings.CreateMexHttpBinding(); } else if (baseAddress.StartsWith("net.tcp://")) { mexBinding = MetadataExchangeBindings.CreateMexTcpBinding(); } else { throw new NotSupportedException("不支持的协议前缀。" + baseAddress); } //事件参数 ServiceBindingEventArgs args = new ServiceBindingEventArgs(); args.Address = interfaceType.Name; args.ContractInterface = interfaceType; args.ServiceClass = wcfType; args.ServiceMetadataBehavior = serviceBehavior; args.MexEndpointAddress = "mex"; //触发“服务绑定时”事件 if (ServiceBinding != null) { ServiceBinding(this, args); } //得到URL String url = baseAddress + args.Address + "/"; System.ServiceModel.ServiceHost serviceHost = new System.ServiceModel.ServiceHost(wcfType, new Uri(url)); serviceHost.Description.Behaviors.Add(args.ServiceMetadataBehavior); ServiceEndpoint mexEndpoint = new ServiceMetadataEndpoint(mexBinding, new EndpointAddress(url + args.MexEndpointAddress)); serviceHost.AddServiceEndpoint(mexEndpoint); serviceHost.AddDefaultEndpoints(); //打开 serviceHost.Open(); return(serviceHost); }
protected override void OnStart(string[] args) { if (myHost != null) { myHost.Close(); } // Create the host and specify a URL for an HTTP binding. myHost = new ServiceHost(typeof(MathService), new Uri("http://localhost:8080/MathServiceLibrary")); myHost.AddDefaultEndpoints(); // Open the host. myHost.Open(); }
protected override void OnStart(string[] args) { if (myHost != null) { myHost.Close(); myHost = null; } Uri address = new Uri("http://localhost:8080/MathServiceLibrary"); myHost = new ServiceHost(typeof(MathService), address); //BasicHttpBinding binding = new BasicHttpBinding(); //Type contract = typeof(IBasicMath); //myHost.AddServiceEndpoint(contract, binding, address); myHost.AddDefaultEndpoints(); myHost.Open(); }
static void Main(string[] args) { using (var host = new ServiceHost( typeof(EchoService), new Uri("http://localhost:8081/Echo"))) { host.AddServiceEndpoint(new UdpDiscoveryEndpoint()); host.AddDefaultEndpoints(); host.Open(); foreach (var endpoint in host.Description.Endpoints) { Console.WriteLine("{0} ({1})", endpoint.Address, endpoint.Binding.Name); } Console.ReadLine(); } }
public void Start() { Console.WriteLine("Starting local child process Service..."); Uri baseAddress = DiscoveryUtils.DiscoveryHelper.AvailableTcpBaseAddress; this.FindCoordinator(); _processHost = new ServiceHost(typeof(ChildProcess), baseAddress); _processHost.AddDefaultEndpoints(); _processHost.Open(); IntroduceToCoordinator(); _worker = new Thread(new ThreadStart(DoWork)); _worker.Start(); StartStatusServer(); }
private void StartElectionService() { Console.WriteLine("Starting local election service..."); Uri baseAddress = DiscoveryHelper.AvailableTcpBaseAddress; _election = new Election(); _election.Elected += ElectionElected; _election.ProcessLost += ElectionProcessLost; _election.FindConstituents(); _electionHost = new ServiceHost(typeof(Election), baseAddress); _electionHost.AddDefaultEndpoints(); _electionHost.Open(); _election.ElectionIdentity = _electionHost.Description.Endpoints[1].Address; Console.WriteLine("Election Service Started at: {0}", _electionHost.Description.Endpoints[1].Address.ToString()); Console.WriteLine(); IntroduceElection(); }
private void StartCoordinator() { Console.WriteLine("Starting local Coordinator Service..."); Uri baseAddress = DiscoveryUtils.DiscoveryHelper.AvailableTcpBaseAddress; this.FindProcesses(); _coordinatorHost = new ServiceHost(typeof(Coordinator), baseAddress); _coordinatorHost.AddDefaultEndpoints(); _coordinatorHost.Open(); IntroduceToProcesses(); }
static void Main() { var realService = new ServiceHost(typeof (Service), new Uri("http://localhost:12345/a")); realService.AddDefaultEndpoints(); var smb = new ServiceMetadataBehavior {HttpGetEnabled = true}; realService.Description.Behaviors.Add(smb); realService.Open(); var serviceHost = new ServiceHost(typeof (Duck), new Uri("http://localhost:12345/router")); serviceHost.AddDefaultEndpoints(); serviceHost.Open(); Console.WriteLine("Service is up and running."); var routerClient = ChannelFactory<IServiceClient>.CreateChannel(new BasicHttpBinding(), new EndpointAddress( "http://localhost:12345/router")); Console.WriteLine(routerClient.Op("bar")); Console.ReadLine(); serviceHost.Close(); realService.Close(); }