简体   繁体   English

在 SvcUtil 和 WSDL 代码生成期间抓取已知类型属性

[英]Scraping KnownType attributes during SvcUtil and WSDL Code generation

I have a WCF service with a mex endpoint for metadata.我有一个带有用于元数据的 mex 端点的 WCF 服务。 I use the SvcUtil through visual studio to generate client data contracts code (C#) while the service is running.我通过 Visual Studio 使用 SvcUtil 在服务运行时生成客户端数据合同代码 (C#)。 SvcUtil adds KnownType attributes for the inherited and referenced types. SvcUtil 为继承的和引用的类型添加了KnownType 属性。 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?如何让 SvcUtil 或 WSDL 导入器不使用已知类型属性标记所有这些类型? 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.我最糟糕的情况是在代码生成后遍历文件并删除这些属性,但我希望有一种更简洁的方法来做到这一点。

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).配置文件不必是您的 app.config(或 web.config)。 It could be called dummy.config .它可以被称为dummy.config

When you run svcutil.exe , add the following parameter /svcutilConfig:dummy.config .运行svcutil.exe 时,添加以下参数/svcutilConfig:dummy.config When the client code is generated, your KnownType attributes should go away.生成客户端代码后,您的KnownType 属性应该会消失。

Here's another example of registering known types using a configuration file.这是使用配置文件注册已知类型的另一个示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM