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.
LVL 1
EamonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

EamonAuthor Commented:
This is the code from the windows service


Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp


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 Start")
        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.EventLog.SourceExists("CustSource") Then
            System.Diagnostics.EventLog.CreateEventSource("CustSource", "TestLog")
        End If

        EventLog1.Source = "CustSource"
        EventLog1.Log = "TestLog"




        Try
            Dim channel As New TcpChannel(9999)
            ChannelServices.RegisterChannel(channel, False)   ' eamon check this again to make sure it is correct.
            RemotingConfiguration.ApplicationName = "CustInfoName"
            '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("remoCustService.CustServer")
            RemotingConfiguration.RegisterWellKnownServiceType(t, "CustServer", WellKnownObjectMode.SingleCall)

            Test = t.ToString

        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText("c:\Testing.txt", Now() & " - " & ex.ToString & vbCrLf, True)
        End Try


    End Sub

    Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
        'Just keeping the service alive
        x = 1
        'x += 1
        ' EventLog1.WriteEntry("Tick " & x)
        EventLog1.WriteEntry("Test = " & Test)
    End Sub
End Class


Public Class CustServer
    Inherits MarshalByRefObject


    Private strCnn As String = "SourceDB=\\sales_pentium\Ddrv\HEAD\DATA;PWD=;SourceType=DBF;Collate=Machine;BackgroundFetch=Yes;Exclusive=No;Driver={Microsoft dBase VFP Driver (*.dbf)};UID="
    Private strCust As String
    Private strSDate As String
    Private strEDate As String

    Private dsHead As DataSet


    Public Sub New()
        'RemotingConfiguration.ApplicationName = "getCustDocs"
        'RemotingConfiguration.RegisterWellKnownServiceType(GetType(clsCustInfo), "MyUri", WellKnownObjectMode.Singleton)


        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.Message.ToString)
        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(strSQL, Cnn)

            daHead.SelectCommand.Parameters.Add(New Odbc.OdbcParameter("@Cust", Odbc.OdbcType.NVarChar, 6))
            daHead.SelectCommand.Parameters.Add(New Odbc.OdbcParameter("@SDate", Odbc.OdbcType.Date))
            daHead.SelectCommand.Parameters.Add(New Odbc.OdbcParameter("@EDate", Odbc.OdbcType.Date))

            daHead.SelectCommand.Parameters.Item("@Cust").Value = strCust
            daHead.SelectCommand.Parameters.Item("@SDate").Value = strSDate
            daHead.SelectCommand.Parameters.Item("@EDate").Value = strEDate

            daHead.Fill(dsHead, "TrHead")
            daHead = Nothing
        Catch ex As Exception
            'MessageBox.Show(ex.ToString)
        End Try

        Cnn.Dispose()

    End Sub

End Class
PockyMasterCommented:
Maybe stupid question, but do you run all the code in the same project?
Mikal613Commented:
Why dont you just add a web reference and use that to handle the call.
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

EamonAuthor Commented:
This is the code in my windows form


Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.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.ToString)

            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.RegisterChannel(chan, False) '   not sure about ensure security

                Dim t As Type = System.Type.GetType("Form1.CustServer")    ' 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/CustServer")   ' 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.ToString, "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
EamonAuthor Commented:
no code in the form is run in different project to the code for the service
PockyMasterCommented:
You have to reference the remoting object in your client as well, that will reveal your type problem.
PockyMasterCommented:
this guy did some work to explain it in simple words:

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=1284&lngWId=10

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
EamonAuthor Commented:
Have not had a chance to fully test this, but it looks like it will get me going.
Thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.