SVCUtil skip complexType of a wsdl to avoid duplicates

会有一股神秘感。 提交于 2019-12-10 00:21:35

问题


I have multiple wsdl files downloaded on my local - A.WSDL and B.WSDL

A.WSDL has same set of complex type (nearly 100) as that of B.WSDL <xsd:complexType name="Book"> but the methods/operations are different.

For Example: A.WSDL has complex type <xsd:complexType name="Book"> and operations being create new operations

B.WSDL has same complex type <xsd:complexType name="Book"> and operations being read operations

I am using SVCUtil to generate stubs on the client end to a single file and stubs with the same namespace. But getting the below error:

Error: There was an error verifying some XML Schemas generated during export: The complexType http://mylocalhost/object:Book has already been declared.

The constraints are:

1) I will not be able to change the WSDL files.

2) Would like to place the generated stub classes in single name space.

3) No wsdl.exe

Is there any way that either the duplicated complexType could be skipped or could be overwritten?


回答1:


I quote what Daniel Roth has provided 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."



回答2:


I did this by writing a batch file.

The approach was 1) Create proxy classes for A.wsdl using SVCUtil

2) Compile them to .dll files

3) Create proxy classes for B.wsdl referencing to the dll file created in #2 using SVCUtil.

Below are the lines of code:

"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 `



来源:https://stackoverflow.com/questions/15831390/svcutil-skip-complextype-of-a-wsdl-to-avoid-duplicates

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!