PDA

View Full Version : Passing an object to a remote service


oz_ko
10-28-2006, 01:00 AM
Hi all,
I'm having some problems passing an object to a remote service and getting a
SerializationException "Unable to find assembly" (the client assembly).

Everything is done through interfaces so I don't know why this should be the case. I have three projects: Interfaces, Client, and Server.
There should be no dependency on the client assembly in the server so I don't know why it would be looking for it. Any ideas?


Interfaces:

namespace Interfaces
{
public interface IHelloSayer
{
String GetString();
}
public interface IServer
{
String SayHello(IHelloSayer helloSayer);
}
}



Client:

//HelloSayer is marked serializable
IHelloSayer helloSayer = (IHelloSayer) new HelloSayer("Hello");
IServer server = (IServer)ctx.GetObject("server");
String response = server.SayHello( helloSayer );


Server:

namespace Server
{
public class Server : IServer
{
public String SayHello(IHelloSayer helloSayer)
{
return helloSayer.GetString();
}
}
}

oz_ko
10-29-2006, 11:59 PM
I hope this makes sense but here goes anyway:

I've been trying to pass an object to a remote server (see post above) from the client assembly but I think this requires the server assembly to have access to the client assembly. Does anyone know if this is correct?

Obviously I don't want the server assembly to access to the client assembly. The only solution I can see is that the client instantiates an object in the Interfaces assembly and passes it to pass to the server assembly. From what I can gather, the server needs the concrete class' assembly, not just the interface definition.

Can anyone confirm this or is there a better way to implement passing an object from client to server?

Also, if the object passed to the server (in the Interfaces assembly) references some .Net framework objects and the .Net framework versions are not identical will this cause any issues? Would there be an issue between .Net 2.0 and 1.1, and would there be problems between older and newer versions of the 2.0 framework?


Thanks
Oz

Bruno Baia
10-30-2006, 02:10 AM
Hi,


I've been trying to pass an object to a remote server (see post above) from the client assembly but I think this requires the server assembly to have access to the client assembly. Does anyone know if this is correct?

yep, and ass generally required with a .NET Remoting application, the arguments to your service methods should be Serializable. An interface cannot be serializable.

I've updated the Calculator sample (get latest code from CVS or wait next nightly build), adding solution/projects for VS2005 to support .NET 2.0.
I also added a domain object to pass between client and server.
As you guess, this object needs to be in the common assembly used from both client and server.


public interface ICalculator
{
int Add(int n1, int n2);

int Substract(int n1, int n2);

DivisionResult Divide(int n1, int n2);

int Multiply(int n1, int n2);
}

[Serializable]
public class DivisionResult
{
private int _quotient = 0;
private int _rest = 0;

public int Quotient
{
get { return _quotient; }
set { _quotient = value; }
}

public int Rest
{
get { return _rest; }
set { _rest = value; }
}
}



Cheers,
Bruno

oz_ko
10-31-2006, 02:18 AM
Thanks Bruno.

Oz