views:

261

answers:

2

Hi,
I'm writing a few WCF services that expose data being retrieved from the Entity Framework, and in following Domain Driven Design patterns, I've got a repository per aggregate. The concrete example is a collection of questions and answers. There is a QuestionRepository and an AnswerRepository.

I'm running into problems when I want to pass items from the QuestionRepository to the AnswerRepository. Since both services are backed by the same data model, they are using the same logical items, but svcutil puts them in two different name spaces and treats them as completely different services.

Is there any way to get around this problem? Is it possible to host two ServiceContracts in the same service? Is it possible to have WCF reuse the data contracts generated from another service?

Thanks, Roy

A: 

I believe that one thing that might help you is to take a look at the DataContractAttribute class that let you specify the name and namespace for the serialization.

That said, if you are using the same logical items, it should be enough to make them compatible across services.

All depends on the WSDL generated by the MEX endpoint.

Paulo Santos
+2  A: 

You should definitely be able to have a common DataContract used by two separate services, IQuestionService and IAnswerService.

Do you own both ends of the wire, e.g. both client and server? Both .NET/WCF ? In that case, you could e.g. put your DataContract and all your common interfaces into a single, separate assembly, and share that assembly between the two services, both on the server and on the client.

On the client, if you run svcutil, you could tell it to use types from that given common assembly, e.g. tell it NOT to re-create your Question and Answer data types, but use those from your assembly. Check out the /reference (or /r) parameter of svcutil.

svcutil (your WSDL) /r (your common assembly here) ......

Or the other option would be to skip svcutil all together and create your ChannelFactory etc. yourself and instantiate your client 100% manually, without service reference etc.

ChannelFactory<IQuestion> cFac =
   new ChannelFactory<IQuestion>("ConfigName");
IQuestion proxy = cFac.CreateChannel();

and then use the proxy object like the one you use now generated by svcutil.

That of course only works if you own both ends of the wire.

Marc

marc_s