代码如下:
using (ServiceHost
DuplexCommonHost = new ServiceHost(typeof(DuplexCommonService)),
OneWayCommonHost = new ServiceHost(typeof(OneWayCommonService)))
{
DuplexCommonHost.Opened += delegate { Console.Write("DuplexCommon service has been opened!"); };
DuplexCommonHost.Open();
OneWayCommonHost.Opened += delegate { Console.Write("OneWayCommon service has been opened!"); };
OneWayCommonHost.Open();
Console.Read();
}
结果客户端报一下错误:没有终结点在侦听可以接受消息的 http://localhost:8080/OneWayCommon
屏蔽红色部分代码,客户端正常运行。
对的,是不能同时实例化的,否则会报不能同时监听多个连接,最多只能监听一次,也就是同一个IP和端口号,只能同时使用一次,SockException异常,为什么要实例化两次,有点不明白?