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.
精彩评论