开发者

How to share domain classes and business rules between client and server like in RIA Services by writing them only once

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开发者_Python百科). 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?


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();
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜