Search code examples
c#wcfdatacontract

Use other DataContract classes than the generated one's


Our customer sent us a WSDL file for their web service API. We used Visual Studio's "Add Service Reference" to consume it.

However: we only want to generate a service proxy, not the data contract classes. We want to reuse classes we already have within a referenced assembly.

  • How to instruct "Add Service Reference" to not create Data Contract classes?
  • ...or how to instruct WCF to use our Data Contract classes from the referenced assembly instead?

Solution

  • This comes down to the following options on the Advanced... part of "Add Service Reference":

    enter image description here

    which also map to the /r / /reference option in svcutil.exe.

    This defaults to enabled, so if it isn't working: there's a good chance your types are not exact matches. The easiest way to ensure exact matches is to reference the same library dll from both projects, or worst case the same .cs file (a dll reference would be preferable, IMO). The data-contract namespace and name are the usual culprits here, and must match exactly (as must the members).