【问题标题】:SVCUtil skip complexType of a wsdl to avoid duplicatesSVCUtil 跳过复杂类型的 wsdl 以避免重复
【发布时间】:2014-01-21 02:19:48
【问题描述】:

我在本地下载了多个 wsdl 文件 - A.WSDL 和 B.WSDL

A.WSDL 与 B.WSDL 具有相同的复杂类型集(近 100 个) <xsd:complexType name="Book"> 但方法/操作不同。

例如: A.WSDL 具有复杂类型 <xsd:complexType name="Book"> 和正在创建新操作的操作

B.WSDL 具有相同的复杂类型<xsd:complexType name="Book"> 并且操作是读取操作

我正在使用 SVCUtil 在客户端生成存根到单个文件和具有相同命名空间的存根。但得到以下错误:

错误:验证导出期间生成的某些 XML 模式时出错: complexType http://mylocalhost/object:Book 已被声明。

约束是:

1) 我将无法更改 WSDL 文件。

2) 希望将生成的存根类放在单个名称空间中。

3) 没有 wsdl.exe

有什么方法可以跳过或覆盖重复的 complexType?

【问题讨论】:

  • 复杂类型 = 类 您希望在同一个命名空间中有两个名称相同的类吗? wtf?
  • @NahumLitvin :这不是两个不同的类。两者都是相同的类,具有相同的复杂类型结构,但在两个不同的 wsdls 中。两个不同的wsdl中的操作是不同的。我无法控制 wslds。这就是它从 3rd 方系统生成的方式
  • 如果您无法更改文件,请创建一个将生成新文件的小脚本。没有其他办法。
  • 你好 Raghav,这两个 wsdl 文件的 XSD 是否相同?
  • @ConsultYarla :是的,两个 wsdl 文件的 XSD 相同。

标签: c# wcf svcutil.exe


【解决方案1】:

我引用 Daniel Roth 提供的 here

"I think you are looking for something like the /shareTypes feature in wsdl.exe.  
 If you want to correctly share types all you need to do is generate clients 
 for both service at the same time.  You can do this by passing the location 
 of the metadata for both services to svcutil:

       svcutil [service url1] [service url2]

 When you pass both services to svcutil at the same time svcutil can figure out 
 which types are shared and only generate one type instead of many.

 If you want svcutil to generate existing types instead of new types, you need 
 to 'reference' the existing types in a DLL:

      svcutil /reference:MyTypes.dll [service url1] [service url2]

 If there are types in the referenced DLL that you don't want to be used in code           
 generation, you can use the /excludeType switch to keep that type from getting 
 generated."

【讨论】:

  • svcutil [service url1] [service url2] - 因为错误“The complexType has been declared”而从未为我工作过
  • 我无法手动排除,因为有 100 个和奇数的数据对象(复杂类型)
【解决方案2】:

我通过编写一个批处理文件来做到这一点。

方法是 1) 使用 SVCUtil 为 A.wsdl 创建代理类

2) 将它们编译为 .dll 文件

3) 使用 SVCUtil 为 B.wsdl 创建引用在 #2 中创建的 dll 文件的代理类。

以下是代码行:

"Your_Windows_SDK_Path\Bin\SvcUtil.exe" A.wsdl /language:C# /out:A.cs

"Your_Windows_.NetFramework_Path\csc.exe" /target:library /out:myreferences.dll A.cs

"Your_Windows_SDK_Path\Bin\SvcUtil.exe" B.wsdl /r:myreferences.dll /language:C# /out:B.cs /mergeconfig /config:output.config `

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-04
    • 1970-01-01
    • 2017-06-17
    • 1970-01-01
    • 2018-10-15
    • 2021-12-16
    相关资源
    最近更新 更多