[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.remoting

Interface based serialization

noelwatson

9/1/2004 12:51:00 PM

I am attempting to get the example posted on csharphelp to work
http://www.csharphelp.com/archives/archi...

The example executes fine, but when checking whether the call

IResume aResume = resService.GetResume();

is passed copied locally to the machine (ByVal), I find that it has
been passed byRef. My check for this is adding a property returning
Environment.MachineName - calling this new property returns the name
of the remote machine.
My understanding is that adding the [Serializable] attribute to the
class Resume would make it serializable. However, it would appear that
adding MarshalByRefObject overrides this and makes it ByRef. Removing
MarshalByRefObject cause the application to fall over as it cannot
find the server assembly - something that can be solved by adding a
reference in Client - obviously this removes the benefits of
Interfaces.

Thanks for reading

Noel
3 Answers

Ken Kolda

9/1/2004 3:40:00 PM

0

You are correct that if the class derives from MarshalByRefObject then it
will be remoted by ref (even if also marked as serializable). You're also
right that if the class is only serializable then the client must have the
full class implementation available to it. Those are the rules, so you need
to figure out how to build your app to work within them.

What I usually do is define a set of data classes (e.g. a InventoryItem or a
Resume object) -- these are purely data classes which are serializable and
are implemented in the same assembly as my remoting interfaces. Essentially,
they are part of the "interface" between my clients and my server.

My MBRO classes are essential business logic classes, e.g. for
getting/saving the data objects, for performing various operations, etc.
These business processes aren't needed on the client (and, really, the
server should control them for security/consistency purposes), so only the
interfaces are exposed to them.

Ken


"Noel Watson" <noelwatson@bristol94.freeserve.co.uk> wrote in message
news:84554d21.0409010451.31e87813@posting.google.com...
> I am attempting to get the example posted on csharphelp to work
> http://www.csharphelp.com/archives/archi...
>
> The example executes fine, but when checking whether the call
>
> IResume aResume = resService.GetResume();
>
> is passed copied locally to the machine (ByVal), I find that it has
> been passed byRef. My check for this is adding a property returning
> Environment.MachineName - calling this new property returns the name
> of the remote machine.
> My understanding is that adding the [Serializable] attribute to the
> class Resume would make it serializable. However, it would appear that
> adding MarshalByRefObject overrides this and makes it ByRef. Removing
> MarshalByRefObject cause the application to fall over as it cannot
> find the server assembly - something that can be solved by adding a
> reference in Client - obviously this removes the benefits of
> Interfaces.
>
> Thanks for reading
>
> Noel


noelwatson

9/2/2004 8:46:00 AM

0

Thanks for the response Ken,

One thing is still puzzling me. Are you not taking away some of the
advantages of interface based remoting (not deploying server code to
the client) by having to place your serializable objects on the
client's machine. I've read the two main books on Remoting (Ingo's and
MSPress) and I don't believe either of them mentioned this
requirement.

Noel

retoro

9/2/2004 2:26:00 PM

0

I don't think it takes away from it -- in fact, it makes perfect sense to
me. From a technical point of view, it's clear that if the client has its
own local copy of the object then it must also have the implementation code
for that object. Otherwise, when you call a property or method on the
object, how would the client know what to do? For MBRO objects, it doesn't
need the implementation since the call is forwarded to the server -- all it
needs is to know the property arguments and return value. But for
marshal-by-value objects, complete knowledge of the object is required.

As I mentioned before, from a logical point of view I think of serializable
types as part of the client/server interface. They provide a means for
passing data objects back and forth. Business logic classes should generally
by MBR. Because they're part of the "interface", having both client and
server know them is completely reasonable/expected.

Ken


"Noel Watson" <noelwatson@bristol94.freeserve.co.uk> wrote in message
news:84554d21.0409020046.334af4e1@posting.google.com...
> Thanks for the response Ken,
>
> One thing is still puzzling me. Are you not taking away some of the
> advantages of interface based remoting (not deploying server code to
> the client) by having to place your serializable objects on the
> client's machine. I've read the two main books on Remoting (Ingo's and
> MSPress) and I don't believe either of them mentioned this
> requirement.
>
> Noel