Say I have a web project which uses a WCF service for behind-the-scenes processing, and an MVC 2 project handling web-requests (I guess this will be the WCF client). The WCF service generates data and deals with pre-generated data (the processing will likely happen asynchronously). These two things are separate projects in the same solution in visual studio.
Now, I’m not sure where to put the data structures representing stuff that the service generates, and stuff that the client needs to process and send to users’ browsers. Currently they’re all in the service’s interface (endpoint interface? Not sure what it’s called exactly) marked with [DataContract] (not sure what that does yet). But, since the MVC app is in a separate project, I’d have to re-define all the data structures there — is that necessary? Should I be putting these structures elsewhere in the solution? The interface is getting pretty full of class definitions — am I able to make some sort of shared resource containing the shared data structures between the projects? What about the [DataContract] part — do I still need to stuff that in the interface somehow if the classes are defined somewhere else?
Apologies if I’m not quite making sense or being very vague. I’ve never used these Microsoft technologies before so I’m still pretty lost. I’m just learning as I go.
Put your data objects in another, separate project (select Class Library when creating it) and reference them from both WCF and MVC2 (duplication aside, I don’t think it will be possible to get it to work otherwise).
[DataContract]has to be used to decorate the data object classes, no matter where they are.I am not sure what you mean when saying “What about the [DataContract] part — do I still need to stuff that in the interface somehow”… can you provide some sample code?
For reference, here’s some code from a project I worked on in the past:
This is in project
Server.Contracts:This is also in
Server.Contracts:This project is referenced from these two other projects, among others:
ILogServiceis implemented)