How do you return a user defined type from a WCF service?
.net, user-defined-types, wcf, web-services
Solution
Just to second Yossi's/Rich's thoughts:
- yes, you can add a reference to the shared dll (rather than using the generated proxy class)
- yes, it defeats a lot of the intent of data-contracts, and if any kind of custom serialization is happening, you may have issues extending your service
I have gone down this road before, and in some ways wish I hadn't. Re extensibility / custom serialization - you have to be very careful. A bit easier if you use a pre-rolled serializer such as protobuf-net (which can integrate directly into WCF, and which is designed with extensibility in mind), but not easy.
Actually, one advantage of sharing the classes is that it makes it a bit easier to test: since you have the same `IFoo` everywhere, you can mock that `IFoo` with reasonable chance of success. It is harder to mock when the proxy gets involved (as you change more moving parts between the test code and the production code).
Problem
I have a WCF service hosted in IIS. The intention is for clients to make a call and receive a custom class that is defined in another project/dll. I have generated a service client using the svcutil.exe. The problem is this autogenerated client contains a new partial / proxy definition for the class I am trying to return from the service. It now throws a conversion error between my original custom class and the new partial definition at compile time. So how do you return user defined types from a WCF service? Advice appreciated.