Thursday, October 06, 2005

[Opf3] Opf3 questions...

I got this question today:

I am developing a product in C# that will use ASP.NET, Windows forms smart client, and ADO.NET.
I am also using .NET 2.0 beta 2.
I have VistaDB and also want to use SQL Server 2005, or maybe other databases in the future.
You use attributes in the persistent classes. How does this work in a multi-tiered environment where remoting or web services is used to move business objects across the network? I don’t want my remote client tier to reference any of the data access layer logic. I want all that on the server side.


The answer was the following:
On you find a “Tutorial & Samples” zip file to download. This file contains a sample on how Opf3 works with Webservices and an example on how it works with .NET Remoting. For .NET Remoting you have to implement (which is not shown in the example) an interface for each persistent object. Those interfaces are then shared with the client. The interfaces do not contain the Attributes.

If you are using Webservices .NET generates a proxy class on the client side that does not contain any attributes. When sending the object to the client it is transformed to the proxy object. When sending it back it is again transformed to the original object. The proxy object does not contain any attributes. The original object (on the server) contains the attributes… With webservices you have also to consider to put the [XmlIgnore] attribute on properties that hold related objects. If not the .NET XmlSerializer will also serialize that property, which means all related objects are send to the client. If the related objects contain other related objects those will be also serialized and so forth... But this is an issue of Webservices and the .NET XmlSerializer. For .NET Remoting you don’t have to bother about this. When you request the related objects the client asks the server for the objects and they are transmitted to the client (on demand).

Another important thing you have to do is implementing the ISelfContainingObject interface to every persistent object. This interface (look also in the documentation of Opf3 – found in the zip of the Opf3 Demo or on the web page: allows the persistent object to hold its own state (by state is meant Loaded, Inserted, Deleted, Update and the Concurrency Information). Without implementing this interface the ObjectContext instance (used to load or persistet the object) holds the state for the object. If you remote (over .NET Remoting or via Webservice) an object the object leaves the AppDomain of the ObjectContext and after a little while the state information is deleted by the ObjectContext (as the class “thinks” the object does no longer exist – the original object is then also deleted by the GarbageCollector of .NET as it really does no longer exist in the current AppDomain). By implementing the ISelfContainingObject interface the class holds the state information by itself. You remote the object and the state information is carried within the object...


Post a Comment

<< Home