Hi all,
I need to crate a two way communication between client and server using Remoting. I have a Dll file in which I keep two interfaces. Let's call them IA and IB. IA is implemented by the server's class A and IB is implemented by the client's class B.
The main goal is to send an object of type IB (an instance of B) that is created on the client, through a method on an object of type IA (an instance of A) theat is created by the server.
Well, the server exposes A using Remoting and the client receives it. The client can call methods and properties on A (easy, because it knows the interface IA) and even can pass the B object throgh a certain method. BUT, whenever I try to call a method on B (using the IB interface) I fail.
What am I doing wrong?
Here are Interfaces.cs, Client.cs, Server.cs and error description:
**********************Inte
rfaces****
**********
*******
using System;
namespace Interfaces
{
public interface IA
{
string Name
{
get;
}
void SetClient(IB b);
}
public interface IB
{
string Name
{
get;
}
}
}
**************************
**********
**********
*******
************************Se
rver******
**********
******
using System;
using System.Runtime.Remoting;
using Interfaces;
namespace Server
{
[Serializable]
class A: MarshalByRefObject, IA
{
[STAThread]
static void Main(string[] args)
{
RemotingConfiguration.Conf
igure("Rem
otingListe
ner.config
");
Console.ReadLine();
}
#region IA Members
public string Name
{
get { return "Server"; }
}
public void SetClient(IB b)
{
Console.WriteLine(b.Name);
}
#endregion
}
}
**************************
**********
**********
*******
************************Cl
ient******
**********
******
using System;
using System.Runtime.Remoting;
using Interfaces;
namespace Client
{
[Serializable]
class B: MarshalByRefObject, IB
{
[STAThread]
static void Main(string[] args)
{
RemotingConfiguration.Conf
igure("Cli
entSideReg
istrar.con
fig");
IA a = (IA)Activator.GetObject(ty
peof(IA), "
http://localhost:8989/A.rem");
B b = new B();
a.SetClient(b);
Console.ReadLine();
}
#region IB Members
public string Name
{
get
{
return "Client";
}
}
#endregion
}
}
**************************
**********
**********
*******
************************Er
ror description***************
*******
An unhandled exception of type 'System.Runtime.Remoting.R
emotingExc
eption' occurred in mscorlib.dll
Additional information: System.ArgumentNullExcepti
on: No message was deserialized prior to calling the DispatchChannelSink.
Parameter name: requestMsg
at System.Runtime.Remoting.Ch
annels.Dis
patchChann
elSink.Pro
cessMessag
e(IServerC
hannelSink
Stack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)
at System.Runtime.Remoting.Ch
annels.Bin
aryServerF
ormatterSi
nk.Process
Message(IS
erverChann
elSinkStac
k sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)
at System.Runtime.Remoting.Ch
annels.Htt
p.HttpServ
erTranspor
tSink.Serv
iceRequest
(Object state)
at System.Runtime.Remoting.Ch
annels.Soc
ketHandler
.ProcessRe
questNow()
**************************
**********
**********
**********
**********
*
Ophir.