构建依赖于拥有一组非常冗长的 SOAP 服务(我们说的是 50 多个 WSDL 文件)的第 3 方提供商的应用程序。然而,每个单独的 WSDL 都有许多共享类型声明。当使用 wsdl.exe 生成客户端代码时,曾经有一个/sharedtypes 标志,如果多次找到一个类型,它会合并重复的条目。
当我尝试生成我的客户端代码时,我轰炸了第 3 方在其所有 WSDL 文件中包含的这些重叠类型。
svcutil /t:code /importxmltypes [mypath]/*.wsdl
导致暗示类型冲突的错误消息。例如,以下错误消息的几个示例:
Error: There was an error verifying some XML Schemas generated during export:
The simpleType 'http://common.soap.3rdparty.com:CurrencyNotation' has already been
declared.
Error: There was an error verifying some XML Schemas generated during export:
The complexType 'http://common.soap.3rdparty.com:NumberFormat' has already been
declared.
我无法控制 WSDL 的输出。我不想手动编辑 WSDL,因为担心在运行时以时尚方式中断的错误将很难追溯到我们对 WSDL 文件的编辑。更不用说有 50 个 WSDL 文件,范围从 200-1200 行 XML。 (再次提醒我为什么我们认为 SOAP 是 90 年代后期对我们所有人的伟大拯救?)
最佳答案
尝试在一条命令中指定所有 WSDL:
svcutil http://example.com/service1?wsdl http://example.com/service2?wsdl ...
这应该会自动处理重复的类型。另一种选择是查看 /reference
命令开关:
/reference:<file path> - Add the specified assembly to the set of
assemblies used for resolving type
references. If you are exporting or
validating a service that uses 3rd-party
extensions (Behaviors, Bindings and
BindingElements) registered in config use
this option to locate extension assemblies
that are not in the GAC. (Short Form: /r)
这意味着如果您已经在某个程序集中定义了某些类型,您可以包含此程序集,svcutil
将从中排除类型以避免重复:
svcutil /reference:someassembly.dll http://example.com/service?wsdl
关于c# -/sharedtypes 等同于 svcutil.exe?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2361609/