Re: How to use event in Remoting (VB2005)?

Tech-Archive recommends: Speed Up your PC by fixing your registry



Hi,

When the server tries to deserialize the delegate that you have supplied as a handler for the result event the framework requires
the real method to which the delegate 'points' (not an interface). Not only must the server reference the assembly which contains
the Type that contains the event handler method on the client, but the method itself must be publicly visible.

I've seen recommendations to use an abstract class (MustInherit in VB?) and a public method to provide the contract for the event
handler. You then must implement this contract on the client to handle the event and reference the assembly that contains the
abstract class on the server.

Please forgive my lousy VB:

{MySharedRemotingAsm.dll}

Public MustInherit Class ServerEventHandlersBase
Public MustInherit Sub ResultEventHandler(ByVal sender As Object, ByVal e As EventArgs)
End Sub?
End Class

{Client.dll} references {MySharedRemotingAsm.dll}

Public Class ServerEventHandlers _
Inherits ServerEventHandlersBase
Public ResultEventHandler(ByVal sender As Object, ByVal e As EventArgs)
' TODO: Handle Event
End Sub
End Class

{Server.dll} references {MySharedRemotingAsm.dll}

' You don't need to do anything special here since the
' framework will be able to handle the delegate deserialization
' as long as it can locate the reference to MySharedRemotingAsm.dll
[...]

HTH

--
Dave Sexton

"Eternal Snow" <allen_st_clair@xxxxxxx> wrote in message news:81A9A26C-B1D0-4298-973C-93B27A6D3703@xxxxxxxxxxxxxxxx
I wanna create a remoting solution to transfer a event from server to client. My code are below:

////// Interface /////

Public Interface ISample
Event result(ByVal sum As Integer)
Sub sum(ByVal a As Integer, ByVal b As Integer)
End Interface

///// Interface End ///

///// Server /////

Public Class Class_server
Inherits MarshalByRefObject
Implements [Interface].ISample

Public Event result(ByVal sum As Integer) Implements [Interface].ISample.result

Public Sub sum(ByVal a As Integer, ByVal b As Integer) Implements [Interface].ISample.sum
RaiseEvent result(a + b)
End Sub
End Class

Imports System.Runtime
Module Module1

Sub Main()
Dim dict As New System.Collections.Hashtable
dict("port") = 13000

Dim provider As New Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider
provider.TypeFilterLevel = Runtime.Serialization.Formatters.TypeFilterLevel.Full

Dim ChannelHttp As New System.Runtime.Remoting.Channels.Http.HttpChannel(dict, Nothing, provider)
Remoting.Channels.ChannelServices.RegisterChannel(ChannelHttp, False)

Remoting.RemotingConfiguration.RegisterWellKnownServiceType(GetType(Class_server), "sum2",
Remoting.WellKnownObjectMode.Singleton)

Console.WriteLine("Service started. Press Enter to quit.")
Console.ReadLine()
End Sub

End Module

///// Server End /////

///// Client /////

Module Module1

Sub Main()
Dim a As Integer = 1, b As Integer = 2

Dim dict As New System.Collections.Hashtable
dict.Add("port", 0)

Dim provider As New Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider
provider.TypeFilterLevel = Runtime.Serialization.Formatters.TypeFilterLevel.Full

Dim ChannelHttp As New Runtime.Remoting.Channels.Http.HttpChannel(dict, Nothing, provider)
Runtime.Remoting.Channels.ChannelServices.RegisterChannel(ChannelHttp, False)

Dim obj As [Interface].ISample = Activator.GetObject(GetType([Interface].ISample), "http://localhost:13000/sum2";)

If obj Is Nothing Then
MsgBox("error")
End
End If
AddHandler obj.result, AddressOf Result
' Error Here
' System.ArgumentNullException: No message was deserialized prior to calling the DispatchChannelSink.
' Parameter name: requestMsg
' at System.Runtime.'oting.Channels.DispatchChannelSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage
requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders,
Stream& responseStream)
' at System.Runtime.'oting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage
requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders,
Stream& responseStream)
' at System.Runtime.'oting.Channels.Http.HttpServerTransportSink.ServiceRequest(Object state)
' at System.Runtime.'oting.Channels.SocketHandler.ProcessRequestNow()

obj.sum(1, 2)
Console.ReadLine()
End Sub

Sub Result(ByVal sum As Integer)
Console.WriteLine(sum)
End Sub

End Module

///// Client End /////

How can I fix it? thanks.


.



Relevant Pages

  • Re: Cannot create channel sink
    ... Client App.config ... I am runing client application and server appliaction ... sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream ... requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Cannot create channel sink
    ... Client App.config ... I am runing client application and server appliaction ... sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream ... requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Cannot create channel sink
    ... Client App.config ... I am runing client application and server appliaction ... sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream ... requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Binary of HTTP config issues
    ... > client appconfig. ... > payload of the traffic between client and server it is a soap envelope so ... >>> hannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders ... >>> requestHeaders, Stream requestStream, IMessage& responseMsg, ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: How to use event in Remoting (VB2005)?
    ... Public Sub sum ... Dim dict As New System.Collections.Hashtable ... sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream ... requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, ...
    (microsoft.public.dotnet.framework.remoting)