构建依赖于第三方提供商的应用程序,该应用程序具有非常冗长的SOAP服务集(我们正在讨论50多个WSDL文件)。但是,每个单独的WSDL都有许多共享类型声明。使用wsdl.exe生成客户端代码时,曾经有一个/ sharedtypes标志,如果多次找到类型,它将合并重复的条目。
当我尝试生成我的客户端代码时,我会轰炸第三方在其所有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。 (再次提醒我为什么我们认为在90年代后期,SOAP对我们所有人来说都是伟大的救赎?)
答案 0 :(得分:2)
尝试在一个命令中指定所有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
答案 1 :(得分:0)
我遇到了类似的问题。通过为不同的xml命名空间定义不同的CLR命名空间(使用svcutil的/ namespace参数),我能够使它工作。
/namespace:http://www.opengis.net/gml,OpenGIS.GML
答案 2 :(得分:0)
我一直在使用wsdl.exe来解决这个问题,因为我使用了一些SOAP Web服务,它们在不同的端点定义相同的数据传输对象。所以我使用wsdl.exe,因为它有sharetypes开关。我不是WPF开发人员,所以我并不关心输出没有为WPF实现IWhatever,但是生成的类都是部分的,所以你可以做一些工作来在一个单独的文件中实现你关心的接口。