741741147

Hi everybody,

I have a problem with win services. I want to access a win service above a web service, I mean I have a win service that always run on computer and I must access some of the methods on this service. How can I do it Please help me about this. Thank you for all answers...



Re: Visual C# General Win Service PROBLEM

ahmedilyas

What problem do you have any errors What code are you using






Re: Visual C# General Win Service PROBLEM

741741147

I do not have any error, because I also do not have any code Smile . I am using C# and I write a win service and this win service has a method for adding two numbers. OnStart event this method runs. But I want to call this adding method on a web service ( I want to use win services's method remotely ). I counld not find any code to implement this. Thats it...




Re: Visual C# General Win Service PROBLEM

741741147

Ok I think I find the solution, I can reference a win service to web service. I had supposed that I counld not do it. But I would do. Thank you very much for your interest...




Re: Visual C# General Win Service PROBLEM

Peter Ritchie

To communicate with a running Windows Service you must provide some means of inter-process communications within the Windows Service. Accessing the Windows service's assembly via a web service is executing code in the Web Service, not accessing a running Windows Service.






Re: Visual C# General Win Service PROBLEM

Martin Xie - MSFT

Hi,

If you want to call a method in windows service from a web service, you have to add reference to System.ServiceProcess.dll and use ServiceController Class in the web service, and then override OnCustomCommand method in the windows service.

For Example.

WebService Code

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ServiceProcess
End Try

Return status
End Function

End Class

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

The following threads include good samples.

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

Best Regards,

Martin Xie