I’ve used Visual Studio’s Add Service Reference feature to add a service (actually it is a workflow service, created in WF4 RC1, but I don’t think this makes any difference), and it also added the DataContracts that the service uses. At first this seemed fine, because All I’ve had in the DataContracts was simply properties, with no implementations. But now I’ve added code in the constructor of one data contracts that initializes creates an instance of one of the properties that exposes a list of other DCs, and when I’ve updated the service reference via VS (2010 RC1), the implementation was not updated.
What should I do? Should I use my DCs instead of the ones created by VS or should I use the ones VS created? I’ve noticed that the properties in the VS-generated DCs contain some additional logic for checking equality in the setters and they also implement some interfaces too (like IExtensibleDataObject and INotifyPropertyChanged) which might get handy I guess in the future (I’m not knowledgeable at WCF).
Thank you for your time folks,
Avi
Yes, that is the way it works – and that’s really the only way it can work if you think about it, when you have a separate, autonomous service.
If you control both ends of the wire, e.g. you write both the service and the client, you can of course do a few more things:
you can put all your service and data contracts into a separate assembly,
MyContracts, and then add a reference to that assembly both on the service as well as the client sidewhen you do that, Visual Studio will not re-create those types that it finds in that referenced assembly, but it will just use those
But you need to be extremely careful: Data Contract should only ever contain data – never any behavior! So be extra careful not to put any behavior-based stuff into your DataContracts. The message going between client and service in WCF is a pure text-based serialized message – you cannot convey any code between the two, really – keep that in mind!