合同:
[ServiceContract]
public interface IDaemonService {
[OperationContract]
void SendNotification(DaemonNotification notification);
}服务:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class DaemonService : IDaemonService {
public DaemonService() {
}
public void SendNotification(DaemonNotification notification) {
App.NotificationWindow.Notify(notification);
}
}在WPF应用程序中,我执行以下操作:
using (host = new ServiceHost(typeof (DaemonService), new[] {new Uri("net.pipe://localhost")})) {
host.AddServiceEndpoint(typeof (IDaemonService), new NetNamedPipeBinding(), "AkmDaemon");
host.Open();
} 这个WPF应用程序启动另一个应用程序,如下所示:
Task.Factory.StartNew(() => {
var tpm = new Process { StartInfo = { FileName = "TPM" } };
tpm.Start();
}
});名为TPM的应用程序启动正常。然后,我在Visual的调试菜单中附加到进程,我看到客户端说没有人在监听端点。
这是客户端:
[Export(typeof(DaemonClient))]
public class DaemonClient : IHandle<DaemonNotification> {
private readonly ChannelFactory<IDaemonService> channelFactory;
private readonly IDaemonService daemonServiceChannel;
public DaemonClient(IEventAggregator eventAggregator) {
EventAggregator = eventAggregator;
EventAggregator.Subscribe(this);
channelFactory = new ChannelFactory<IDaemonService>(new NetNamedPipeBinding(),
new EndpointAddress("net.pipe://localhost/AkmDaemon"));
daemonServiceChannel = channelFactory.CreateChannel();
}
public IEventAggregator EventAggregator { get; private set; }
public void Handle(DaemonNotification message) {
daemonServiceChannel.SendNotification(message); //Here I see that the endpoint //is not found
}
public void Close() {
channelFactory.Close();
}
}EndpointNotFoundException没有端点侦听“net.管道://localhost/AkmDaemon”.短唇
发布于 2014-03-04 08:15:16
您是在一个ServiceHost语句中创建您的using语句,因此在Open调用之后立即对它进行处理。Dispose调用关闭ServiceHost。
using (host = new ServiceHost(...))
{
host.AddServiceEndpoint(...);
host.Open();
}
// ServiceHost.Dispose() called here把使用的块放下来。
https://stackoverflow.com/questions/22163473
复制相似问题