使用 JDK 工具 wsimport 从 .NET 2.0 应用程序生成的 WSDL 生成 Java SOAP Web 服务客户端时出现问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/785945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 19:27:24  来源:igfitidea点击:

Problem generating Java SOAP web services client with JDK tool wsimport from a WSDL generated by a .NET 2.0 application

java.netweb-servicesaxiswsimport

提问by razenha

I'm trying to generate a client for some SOAP web services using the JDK 6 tool wsimport. The WSDL was generated by a .NET 2.0 application. For .NET 3.X applications, it works fine.

我正在尝试使用 JDK 6 工具为某些 SOAP Web 服务生成客户端wsimport。WSDL 是由 .NET 2.0 应用程序生成的。对于 .NET 3.X 应用程序,它工作正常。

When I run

当我跑

wsimport -keep -p mypackage http://myservice?wsdl

it shows several error messages like this:

它显示了几个这样的错误消息:

[ERROR] A class/interface with the same name "mypackage.SomeClass" is already in use. Use a class customization to resolve this conflict. line ?? of http://myservice?wsdl

[错误] 具有相同名称“mypackage.SomeClass”的类/接口已在使用中。使用类自定义来解决此冲突。线 ??的HTTP://为MyService WSDL

When I generate the web services client using Axis 1.4 (using the Eclipse WebTools plug-in).

当我使用 Axis 1.4(使用 Eclipse WebTools 插件)生成 Web 服务客户端时。

Does anybody know what can I do in order to use the wsimporttool? I really don't understand what the "class customization" thing is.

有谁知道我可以做什么才能使用该wsimport工具?我真的不明白“类定制”是什么东西。

采纳答案by PaulH

I don't know if this was ever solved, but I spent some time googling for a solution to this same problem.

我不知道这是否曾经解决过,但我花了一些时间在谷歌上搜索同样问题的解决方案。

I found a fix here - https://jax-ws.dev.java.net/issues/show_bug.cgi?id=228

我在这里找到了一个修复程序 - https://jax-ws.dev.java.net/issues/show_bug.cgi?id=228

The solution is to run wsimport with the -B-XautoNameResolution(no spaces)

解决方案是使用-B-XautoNameResolution(无空格)运行 wsimport

回答by simon

You are possibly generating all the classes from the WSDL file in the same package. If that is the case, try specifying a different target package for each WSDL file with the -p option of wsimport.

您可能从同一个包中的 WSDL 文件生成所有类。如果是这种情况,请尝试使用 wsimport 的 -p 选项为每个 WSDL 文件指定不同的目标包。

回答by Margaret Lydon

For anyone reading this using maven, this is how to add it to the .pom file. Note the args in the configuration section. This is not very easily found in documentation. Many thanks to Isaac Stephens for his help with this.

对于使用 maven 阅读本文的任何人,这是将其添加到 .pom 文件的方法。请注意配置部分中的参数。这在文档中并不容易找到。非常感谢 Isaac Stephens 在这方面的帮助。

<!-- definition for ERPStandardWork service -->
<execution>
  <id>ERPStandardWorkService</id>
  <goals>
    <goal>wsimport</goal>
  </goals>
  <configuration>
    <!-- this resolves naming conflicts within the wsdl - there are several copies of fault report objects which clash otherwise. -->
    <args>
       <arg>-B-XautoNameResolution</arg>
    </args>
    <wsdlDirectory>${basedir}/src/main/resources/META-INF/wsdl</wsdlDirectory>
    <wsdlFiles>
        <wsdlFile>ERPStandardWork.wsdl</wsdlFile>
    </wsdlFiles>
      <wsdlLocation>${basedir}/src/main/resources/META-INF/wsdl/ERPStandardWork.wsdl
    </wsdlLocation>
    <staleFile>${project.build.directory}/jaxws/ERPStandardWork/.staleFlag
    </staleFile>
  </configuration>
</execution>

回答by Abhi Rampal

The accepted answer above would solve your problem but wouldnt fix the underlying cause.

上面接受的答案将解决您的问题,但不会解决根本原因。

The issue is happening because an operation in your wsdl file has the same name as an xsd:complexType in your xsd file - like the example below. All types and operations should have unique names.

出现此问题是因为 wsdl 文件中的操作与 xsd 文件中的 xsd:complexType 具有相同的名称 - 如下例所示。所有类型和操作都应该有唯一的名称。

<xsd:complexType name="SearchDocuments">
      <xsd:sequence>
        <xsd:element name="document" type="ns0:SearchDocumentById" maxOccurs="unbounded"/>
      </xsd:sequence>
</xsd:complexType>

<operation name="SearchDocuments">
      <input wsam:Action="http://controller.xxx.xxx.com/DocumentWS/searchDocumentsRequest" message="tns:searchDocumentsRequest"/>
      <output wsam:Action="http://controller.xxx.xxx.com/DocumentWS/searchDocumentsResponse" message="tns:searchDocumentsResponse"/>
</operation>

So check your operations and types. Make sure none of them have the same name i.e. no duplicate names.

因此,请检查您的操作和类型。确保它们都没有相同的名称,即没有重复的名称。