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
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
QuestionandAnswerdata types, but use those from your assembly. Check out the/reference(or/r) parameter of svcutil.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.
and then use the
proxyobject like the one you use now generated by svcutil.That of course only works if you own both ends of the wire.
Marc