Remoting Questions

I have a remote object that must be used by multi ple client possibly at the same time for across the net.My object only has 5 functions .The finally step(function does a sql process that is ran by an exe that I call from my remote object on the server.For some reason when one client is doing this process and the next client tries to just get connect to my object they get a remoting error and can not connect.
Remote object
<code>
Imports System
Imports System.IO
Imports System.Data.SqlClient
Imports Microsoft.ApplicationBlocks.Data
Imports Microsoft.VisualBasic
Imports System.Data.Odbc

Public Class ServiceClass
    Inherits MarshalByRefObject

    Private m_starttime As DateTime
    Private connString As String = "Server=myserever;database=DNuke;uid=;password="
    Public Sub New()
        Console.WriteLine("ServiceClass created without constructor. Instance hash is " & Me.GetHashCode().ToString())
        m_starttime = DateTime.Now
    End Sub

    Protected Overrides Sub Finalize()
        Console.WriteLine("I'm being collected after " & (New TimeSpan(DateTime.Now.Ticks - m_starttime.Ticks)).ToString() & " seconds.")
        MyBase.Finalize()
    End Sub

    Public Function GetServerTime() As DateTime
        Console.WriteLine("Time requested by a client.")
        Return DateTime.Now
    End Function
    Public Function CheckFile(ByVal theFile As String) As Boolean
        Console.WriteLine("File requested by a client was: " & theFile)
        Dim str As String = "C:\Working\"
        str = str & theFile
        If File.Exists(str) Then
            Console.WriteLine("File requested by a client.")
            Return True
        Else
            Return False
        End If

    End Function
    Public Function UnzipFile(ByVal aFile As String) As Boolean
        Console.WriteLine("File Unzip requested by a client was: " & aFile)
        Dim dataPath As String
        dataPath = "C:\Working\pkzipc -extract -over=all C:\Working\" & aFile & ".zip C:\Working\"
        Try
            Shell(dataPath, AppWinStyle.NormalFocus, True)
        Catch ex As Exception
        End Try
    End Function
    Public Function DeleteSql(ByVal DealerID As String) As Boolean
        Console.WriteLine("Delete Sql requested by a client was: " & DealerID)
        Try
            SqlHelper.ExecuteNonQuery(connString, "Autostar_RemoveData", DealerID)
        Catch ex As Exception
        End Try
    End Function
    Public Function ConvertDBFtoSql(ByVal fName As String) as String
        Console.WriteLine("Converting DBF To Sql requested by a client was: ")
        Dim arParms() As SqlParameter = New SqlParameter(20) {}

        Dim oConn As New OdbcConnection
        'Execute Statement
        Dim f1 As String = "C:\Working\" & fName & ".dbf"
        Dim f2 As String = "C:\Working\" & fName & ".fpt"

        Dim sConnString As String = "Driver={Microsoft Visual FoxPro Driver};UID=;PWD=;SourceDB=C:\Working\;SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;"
        Dim strSQL As String = "Select * From " & fName
        Dim cmd As OdbcCommand = New OdbcCommand(strSQL)
        Dim oODBCConnection As New OdbcConnection(sConnString)
        Try
            oODBCConnection.Open()
            cmd.Connection = oODBCConnection 'Just add this line
            Dim Reader As OdbcDataReader
            Reader = cmd.ExecuteReader()
            While Reader.Read
                arParms(0) = New SqlParameter("@dealer", System.Data.SqlDbType.Char, 8)
                arParms(0).Value = Trim(Reader(0))
                ' @FileName Input Parameter
                arParms(1) = New SqlParameter("@stock", System.Data.SqlDbType.Char, 8)
                arParms(1).Value = Trim(Reader(1))
                ' @WebID Input Parameter
                arParms(2) = New SqlParameter("@vin", System.Data.SqlDbType.Char, 17)
                arParms(2).Value = Trim(Reader(2))
                arParms(3) = New SqlParameter("@make", System.Data.SqlDbType.Char, 20)
                arParms(3).Value = Reader(3)
                arParms(4) = New SqlParameter("@model", System.Data.SqlDbType.Char, 20)
                arParms(4).Value = Trim(Reader(4))
                arParms(5) = New SqlParameter("@color", System.Data.SqlDbType.Char, 12)
                arParms(5).Value = Trim(Reader(5))
                arParms(6) = New SqlParameter("@body", System.Data.SqlDbType.Char, 4)
                arParms(6).Value = Trim(Reader(6))
                arParms(7) = New SqlParameter("@status", System.Data.SqlDbType.Char, 10)
                arParms(7).Value = Trim(Reader(7))
                arParms(8) = New SqlParameter("@inv", System.Data.SqlDbType.Bit)
                arParms(8).Value = Reader(8)
                arParms(9) = New SqlParameter("@compcode", System.Data.SqlDbType.Char, 2)
                arParms(9).Value = Reader(9)
                arParms(10) = New SqlParameter("@year", System.Data.SqlDbType.Char, 4)
                arParms(10).Value = Reader(10)
                arParms(11) = New SqlParameter("@selling", System.Data.SqlDbType.Decimal, 9)
                arParms(11).Value = Reader(11)
                arParms(12) = New SqlParameter("@new", System.Data.SqlDbType.Bit)
                arParms(12).Value = Reader(12)
                arParms(13) = New SqlParameter("@mileage", System.Data.SqlDbType.Int)
                arParms(13).Value = Reader(13)
                arParms(14) = New SqlParameter("@downpay", System.Data.SqlDbType.Decimal, 9)
                arParms(14).Value = Reader(14)
                arParms(15) = New SqlParameter("@createdate", System.Data.SqlDbType.DateTime)
                arParms(15).Value = Reader(15)
                arParms(16) = New SqlParameter("@createtime", System.Data.SqlDbType.DateTime)
                arParms(16).Value = Reader(16)
                arParms(17) = New SqlParameter("@engine", System.Data.SqlDbType.Char, 15)
                arParms(17).Value = Reader(17)
                arParms(18) = New SqlParameter("@fuel", System.Data.SqlDbType.Char, 15)
                arParms(18).Value = Reader(18)
                arParms(19) = New SqlParameter("@trans", System.Data.SqlDbType.Char, 15)
                arParms(19).Value = Reader(19)
                arParms(20) = New SqlParameter("@features", System.Data.SqlDbType.Char, 15)
                arParms(20).Value = Reader(20)
                Try
                    SqlHelper.ExecuteNonQuery(connString, System.Data.CommandType.StoredProcedure, "Autostar_InsertInventory", arParms)
                Catch ex As Exception
return "fail"
                End Try
            End While
            Reader.Close()
        Catch ex As Exception
return "fail"
        Finally
            oODBCConnection.Close()
        End Try
        File.Delete(f1)
        File.Delete(f2)
return "pass"

    End Function
 Public Function RunUpdateSQL(ByVal p1 as String,ByVal p2 as String,ByVal p3 as String) As Boolean
        Console.WriteLine("Update Sql was requested by a client")
         Dim dataPath As String
        dataPath = "C:\InvUpdates\WebInventoryUpdate.exe " & p1 & " " & p2
        Try
            Shell(dataPath, AppWinStyle.NormalFocus, True)
        Catch ex As Exception
return false
        End Try
return true
    End Function
    Public ReadOnly Property InstanceHash() As Integer
        Get
            Return Me.GetHashCode()
        End Get
    End Property

End Class
</code>


Server code(exe)
<code>
Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Http


Public Class ServerProcess
   <MTAThread()> _
   Public Shared Sub Main()

      Dim channel As New HttpChannel(13000)
      ChannelServices.RegisterChannel(channel)

      Dim object1 As New ServiceClass()

      ' Creates the single instance of ServiceClass. All clients
      ' will use this instance.
      Dim ref1 As ObjRef = RemotingServices.Marshal(object1, "object1uri")
      Console.WriteLine("ObjRef.URI: " & ref1.URI)

      Console.WriteLine("Running. Press Enter to end publication.")
      Console.ReadLine()

      ' This unregisters the object from publication, but leaves
      ' the channel listening.
      RemotingServices.Disconnect(object1)
      Console.WriteLine()
      Console.WriteLine("Disconnected the object. Client now receives a RemotingException.")
      Console.WriteLine("Press Enter to unregister the channel.")
      Console.ReadLine()
      ' At this point, the ServerClass object still exists. The server
      ' could republish it.

      ' This unregisters the channel, but leaves the application
      ' domain running.
      ChannelServices.UnregisterChannel(channel)
      Console.WriteLine("Unregistered the channel. Client now receives a WebException.")
      ' The ServerClass object still exists. The server could
      ' reregister the channel and republish the object.
      Console.WriteLine("The host application domain is still running. Press Enter to stop the process.")
      Console.ReadLine()

      ' The ServiceClass object's Finalize method writes a message to
      ' the console. A single object will almost always succeed in
      ' running its Finalize method before the Console is finalized;
      ' in a larger application, you could ensure that all objects
      ' finalize before the application ends by calling the garbage
      ' collector and waiting.
      GC.Collect()
      GC.WaitForPendingFinalizers()
   End Sub
  
End Class
</code>
Any Ideas as to how to accomplish what I need or Why the app does not run when multiple clients are trying to run at the same time


Answer this question

Remoting Questions

  • spga

    It should help you achieve the same u are trying with  RemotingServices.Marshal...
    An alternative approach which might not have the issue you are currently facing.

    Regards,
    Vikram

  • Hank Hubbard

    Hi,
    Why not simply expose the class as a Singleton on the server using RemotingConfiguration.RegisterWellKnownServiceType
    Regards,
    Vikram

  • Daniel McGloin

    What exactly will this do for me
  • Remoting Questions