2014-01-24 3 views

답변

1

답변은 인프라에 따라 다릅니다. 서비스가 모두 동일한 시스템에있는 경우 NetNamedPipeBinding을 사용할 수 있습니다. 서비스와 소비자가 다른 시스템에있는 경우 NetTcpBinding 또는 BasicHttpBinding을 사용할 수 있습니다.

1
This solved my purpose... 

private const int RF_TESTMESSAGE = 0xA123; 
     const int WM_USER = 0x0400; 
     const int WM_CUSTOM_MESSAGE = WM_USER + 0x0001; 

     [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] 
     public static extern int SendMessage(IntPtr hwnd, [MarshalAs(UnmanagedType.U4)] int Msg, IntPtr wParam, int lParam); 

     public FormVideoApp() 
     { 
      InitializeComponent(); 
      lblProcID.Text = string.Format("This process ID: {0}", Process.GetCurrentProcess().Id); 
     }  

     private void button1_Click(object sender, EventArgs e) 
     { 
      //get this running process 
      Process proc = Process.GetCurrentProcess(); 
      //get all other (possible) running instances 
      //Process[] processes = Process.GetProcessesByName(proc.ProcessName); 
      Process[] processes = Process.GetProcessesByName("Application"); 
      int numberToSend = 1500; 
      string str = string.Empty; 
      str = "start"; 
      switch (str) 
      { 
       case "start": 
        numberToSend = 101; 
        break; 
       case "stop": 
        numberToSend = 102; 
        break; 
       case "error": 
        numberToSend = 103; 
        break; 
      } 

      if (processes.Length > 0) 
      { 
       //iterate through all running target applications 
       foreach (Process p in processes) 
       { 
        if (p.Id != proc.Id) 
        { 
         //now send the RF_TESTMESSAGE to the running instance 
         //SendMessage(p.MainWindowHandle, RF_TESTMESSAGE, IntPtr.Zero, IntPtr.Zero); 
         SendMessage(p.MainWindowHandle, WM_CUSTOM_MESSAGE, IntPtr.Zero, numberToSend); 
        } 
       } 
      } 
      else 
      { 
       MessageBox.Show("No other running applications found."); 
      } 
     } 
     protected override void WndProc(ref Message message) 
     { 
      //filter the RF_TESTMESSAGE 
      if (message.Msg == WM_CUSTOM_MESSAGE) 
      { 
       int numberReceived = (int)message.LParam; 
       string str=string.Empty; 
       //Do ur job with this integer 

       switch (numberReceived) 
       { 
        case 101: str = "start";      
         break; 
        case 102: str = "stop"; 
         break; 
        case 103: str = "error"; 
         break; 
       } 
       this.listBox1.Items.Add(str + "Received message RF_TESTMESSAGE"); 
      } 
      else 
      { 
       base.WndProc(ref message); 
      } 

      ////filter the RF_TESTMESSAGE 
      //if (message.Msg == RF_TESTMESSAGE) 
      //{ 
      // //display that we recieved the message, of course we could do 
      // //something else more important here. 
      // this.listBox1.Items.Add("Received message RF_TESTMESSAGE"); 
      //} 
      //be sure to pass along all messages to the base also 
      //base.WndProc(ref message); 
     }