最近在自学WCF,同样的代码,为什么放在控制台执行,服务能开启在浏览器中输入地址有内容,而放在Winform 里面服务开启后,在浏览器里找不到。代码如下
using (ServiceHost host = new ServiceHost(typeof(contract.sayHello)))
{
host.AddServiceEndpoint(typeof(contract.IsayHello), new WSHttpBinding(),
"http://127.0.0.1/sayHello");
if (host.Description.Behaviors.Find() == null)
{
ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
behavior.HttpGetEnabled = true;
behavior.HttpGetUrl = new Uri("http://127.0.0.1/sayHello");
host.Description.Behaviors.Add(behavior);
}
// Console.Write("open....");
host.Open();
MessageBox.Show("open....");
// Console.Read();
}