Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 1st, 2007, 10:25 PM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default [Urgent] Server Side custom exception

Hi all,

I had created a Remoting Custom Exception that inherits from System.Exception.

Below is the coding that i wrote,

// Remoting Custom Exception

[Serializable]
   public class DbActionException : Exception
   {
       public DbActionException() : base()
       { }
       public DbActionException(string message)
           : base(message)
       { }
       public DbActionException(string message, System.Exception inner)
           : base(message, inner)
       { }
       protected DbActionException(SerializationInfo info, StreamingContext
context)
           : base(info, context)
       { }
       public override void GetObjectData(SerializationInfo info,
StreamingContext context)
       {
           base.GetObjectData(info, context);
       }
   }

// in DAL Layer

try{ //Do somethings }
catch(Exception ex)
{
  throw new DbActionException(ex.ToString());
}

// in Service Layer

try{ //Do somethings }
catch(DbActionException ex)
{
  throw ex;
}

// in UI Layer

try{ //Do somethings }
catch(DbActionException ex)
{
 ExceptionPolicy.HandleException(ex, "LoggingPolicy")
}

The problem is - in my UI layer (client side), it requests for server layer's
assembly. If i didn't add the service layer assembly, the error of Could not
load file or assembly <name>, Version=<version>... or one of its dependencies.
The system cannot find the file specified.":"<name>, Version=<version>...
If i added the service layer assembly, this error won't occur and the
exception is succeed to log. But as everyone knows that it is make sense that
service layer dll cannot be added at UI layer right?

Do anyone have the solution?
Thanks for any reply!
 
Old April 1st, 2007, 11:53 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

While I'm not entirely sure I understand the question, I'll offer this explanation:

In order for remoting to function, you need to have the remoted objects available at both ends of the communications. If the objects you are remoting live in your server layer dll, then yes, you need to have that server layer DLL wherever the UI is calling it. The difference is that the code in the actual server layer DLL at the UI end is not executing. It's executing at the server, thru the remoting channel. However, the UI is using the server layer DLL as the reference for the class definitions.

Often, this kind of scenario is simplified by creating an assembly of very simple classes, or even just of interfaces. The types that are remoted are the interfaces themselves instead of the classes that implement those interfaces. This benefits you two-fold: A) you don't need to distribute your logic in an assembly just so the consumer (UI in your case) has it for the necessary reference, and also B) by exposing interfaces as the remoted object, you can much more easily change the actual class that is instantiated without breaking the consumers of the remoted objects.

-Peter
 
Old April 3rd, 2007, 04:11 AM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

how about i write my prob in this way...

I created a Custom Exception that inherits from ApplicationException.
This is declared in an assembly that is on the server side.

I made this class serializable and overloaded all the necessary
constructors for the serialization to work. The problem is that rigth
now I'm forced to have the assembly from the server side present on the
client side. If not will get an error saying:
"Cannot find the assembly <name>, Version=<version> ......."

I cannot have this assembly on the client side, and I would prefer not
have to create a DLL only for an exception. Is there any way to get
this custom exception to work without having to carry over the server
side code?

I was hoping that Remoting with Serialization would remove the need to
have the server side DLL on the client. any more advice or solution for this problem??

 
Old April 3rd, 2007, 07:44 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Remoting requires the presence of the assembly that contains the class to be remoted. That's how it works. Even though the actual code inside the class doesn't get executed on the consumer side (client), the class needs to be there. This is the idea behind using a library of interfaces as the distributed library. The remoted objects are interfaces instead of classes. However, in the case of an exception, you'll need to put it in the library that is used at the consumer end.

If you want to keep all the server side entities masked from the consuming side then you might want to try web services instead of remoting. The web service will expose what it needs, and the consumer side will have a proxy that creates stub entities to mirror what is exposed through the service(s). This is the only way I see of doing what you are asking.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Converting Client-side to Server-side Code kwilliams ASP.NET 2.0 Professional 1 November 21st, 2007 05:25 PM
Firing server side events at client side codes mehdi62b ASP.NET 1.0 and 1.1 Basics 6 May 18th, 2005 09:11 AM
sharing a server-side variable with client-side pigtail Javascript How-To 6 November 4th, 2004 02:01 AM
Accessing Server Side Data on Client Side steve456 Classic ASP Professional 3 October 15th, 2003 02:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.