无法从WSDL生成存根/Java框架

3

我编写了一个WSDL以生成存根和框架,但是我的框架在Eclipse中没有被生成。我正在使用Eclipse的Helios版本。
有人能告诉我WSDL的问题是什么吗?

我想使用Axis 2。我也尝试使用wsdl2java生成框架,但是在生成的类中出现了编译问题。我无法在此处附加文件,因此我将其粘贴在此处。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:impl="http://DefaultNamespace"
      xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:apachesoap="http://xml.apache.org/xml-soap"
      xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      name="Test" targetNamespace="http://DefaultNamespace"> 
      <wsdl:types>
        <xsd:schema elementFormDefault="qualified"
          targetNamespace="http://DefaultNamespace" xmlns="http://www.w3.org/2001/XMLSchema">
          <import namespace="http://xml.apache.org/xml-soap" />
          <xsd:element name="serviceMethod">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="vo" type="impl:MyVo" />
              </xsd:sequence>
            </xsd:complexType>
          </xsd:element>
          <xsd:complexType name="MyVo">
            <xsd:sequence>
              <xsd:element name="name" nillable="false" type="xsd:string" />
              <xsd:element name="params" nillable="true"
                type="apachesoap:Map" />
            </xsd:sequence>
          </xsd:complexType>
          <xsd:element name="serviceMethodResponse">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="serviceMethodReturn" type="impl:MyVo" />
              </xsd:sequence>
            </xsd:complexType>
          </xsd:element>
        </xsd:schema>
        <xsd:schema elementFormDefault="qualified"
          targetNamespace="http://xml.apache.org/xml-soap" xmlns="http://www.w3.org/2001/XMLSchema">
          <import namespace="http://DefaultNamespace" />
          <xsd:complexType name="mapItem">
            <xsd:sequence>
              <xsd:element name="key" nillable="true" type="xsd:anyType" />
              <xsd:element name="value" nillable="true" type="xsd:anyType" />
            </xsd:sequence>
          </xsd:complexType>
          <xsd:complexType name="Map">
            <xsd:sequence>
              <xsd:element maxOccurs="unbounded" minOccurs="0"
                name="item" type="apachesoap:mapItem" />
            </xsd:sequence>
          </xsd:complexType>
        </xsd:schema>
      </wsdl:types>
      <wsdl:message name="serviceMethodRequest">
        <wsdl:part element="impl:serviceMethod" name="parameters" />
      </wsdl:message>
      <wsdl:message name="serviceMethodResponse">
        <wsdl:part element="impl:serviceMethodResponse" name="parameters" />
      </wsdl:message>
      <wsdl:portType name="Test">
        <wsdl:operation name="serviceMethod">
          <wsdl:input message="impl:serviceMethodRequest" name="serviceMethodRequest" />
          <wsdl:output message="impl:serviceMethodResponse" name="serviceMethodResponse" />
        </wsdl:operation>
      </wsdl:portType>
      <wsdl:binding name="TestSOAP" type="impl:Test">
        <soap:binding style="document"
          transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="serviceMethod">
          <soap:operation soapAction="http://DefaultNamespace/serviceMethod" />
          <wsdl:input>
            <soap:body use="literal" />
          </wsdl:input>
          <wsdl:output>
            <soap:body use="literal" />
          </wsdl:output>
        </wsdl:operation>
      </wsdl:binding>
      <wsdl:service name="Test">
        <wsdl:port binding="impl:TestSOAP" name="MyWebService">
          <soap:address location="http://localhost:8080/Temp/services/MyService" />
        </wsdl:port>
      </wsdl:service>
    </wsdl:definitions>

我这边可以正常工作和编译。你具体的错误信息是什么? - user684934
你尝试过使用Eclipse或wsdl2java生成骨架吗?当我尝试使用Eclipse时,向导中没有显示服务名称、端口名称,并且出现了“在WSDL代码生成期间发生异常:java.lang.NoClassDefFoundError: com/ibm/wsdl/extensions/schema/SchemaImportImpl”的错误。对于Axis2而言。 - java_enthu
3个回答

1

我曾经遇到过同样的问题。我认为这是由于Maven文件夹结构引起的。我创建了一个没有Maven的新项目,它可以正常工作。后来再添加Maven。同时,请检查“Java Build Path”中的源文件夹。如果缺少,则需要添加它。


这并没有真正回答问题。如果您有不同的问题,可以通过点击提问来提出。一旦您拥有足够的声望,您还可以添加赏金以吸引更多关注此问题的人。 - cfi
我回答了这个问题。如果你仔细阅读,我描述了我是如何解决这个问题的。 - Hadi Tok
你的症状可能相似(或相同),但显然出现了不同的问题:请注意,在你回答之前四个月,bdares已经给出了一个解决方案,并被原提问者接受为解决方案。你的解决方案可能是有效的,但对于不同的问题。我认为,你发布的内容是有价值的贡献,但只能作为评论。为了让这个网站对未来的访问者有意义,我们必须尝试区分具有类似症状的不同问题。如果所有具有类似症状的问题最终都汇集在一个问题中,那么这个网站最终将变成一团糟。 - cfi

1

这是您安装的问题。

下载并验证axis2和axis2 eclipse插件,确保您已设置好AXIS2_HOME类路径。

有时它也会停止为我工作,然后我不得不重新安装所有内容。不要费心向Eclipse或Apache提交错误报告,它们总是被关闭为“WORKSFORME”。

从wsdl生成代码的步骤:

  1. 创建动态Web项目。
  2. 创建您的wsdl文件。
  3. 右键单击wsdl文件,选择Web Services -> Generate Java Bean Skeleton
  4. 点击完成

Axis2库、facets和生成的代码将自动添加到您的项目中,并且不会出现编译问题。


你能告诉我你正在使用哪个Eclipse版本和哪个Axis2版本吗? - java_enthu
我正在使用jdk 1.5,eclipse helios,axis2 1.5.4,axis2 codegen插件1.5.4。 - user684934
实际上,我创建了一个动态项目,添加了这个wsdl,使用代码生成器插件Axis2Code generator 1.5.4,并给出文件路径,选择代码生成选项:自定义,选择:生成服务器端代码,选择输出路径(完成),类会在目标位置生成,将它们复制并粘贴到eclipse项目的src中。但是MapItem类存在编译问题。如果我使用CLI,我仍然面临同样的问题。 - java_enthu
谢谢。bdres看起来像右键生成bean没问题。但是在使用codegen向导时会出现编译问题。 - java_enthu
@java_enthu 这可能是因为您忽略了将Axis2 facet和Axis2库添加到项目中。而且Eclipse从来不会说“存在编译器问题”。在以后的开发中,请告诉我们错误信息或者您如何知道存在错误,因为这是解决此类问题的线索。 - user684934
显示剩余4条评论

0

我曾经遇到同样的问题,但现在已经解决了。问题是如果你有一个“抛出某种异常”的方法,那么它会引起问题。因此,不要抛出错误,尝试使用try-catch块语句。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接