can i call a function in a windows service from a web service using vb.net

ankouny

Member
Joined
Jun 5, 2007
Messages
5
Programming Experience
1-3
Hi,

I need help.

can i call a function in a windows service from a web service using vb.net
 
Yes

Hi,
I think Yes. You have to add reference to System.ServiceProcess.dll and use ServiceController Class. In the windows service you should override OnCustomCommand method.

for eg: WebService code
VB.NET:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ServiceProcess

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Service
    Inherits System.Web.Services.WebService

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

    <WebMethod()> _
    Public Function ExecuteCustomCommand() As String

        Dim status As String
        Try
            myServiceController.ExecuteCommand(129)
            status = "Custom Command Executed Successfully!"
        Catch ex As Exception
            status = "Failed To Execute Custom Command! " & ex.Message
        End Try

        Return status
    End Function

End Class


OnCustomCommand method of 'TestService' (windows service).

VB.NET:
Protected Overrides Sub OnCustomCommand(ByVal command As Integer)

        If (command < 128) Then
            MyBase.OnCustomCommand(command)
        Else
            Select Case command
                Case 129
			'Do Something.
                Case Else
            End Select
        End If

    End Sub
 
Back
Top