3

When I use svcutil or some other proxy generator it creates appropriate classes in client. I wonder what is the best way to store this classes to avoid conflicts.

  • In some other "Common" project and remove generated classes from proxy?
  • Or just use original classes in service and theese duplicated in proxy?
Saint
  • 5,397
  • 22
  • 63
  • 107
  • I don't understand what your question is, can you please explain a bit more detailed? Do you want to avoid using the generated classes? Do you get conflicts during compilation because you also reference the assembly that the original, server-side, classes belong to? – Anders Abel Aug 01 '12 at 11:29
  • @AndersAbel Yes, and I wonder should I have access to original only in server and duplicate this clases with svcutil? Or provide access from client and server side to original and remove generated classes – Saint Aug 01 '12 at 11:32

1 Answers1

3

There are two ways to handle the code for service and data contract classes WCF clients.

  • Generate everything using svcutil.exe. Don't have any kind of reference from your client project to the service assembly. Just use the classes generated by svcutil.
  • Reference the assemblies containing the types directly. I sometimes use a separate assembly for my DTO classes, that is references from both the client and the server. When generating the client code with svcutil, use the /reference:<file path> option to tell svcutil to reuse the types from an existing assembly instead of regenerating them.

If you reference the origin assembly, without passing it with /reference to svcutil you'll end up with a mess of conflicts. I guess that's what happened to you.

Anders Abel
  • 67,989
  • 17
  • 150
  • 217
  • Yes, I know where is my problem now. I only wonder which way is "better" – Saint Aug 01 '12 at 11:40
  • That depends on your requirements. If you have e.g. data validation code in your DTOs it's an advantage to have that functionality available on the client side too. If you are data binding on the client, you can probably benefit from the `INotifyPropertyChange` implementation you get for free by `svcutil`. – Anders Abel Aug 01 '12 at 11:42