2

We have two assemblies, DataContracts and Core. We are currently using svcutil to generate our DataContracts, while referencing Core. We've got a couple of extension methods on different enum types that would be useful on the client side.

Is there any way to get svcutil to include these extension methods into our generated proxies file?

AlexCuse
  • 18,008
  • 5
  • 42
  • 51
  • We ended up writing a simple ruby script that runs after svcutil to transform namespaces appropriately and inject the extension classes into our proxies file. Not the most elegant solution, but it works well enough. – AlexCuse Feb 05 '12 at 19:49

2 Answers2

1

Any methods that you want exposed you need to have as part of the operational contract. I don't know of any other way to expose the metadata in the WSDL without learning more about how the WSDLImporter works. Irregardless - Metadata is only contracts - you can't share operations/behaviors in your metadata. The only way to share method behaviors (your extensions) is to include them in the shared contract/core assembly or expose them as operation contracts.

SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
  • I figured as much. I might try adding a step to pull out the extension methods, change namespace and inject into our proxies file after its been generated. Defining the code in 2 places is better than 50, but still feels risky. – AlexCuse Jan 25 '12 at 01:37
0

The classes generated by svcutil are partial. Therefore the functionality of those classes can be split in multiple files. One file is the one generated by the svcutil with the functionality exposed by the service. Other files could contain the functionality you want to append, which is not part of the data contract.

More info on partial classes Partial Classes and Methods (C# Programming Guide) on MSDN

  • Yeah I know it's not part of the contract. We leverage the partial classes pretty heavily for client-side logic, but don't want to have to maintain two parallel copies of the same methods (these extensions are used on the server side also). The ruby script we added to our build process is doing a good enough job injecting our extensions into the proxies file, even if it is a little weird. – AlexCuse Jul 03 '12 at 13:14