3

I have a WCF service with a mex endpoint for metadata. I use the SvcUtil through visual studio to generate client data contracts code (C#) while the service is running. SvcUtil adds KnownType attributes for the inherited and referenced types. I have a custom data contract resolver and have no use for these Known Types. How can I make SvcUtil or the WSDL Importer not tag all these types with KnownType attributes? My worst case scenario is to go through the file after code generation and remove these attributes, but I am hoping there is a cleaner way to do this.

LadderLogic
  • 1,090
  • 9
  • 17
  • Are you using the [ServiceKnownTypeAttribute](https://learn.microsoft.com/en-us/dotnet/api/system.servicemodel.serviceknowntypeattribute) in your WCF Source Code? – RobV8R Aug 20 '18 at 21:25
  • 1
    Yes, I am using the ServiceKnownTypeAttribute on the service side – LadderLogic Aug 20 '18 at 21:37
  • Normally, I would recommend dropping the server-side `ServiceKnownTypeAttribute`s. In this case, I'm uncertain what affect that would have. I've provided an alternate solution below. – RobV8R Aug 20 '18 at 21:45

1 Answers1

0

One option would be to add the known types to a configuration file. The configuration file doesn't need to be your app.config (or web.config). It could be called dummy.config.

When you run svcutil.exe, add the following parameter /svcutilConfig:dummy.config. When the client code is generated, your KnownType attributes should go away.

Here's another example of registering known types using a configuration file.

RobV8R
  • 1,036
  • 8
  • 16
  • Thank you. I am trying to remove just the known type attributes from the generation, while still keeping the declared types. From the configuration file, I could clear the declared types, but I can't clear Known Types, unless I manually write every declared type and then clear their respective known types, which isn't feasible. Unless I am missing something here... – LadderLogic Aug 20 '18 at 22:58
  • I was actually just thinking about that part. You’d have to manually create (and maintain) the configuration file. One option would be to create a T4 template based on WCF metadata. It’s not a silver bullet, but I think it answers your original question. – RobV8R Aug 21 '18 at 00:54
  • Did you find an alternate solution? – RobV8R Aug 22 '18 at 03:21
  • unfortunately, not an elegant one. Currently sticking with scrubbing the code after generation. – LadderLogic Aug 22 '18 at 19:30