473,506 Members | 16,970 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help to Invoke Method from Windows Service

I have a Windows service that I created that simply exposes a single public
function (RemoteCall). How can I access this publicly exposed method of a
windows service from a windows application? I'm using this as an example to
expand to other more useful methods such as datasets etc. from the service.
I will provide the service code. If someone could provide the client code I
would be grateful.
Windows Service Code:
Imports System.ServiceProcess
Imports System.Runtime.Remoting
Imports System.IO
Imports System.Runtime.Remoting.Channels.Tcp
Imports System.Runtime.Serialization.Formatters.Binary

Public Class Service1
Inherits System.ServiceProcess.ServiceBase

#Region " Component Designer generated code "

Public Sub New()
MyBase.New()

' This call is required by the Component Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call

End Sub

'UserService overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

' The main entry point for the process
<MTAThread()> _
Shared Sub Main()
Dim ServicesToRun() As System.ServiceProcess.ServiceBase

' More than one NT Service may run within the same process. To add
' another service to this process, change the following line to
' create a second service object. For example,
'
' ServicesToRun = New System.ServiceProcess.ServiceBase () {New
Service1, New MySecondUserService}
'
ServicesToRun = New System.ServiceProcess.ServiceBase() {New
Service1}

System.ServiceProcess.ServiceBase.Run(ServicesToRu n)
End Sub

'Required by the Component Designer
Private components As System.ComponentModel.IContainer

' NOTE: The following procedure is required by the Component Designer
' It can be modified using the Component Designer.
' Do not modify it using the code editor.
Friend WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

#End Region

Protected Overrides Sub OnStart(ByVal args() As String)
Dim chan As New TcpChannel(8085)
Dim remotingObj As RemotingObj
Dim RemotingConfiguration As RemotingConfiguration
Dim ChannelServices As Channels.ChannelServices
Try
ChannelServices.RegisterChannel(chan)
RemotingConfiguration.RegisterWellKnownServiceType (GetType
(RemotingObj), "RemotingObj", WellKnownObjectMode.SingleCall)
Catch
System.Diagnostics.EventLog.WriteEntry("ERROR: Failed to
register well known service type ", _
Err.Description, EventLogEntryType.Error)
End Try
End Sub

Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your
service.
End Sub

End Class
Public Class RemotingObj
Inherits System.MarshalByRefObject
Public Function RemoteCall(ByVal name As String)
RemoteCall = "I heard You"
End Function
End Class
Jul 21 '05 #1
0 2684

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3644
by: Jagdeesh | last post by:
Hai Colleagues, I am using Tomcat 4.1.24 and JDK 1.4.0_03 in my winXP machine. I've transferred a set of folders(containing jsp files) into tomcat's webapps directory(to /webapps/bob ,...
0
2254
by: Phil Powell | last post by:
Ok, I installed ANT, I have c:\ant in my ANT_HOME environment variable, I have c:\ant\bin in my PATH environmental variable, I installed the JAR files for TCL and for Javascript (Rhino)... to no...
5
27956
by: Grant Collins | last post by:
Hi I am writing a web based application as part of a small project that I am undertaking using servlets beans and jsp. I already have one servlet - bean - jsp page working and I have written...
5
2084
by: slylos | last post by:
I have an app written in C# (obviously). Here is my dilemma: The form loads, instantiates a bunch of worker threads that execute one at a time. When one finishes, it starts the next one in...
22
4030
by: Jeff Louie | last post by:
Well I wonder if my old brain can handle threading. Dose this code look reasonable. Regards, Jeff using System; using System.Diagnostics; using System.IO; using System.Threading;
14
7332
by: stic | last post by:
Hi, I'm in a middle of writing something like 'exception handler wraper' for a set of different methodes. The case is that I have ca. 40 methods form web servicem, with different return values...
0
848
by: Eric | last post by:
I have a Windows service that I created that simply exposes a single public function (RemoteCall). How can I access this publicly exposed method of a windows service from a windows application?...
10
14816
by: Mae Lim | last post by:
Dear all, I'm new to C# WebServices. I compile the WebService project it return no errors "Build: 1 succeeded, 0 failed, 0 skipped". Basically I have 2 WebMethod, when I try to invoke the...
1
3893
by: viswanathtvs | last post by:
java.util.NoSuchElementException javax.faces.el.EvaluationException: java.util.NoSuchElementException at...
0
7103
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.