.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

remote channel allocation through window applications

Posted By:papsantony       Posted Date: August 11, 2010    Points: 10    Category: Visual Studio    URL: http://www.dotnetspark.com  

try it now
 

Imports System
Imports System.Runtime.Remoting.Messaging

Public MustInherit Class BaseRemoteObject
    Inherits MarshalByRefObject

    Public MustOverride Sub setValue(ByVal newval As Integer)
    Public MustOverride Function getValue() As Integer
End Class



///////////////////////////////////test.vb
// Compile: vbc /t:exe /r:general.dll test.vb
Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels.Http
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Proxies

Module Client

    Delegate Sub SetValueDelegate(ByVal value As Integer)

    Sub Main()
        Dim start As DateTime = System.DateTime.Now

        Dim channel As New HttpChannel()
        ChannelServices.RegisterChannel(channel,false)

        Dim obj As BaseRemoteObject = CType(Activator.GetObject( _
            GetType(BaseRemoteObject), _
            "http://localhost:1234/MyRemoteObject.soap"), BaseRemoteObject)


        Dim svDelegate As New SetValueDelegate(AddressOf obj.setValue)
        Dim svAsyncres As IAsyncResult = svDelegate.BeginInvoke(42, Nothing, _
            Nothing)

        svDelegate.EndInvoke(svAsyncres)

        Dim tmp As Integer = obj.getValue()

        Console.WriteLine(tmp)
        Dim finished As DateTime = System.DateTime.Now
        Dim duration As TimeSpan = finished.Subtract(start)


        
    End Sub
End Module


///////////////////////////////////server.vb
// vbc /target:exe  /r:general.dll server.vb
Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels.Http
Imports System.Runtime.Remoting.Channels
Imports System.Threading


Class MyRemoteObject
    Inherits BaseRemoteObject
    Private myvalue As Integer

    Public Sub New()
    End Sub

    Public Overrides Sub setValue(ByVal newval As Integer)
        Console.WriteLine("old {0} new {1}", myvalue, newval)

        Thread.Sleep(5000)

        myvalue = newval
    End Sub


    Public Overrides Function getValue() As Integer
        Return myvalue
    End Function

End Class

Module ServerStartup

    Sub Main()
        Dim chnl As New HttpChannel(1234)
        ChannelServices.RegisterChannel(chnl,false)

        RemotingConfiguration.RegisterWellKnownServiceType( _
            GetType(MyRemoteObject), "MyRemoteObject.soap", _
            WellKnownObjectMode.Singleton)

        Console.ReadLine()
    End Sub
End Module


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend