1

我在本地下载了多个 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 模式时出错:http://mylocalhost/object:Book已经声明了 complexType。

约束是:

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

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

3)没有wsdl.exe

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

4

2 回答 2

2

我引用 Daniel Roth 在这里提供的内容

"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."
于 2014-01-09T19:44:14.787 回答
1

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

方法是 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 `

于 2014-01-20T18:19:48.567 回答