static void Main(string[] args) { ServiceHost restHost = new ServiceHost(typeof(RestService), new Uri(RestServiceBaseAddress)); restHost.AddServiceEndpoint(typeof(IRestInterface), new WebHttpBinding(), "").Behaviors.Add(new WebHttpBehavior()); restHost.Open(); ServiceHost NormalHost = new ServiceHost(typeof(NormalService), new Uri(NormalServiceBaseAddress)); NormalHost.AddServiceEndpoint(typeof(INormalInterface), new BasicHttpBinding(), ""); NormalHost.Open(); Console.WriteLine("Hosts open"); ChannelFactory <INormalInterface> factory = new ChannelFactory <INormalInterface>(new BasicHttpBinding(), new EndpointAddress(NormalServiceBaseAddress)); INormalInterface proxy = factory.CreateChannel(); Console.WriteLine(proxy.CallAdd(123, 456)); Console.WriteLine(proxy.CallEcho("Hello world")); }
static void CallRestFromWcf() { ServiceHost restHost = new ServiceHost(typeof(RestService), new Uri(Constant.RestServiceBaseAddress)); restHost.AddServiceEndpoint(typeof(IRestInterface), new WebHttpBinding(), "").Behaviors.Add(new WebHttpBehavior()); restHost.Open(); ServiceHost normalHost = new ServiceHost(typeof(NormalService), new Uri(Constant.NormalServiceBaseAddress)); normalHost.AddServiceEndpoint(typeof(INormalInterface), new BasicHttpBinding(), ""); normalHost.Open(); Console.WriteLine("Hosts opened"); ChannelFactory <INormalInterface> factory = new ChannelFactory <INormalInterface>(new BasicHttpBinding(), new EndpointAddress(Constant.NormalServiceBaseAddress)); INormalInterface client = factory.CreateChannel(); Console.WriteLine(client.CallAdd(2, 3)); Console.WriteLine(client.CallEcho("Hello, World")); Console.ReadLine(); }