473,378 Members | 1,394 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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
Nov 22 '05 #1
0 845

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

Similar topics

0
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
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...
0
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?...
1
by: viswanathtvs | last post by:
java.util.NoSuchElementException javax.faces.el.EvaluationException: java.util.NoSuchElementException at...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.