2012-08-31 56 views
1

我可以在窗口服務的功能和數據返回給應用程序vb.net?我可以在Windows服務中有返回功能嗎?

這裏是在窗口服務我的示例代碼:

Protected Overrides Sub OnStart(ByVal args() As String) 
     ' Add code here to start your service. This method should set things 
     ' in motion so your service can do its work. 
     EventLog1.WriteEntry("In OnStart") 
    End Sub 

    Protected Overrides Sub OnStop() 
     ' Add code here to perform any tear-down necessary to stop your service. 
     EventLog1.WriteEntry("In OnStop.") 
    End Sub 
    Protected Overrides Sub OnContinue() 
     EventLog1.WriteEntry("In OnContinue.") 
    End Sub 
    Protected Overrides Sub OnCustomCommand(ByVal command As Integer) 
     Dim mymsg As String 
     Dim servicestorun As New System.ServiceProcess.ServiceBase 
     If (command < 128) Then 
      MyBase.OnCustomCommand(command) 
     Else 
      Select Case command 
       Case 129 
        mymsg = "i want this msg to my vb.net application" 
       Case Else 
      End Select 
     End If 

    End Sub 

這裏是我的代碼vb.net應用:

Dim myServiceController As New System.ServiceProcess.ServiceController("MyNewService") 

     Dim status As String 
     Try 
      myServiceController.ExecuteCommand(129) 
' i want to get the msg from my windows service "i want this msg to my vb.net application" 
      status = "Custom Command Executed Successfully!" 
     Catch ex As Exception 
      status = "Failed To Execute Custom Command! " & ex.Message 
     End Try 

請需要幫助。

回答

1

您可以使用Windows服務作爲WCF主機。例如,見http://msdn.microsoft.com/en-us/library/ms733069.aspx

對於通信在同一臺機器上,我建議命名管道(NetNamedPipeBinding)。你甚至可以使用命名管道,而無需使用WCF(http://stackoverflow.com/questions/4303154/)

+0

我明白了,感謝您的答覆..我真的很感激它:>,i'l嘗試。 –

相關問題