2014-03-04 5 views
0

계약 :net.pipe 서비스 호스트

[ServiceContract] 
public interface IDaemonService { 
    [OperationContract] 
    void SendNotification(DaemonNotification notification); 
} 

서비스 : WPF 응용 프로그램에서

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] 
public class DaemonService : IDaemonService { 
    public DaemonService() { 
    } 

    public void SendNotification(DaemonNotification notification) { 
     App.NotificationWindow.Notify(notification); 
    } 
} 

나는 다음을 수행하십시오

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 Studio의 디버깅 메뉴에서 프로세스에 연결하면 클라이언트가 아무도 끝점에서 수신 대기 중임을 알 수 있습니다. ... 당신은 using에 ServiceHost를을 만드는

답변

2

blablabla : "// 로컬 호스트/AkmDaemon net.pipe"에서 듣기에는 엔드 포인트가 없었다

[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 : 여기

는 클라이언트입니다 성명서는 Open 호 바로 뒤에 처리됩니다. Dispose 호출은 ServiceHost를 닫습니다.

using (host = new ServiceHost(...)) 
{ 
    host.AddServiceEndpoint(...); 
    host.Open(); 
} 
// ServiceHost.Dispose() called here 

그냥 사용 블록을 버리십시오.

+0

오, 나는 피곤했다. :) – EngineerSpock