views:

312

answers:

2

In an ASP.NET - WCF application I want to share domain classes and business rules between client and server without rewriting them, just like in Silverlight RIA Services. Collecting these in one assembly and referencing this from client and server can solve the problem, but how: by adding service refence to client will generate these classes in client proxy, without any behaviour (methods). How can I achive this?

NOTE: RIA Services will not be used.

EDIT: After some Googling I came across CSLA.NET. Can it solve this issue?

+1  A: 

You avoid using the client proxy altogether.

So first off, put your contract classes into a shared assembly, and add a reference to the project in both the server and client programs. In the client you can then use ChannelFactory to create a connection to the WCF service and exchange data; something like

ChannelFactory<IServiceContract> factory;
factory = new ChannelFactory<IServiceContract>("");

IServiceContract proxy = factory.CreateChannel();
using(proxy as IDisposable)
{
   proxy.MyMethod();
}
blowdart
hi blowdart, by not adding proxy class we are deprived of asynchronus methods and other utulities if there are any. i will update this thread as soon as i find any solution to the problem.
arch stanton
You could of course wrap the calls in background worker threads or massage the async behaviour in other ways.
blowdart
@arch, you can create a sub interface of your serivce interface on the cleint and add the "BeginXXX" methods your self"
Ian Ringrose
+1  A: 

Ok here is how I've done it: As blowdart said I put all the domain code that I want to share between server and client into a seperate assembly. Then I had both server and client referencing to this shared assembly. Then added service reference to client, with one exception: In add service reference dialog there is a button "Advanced". There I have checked reuse types in referenced assemblies. This way I had all proxy goodies, asynchronous method calls etc., generated for me.

arch stanton
+1 for extensive answer
Gorgen