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

    Question

  •  

    Hi,

    I need help.

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

    Wednesday, June 06, 2007 5:46 AM

Answers

  • I already find the answer thanks for asking.

    the subject was , if i can call a function in windows service through a web service.

     

    here is an example :

     

     

     

    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

    Code:
    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).

    Code:
    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
    Tuesday, June 12, 2007 5:06 AM

All replies

  • Hi Ankouny,

       I'm not very sure about what you mean by "function in windows service". Could you please cover your problem in more detail?

    Thanks!

    Monday, June 11, 2007 8:09 AM
  • I already find the answer thanks for asking.

    the subject was , if i can call a function in windows service through a web service.

     

    here is an example :

     

     

     

    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

    Code:
    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).

    Code:
    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
    Tuesday, June 12, 2007 5:06 AM