Eamon
asked on
Remoting
I have being trying to get this to work for ages but can't
I want to use remoting to return a Dataset from a windows service.
A windows form with a button on it should query the service and get a dataset back. It is just not working and it is because i just dont fully understand remoting.
I want to use remoting to return a Dataset from a windows service.
A windows form with a button on it should query the service and get a dataset back. It is just not working and it is because i just dont fully understand remoting.
Maybe stupid question, but do you run all the code in the same project?
Why dont you just add a web reference and use that to handle the call.
ASKER
This is the code in my windows form
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Ch annels
Imports System.Runtime.Remoting.Ch annels.Tcp
Public Class Form1
Dim HO As CustServer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Initialize() Then
Dim strCustomer As String = txtCustomer.Text
Dim strStartDate As String = txtStartDate.Text
Dim strEndDate As String = txtEndDate.Text
Try
DataGridView1.DataSource = HO.getCustDocs(strCustomer , strStartDate, strEndDate)
Catch ex As Exception
MessageBox.Show(ex.ToStrin g)
End Try
HO = Nothing
DataGridView1.Refresh()
End If 'If Initialize() Then
End Sub
Public Function Initialize() As Boolean
Try
If HO Is Nothing Then
Dim chan As New TcpChannel()
ChannelServices.RegisterCh annel(chan , False) ' not sure about ensure security
Dim t As Type = System.Type.GetType("Form1 .CustServe r") ' THIS IS REALLY WHERE I HAVE A PROBLEM
' HAVE NO IDEA WHAT TO PUT IN AS TYPE. HAVE TRIED LOTS OF THINHS BUT T IS ALWAYS SET TO NOTHING.
HO = Activator.GetObject(t, "tcp://192.169.1.88:9999/C ustServer" ) ' this is my ip adress and the service is running on my machine
If HO Is Nothing Then
MsgBox("Could not initialize the remoting client. Check your configuration.")
Return False
End If
End If
Return True
Catch ex As Exception
MessageBox.Show(ex.ToStrin g, "Error In Initialize")
Return False
End Try
End Function
Public Class CustServer
Inherits MarshalByRefObject
Public Function getCustDocs(ByVal strCustomer As String, ByVal strStartDate As String, ByVal strEndDate As String) As DataSet
End Function
End Class
End Class
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Ch
Imports System.Runtime.Remoting.Ch
Public Class Form1
Dim HO As CustServer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Initialize() Then
Dim strCustomer As String = txtCustomer.Text
Dim strStartDate As String = txtStartDate.Text
Dim strEndDate As String = txtEndDate.Text
Try
DataGridView1.DataSource = HO.getCustDocs(strCustomer
Catch ex As Exception
MessageBox.Show(ex.ToStrin
End Try
HO = Nothing
DataGridView1.Refresh()
End If 'If Initialize() Then
End Sub
Public Function Initialize() As Boolean
Try
If HO Is Nothing Then
Dim chan As New TcpChannel()
ChannelServices.RegisterCh
Dim t As Type = System.Type.GetType("Form1
' HAVE NO IDEA WHAT TO PUT IN AS TYPE. HAVE TRIED LOTS OF THINHS BUT T IS ALWAYS SET TO NOTHING.
HO = Activator.GetObject(t, "tcp://192.169.1.88:9999/C
If HO Is Nothing Then
MsgBox("Could not initialize the remoting client. Check your configuration.")
Return False
End If
End If
Return True
Catch ex As Exception
MessageBox.Show(ex.ToStrin
Return False
End Try
End Function
Public Class CustServer
Inherits MarshalByRefObject
Public Function getCustDocs(ByVal strCustomer As String, ByVal strStartDate As String, ByVal strEndDate As String) As DataSet
End Function
End Class
End Class
ASKER
no code in the form is run in different project to the code for the service
You have to reference the remoting object in your client as well, that will reveal your type problem.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Have not had a chance to fully test this, but it looks like it will get me going.
Thanks.
Thanks.
ASKER
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Ch
Imports System.Runtime.Remoting.Ch
Public Class CustService
Dim x As Integer
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
EventLog1.WriteEntry("Cust
Timer1.Enabled = True
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
End Sub
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
If Not System.Diagnostics.EventLo
System.Diagnostics.EventLo
End If
EventLog1.Source = "CustSource"
EventLog1.Log = "TestLog"
Try
Dim channel As New TcpChannel(9999)
ChannelServices.RegisterCh
RemotingConfiguration.Appl
'Server is the name of the root namespace. It must be the same for client and server. It is in
'Progect properties - general
Dim t As Type = Type.GetType("remoCustServ
RemotingConfiguration.Regi
Test = t.ToString
Catch ex As Exception
My.Computer.FileSystem.Wri
End Try
End Sub
Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEvent
'Just keeping the service alive
x = 1
'x += 1
' EventLog1.WriteEntry("Tick
EventLog1.WriteEntry("Test
End Sub
End Class
Public Class CustServer
Inherits MarshalByRefObject
Private strCnn As String = "SourceDB=\\sales_pentium\
Private strCust As String
Private strSDate As String
Private strEDate As String
Private dsHead As DataSet
Public Sub New()
'RemotingConfiguration.App
'RemotingConfiguration.Reg
Test = "New Ran"
End Sub
Public Function getCustDocs(ByVal strCustomer As String, ByVal strStartDate As String, ByVal strEndDate As String) As DataSet
strCust = strCustomer
strSDate = strStartDate
strEDate = strEndDate
GetCustDockets()
Return dsHead
dsHead = Nothing
End Function
Private Sub GetCustDockets()
Dim Cnn As Odbc.OdbcConnection = New Odbc.OdbcConnection
Try
Cnn.ConnectionString = strCnn
Cnn.Open()
Catch ex As Exception
'MessageBox.Show(ex.Messag
End Try
Dim strSQL As String = "SELECT branch, ledgr_date, type, docket, ref1, customer, value_in FROM TrHead WHERE (customer = ?) AND (ledgr_date >= ?) AND (ledgr_date <= ?)" 'Dim strSQL As String = "SELECT branch, `date`, ledgr_date, type, docket, ref1, customer, value_in FROM TrHead WHERE (customer = ?) AND (ledgr_date >= ?) AND (ledgr_date <= ?)"
dsHead = New DataSet
Try
Dim daHead As Odbc.OdbcDataAdapter = New Odbc.OdbcDataAdapter(strSQ
daHead.SelectCommand.Param
daHead.SelectCommand.Param
daHead.SelectCommand.Param
daHead.SelectCommand.Param
daHead.SelectCommand.Param
daHead.SelectCommand.Param
daHead.Fill(dsHead, "TrHead")
daHead = Nothing
Catch ex As Exception
'MessageBox.Show(ex.ToStri
End Try
Cnn.Dispose()
End Sub
End Class