c# -/sharedtypes 等同于 svcutil.exe?

标签 c# soap wsdl svcutil.exe

构建依赖于拥有一组非常冗长的 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/

相关文章:

java - 并行化远程服务调用

Maven:从jar中提取文件

c# - XSD.exe 不强制执行 minOccurs

c# - 首先在 EF 4.1 代码中以 "schema.tablename"格式映射 POCO,使用 dotconnect for Oracle

c# - 强制HttpClient使用Content-Type : text/xml

c# - 初始化委托(delegate)变量的奇怪方法

java - 给新手的建议 : ReSTLet or SOAP

java - 将复杂参数从 ksoap Android 传递到 WCF Web 服务

c# - 如何确定完整的异步请求批处理是否失败?

java - 无法在浏览器中打开 WSDL