简体   繁体   English

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

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

I'm trying to generate a client for some SOAP web services using the JDK 6 tool wsimport . 我正在尝试使用JDK 6工具wsimport为一些SOAP Web服务生成客户端。 The WSDL was generated by a .NET 2.0 application. WSDL由.NET 2.0应用程序生成。 For .NET 3.X applications, it works fine. 对于.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. [错误]具有相同名称“mypackage.SomeClass”的类/接口已在使用中。 Use a class customization to resolve this conflict. 使用类自定义来解决此冲突。 line ?? 线? of http://myservice?wsdl 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 wsimport tool? 有谁知道我可以做什么才能使用wsimport工具? I really don't understand what the "class customization" thing is. 我真的不明白“类定制”是什么。

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(无空格)

For anyone reading this using maven, this is how to add it to the .pom file. 对于使用maven阅读此内容的任何人,这是如何将其添加到.pom文件中。 Note the args in the configuration section. 请注意配置部分中的args。 This is not very easily found in documentation. 这在文档中不是很容易找到。 Many thanks to Isaac Stephens for his help with this. 非常感谢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>

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. 问题出现了,因为wsdl文件中的操作与xsd文件中的xsd:complexType同名 - 如下例所示。 All types and operations should have unique names. 所有类型和操作都应具有唯一的名称。

<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 ie no duplicate names. 确保它们没有相同的名称,即没有重复的名称。

You are possibly generating all the classes from the WSDL file in the same package. 您可能在同一个包中生成WSDL文件中的所有类。 If that is the case, try specifying a different target package for each WSDL file with the -p option of wsimport. 如果是这种情况,请尝试使用wsimport的-p选项为每个WSDL文件指定不同的目标包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM