SVCUtil跳过wsdl的complexType以避免重复

时间:2013-04-05 10:18:29

标签: c# wcf svcutil.exe

我在本地下载了多个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

有没有办法可以跳过重复的复杂类型或者可以覆盖它?

2 个答案:

答案 0 :(得分:3)

我引用丹尼尔罗斯提供的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."

答案 1 :(得分:0)

我是通过编写批处理文件来完成的。

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