all groups > dotnet remoting > june 2007 >
You're in the

dotnet remoting

group:

Filter exceptions before marshall


Filter exceptions before marshall chad
6/13/2007 12:00:00 AM
dotnet remoting:
Hi,

We have some services that we start up using RemotingServices.Marshall(..).
We need to filter exceptions generated on the server before they get serialized
and marshaled to clients. Where can we hook into those exceptions so we can
decide whether to pass a new friendly exception or the actual exception that
occurred.

Thanks,

Re: Filter exceptions before marshall Bram
7/3/2007 7:12:18 AM
Hi Chad,

The beauty of .NET remoting is that it's almost entirely transparent.
Once you have a remoted object, you can use it like a local object.
However, the drawback in your case is that it's almost entirely
transparent. So in your case, the best thing you can probably do is
create a wrapper method that catches the relevant exceptions (or all
exceptions, if you are feling lucky) like this:

[Serializable()]
public class MyClass : MarshallByReferenceObject {
public void MyMethod() {
// Do stuff that might generate an exception
// ....
// ....
}

public void MyMethodWrapper() {
try {
MyMethod();
}
catch(ArgumentException) {
// Do nothing, just catch exception
}
}
}

The pitfall, of course is: There is a reason these exceptions are
thrown. Your application state probably won't be what you think it is.
So you might consider catching the exceptions on the client side and
react appropriately.

Regards
Bram

[quoted text, click to view]

Re: Filter exceptions before marshall chad
7/5/2007 11:01:34 AM
Hello Bram,

Thanks for the reply.... eek, that's what we were afraid of.

We're using the objects in a non-remoting as well as a remoting environment.
So like you mentioned it's a completely seamless approach with the big drawback
of server errors in the remoted environment being propagated back to the
client. I would hate to clutter the code with wrappers but it seems like
it's the only way.

The whole concept seems so simple and it's hard to believe there's no hook
inside the remoting layer that we can use for processing before information
is sent back to the client.

Anyone aware if WCF has an elegant solution to overcome this problem?

Regards,

[quoted text, click to view]

Re: Filter exceptions before marshall Chad
7/5/2007 1:08:44 PM
Hello ged@nospam.here,

From the sounds of it we will have the same problem then. So we'll always
have to do :

try
{
doSomething();
}
catch(Exception ex)
{
if(N-Tier Mode)
{
LogError(blah);
throw new ServerException("Sorry dude the server wasn't able to process......
");
}
else
throw;
}

Can this really be the only way? Please someone, tell me there's an easier
way than introducing all this clutter.

Cheers,



[quoted text, click to view]

Re: Filter exceptions before marshall ged NO[at]SPAM nospam.here
7/5/2007 1:10:41 PM
AFAIK, WCF applies the remoting steps regardless of the location of the
client or the server. i.e. same machine or across a LAN/WAN.
So, no need for you to detect which way you are using your object, it will
always be the same.

Think of it ALWAYS being across machine boundaries and WCF will handle the
rest for you.

Does that make sense ?



[quoted text, click to view]
Re: Filter exceptions before marshall <Ged Moretta>
7/5/2007 5:04:19 PM
Hi Chad

Sorry. What I failed to mention was that in WCF you can define multiple
endpoints for a server object.
So, the object can support a namedPipe protocol for local objects, a Tcp
protocol for intra-network comms and a HTTP protocol for WWW comms.
This is all defined in the config file. Then, each client has in its config
file, the correct service definition that it needs to use. The
implementation inside the service/client is the same where ever it is
deployed and WCF manages the comms for you seamlessly. Compared to .Net
Remoting 2.0, WCF is completely seamless.

Maybe I'm not understanding your issue completely correct. If not, I
apologize.

But, to get some more information on WCF, (and see if it does suit your
needs better) I recommend reading "Programming WCF Services" by Juval Lowy.

HTH

Ged


[quoted text, click to view]
AddThis Social Bookmark Button