【问题标题】:error while consuming a .Net web service from a WSDL in NetBeans从 NetBeans 中的 WSDL 使用 .Net Web 服务时出错
【发布时间】:2012-02-08 07:21:33
【问题描述】:

我在 .Net 中定义了一个 Web 服务,我想使用 java 来使用它。 当我想在 NetBeans 中从 WSDL 创建 Web 服务客户端时,出现以下错误。

JAXWS:wsimport 实用程序无法创建 Web 服务客户端。

[错误] 属性“任何”已定义。使用 解决此冲突。

这是我的 WSDL 文件的一部分:

    <s:element name="Select_Normal_Response">
    <s:complexType>
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="Select_Normal_Result">
                <s:complexType>
                    <s:sequence>
                        <s:any minOccurs="0" maxOccurs="unbounded" namespace="..."/>
                        <s:any minOccurs="1" namespace="" processContents="lax" />
                    </s:sequence>
                </s:complexType>
            </s:element>
        </s:sequence>
    </s:complexType>
</s:element>
<s:element name="Select_Normal_With_LastIDResponse">
    <s:complexType>
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="Select_Normal_With_LastIDResult">
                <s:complexType>
                    <s:sequence>
                        <s:any minOccurs="0" maxOccurs="unbounded" namespace="..."/>
                        <s:any minOccurs="1" namespace="..." processContents="lax" />
                    </s:sequence>
              </s:complexType>
            </s:element>
        </s:sequence>
    </s:complexType>
</s:element>

我想因为我有两个 s:any 标签,所以我收到了这个错误。 我该如何解决这个问题?

【问题讨论】:

    标签: java .net web-services netbeans jaxb


    【解决方案1】:

    第二个“s:any”标签有一个非标准的微软特定命名空间“urn:schemas-microsoft-com:xml-diffgram-v1”。您可以从 wsdl 中删除标记并重新尝试生成 Web 服务客户端。

    【讨论】:

    • 自动生成wsdl,如何删除?
    【解决方案2】:

    您需要使用绑定文件来给第二个任何一个唯一的名称。 创建例如 bindings.xjb 文件:

        <jaxws:bindings
                xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
                jxb:version="2.0"
                xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
                jxb:extensionBindingPrefixes="xjc"
        >
            <jaxws:bindings>
                <jxb:bindings node="/s:element/.../s:any[@namespace='...']">
                    <jxb:property name="any2" />
                </jxb:bindings>
            </jaxws:bindings>
        </jaxws:bindings>
    

    然后您可以使用构建类

        wsimport "http://www.yourwsdl.com/path?wsdl" -b bindings.xjb
    

    如果你使用 maven,你可以使用 jaxws-maven-plugin。使用它会在构建项目时自动构建客户端类。

    例如

        <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <version>1.9</version>
                <executions>
                        <execution> 
                                <id>webservice</id>
                                <goals> 
                                        <goal>wsimport</goal>
                                </goals>
                                <configuration>
                                        <packageName>com.company.app.wsclient</packageName>
                                        <wsdlUrls>
                                                <wsdlUrl>http://www.yourwsdl.com/path?wsdl</wsdlUrl>
                                        </wsdlUrls>
                                        <bindingFiles>
                                                <string>${basedir}/src/main/resources/bindings.xjb</string>
                                        </bindingFiles>
                                </configuration>
                        </execution>
                </executions>
                <dependencies>
                        <dependency>
                                <groupId>com.sun.xml.ws</groupId>
                                <artifactId>jaxws-tools</artifactId>
                                <version>2.2.5</version>
                        </dependency>
                </dependencies>
        </plugin>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-11
      • 1970-01-01
      • 2010-10-29
      • 1970-01-01
      相关资源
      最近更新 更多