无论是WSDL还是wsimport和wsdl(单声道)都被严重破坏

时间:2009-11-05 18:11:38

标签: java wsdl java-metro-framework wsimport

编辑我从下面给出的示例开始,但我现在有:

  • 尝试了W3C规范中的示例。修复另一个错误(绑定在一个地方称为StockQuoteSoapBinding,在另一个地方称为StockQuoteBinding)后,它会出现同样的问题。
  • 尝试使用单声道生成器wsdl来查看wsimport是否应该受到指责。它给出了一个等价的错误。

所以在我看来,尽管有关于SOAP的大肆宣传,它实际上并没有起作用 - 至少不像宣传的那样。我无法相信没有人通过这些发生器运行最可见的wsdl示例。

原始问题

wsimport在以下wsdl上失败:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="OrdersService"
  xmlns:xsd="http://www.w3.org/1999/XMLSchema"
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns:os="http://example/schema/OrdersService"
  xmlns:tns="http://example/ns/OrdersService"
  targetNamespace="http://example/ns/OrdersService"
  >

  <wsdl:types>
    <xsd:schema
      targetNamespace="http://example/schema/OrdersService">

      <xsd:element name="o:GetOrders">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="criteria" type="string"/>
      </xsd:sequence>
    </xsd:complexType>
      </xsd:element>

      <xsd:element name="os:GetOrdersResponse">
    <xsd:complexType>
      <xsd:all>
        <xsd:element name="orders" type="string"/>
      </xsd:all>
    </xsd:complexType>
      </xsd:element>

    </xsd:schema>
  </wsdl:types>

  <wsdl:message name="GetOrdersRequest">
    <wsdl:part name="parameters" element="os:GetOrders"/>
  </wsdl:message>

  <wsdl:message name="GetOrdersResponse">
    <wsdl:part name="parameters" element="os:GetOrdersResponse"/>
  </wsdl:message>

  <wsdl:portType name="GetOrdersPortType">
    <wsdl:operation name="GetOrders">
      <wsdl:input message="tns:GetOrdersRequest"/>
      <wsdl:output message="tns:GetOrdersResponse"/>
    </wsdl:operation>
  </wsdl:portType>

  <wsdl:binding name="GetOrdersBinding" type="tns:GetOrdersPortType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="GetOrders">
      <soap:operation soapAction=""/>
      <wsdl:input><soap:body use="literal"/></wsdl:input>
      <wsdl:output><soap:body use="literal"/></wsdl:output>
    </wsdl:operation>
  </wsdl:binding>

  <wsdl:service name="OrdersService">
    <wsdl:port name="GetOrdersPort" binding="tns:GetOrdersBinding">
      <soap:address location="http://localhost:8080/svc/OrdersService/GetOrders"/>
    </wsdl:port>
  </wsdl:service>

</wsdl:definitions>

使用:

parsing WSDL...


[ERROR] Schema descriptor {http://example/schema/OrdersService}GetOrders in message part "parameters" is not defined and could not be bound to Java. Perhaps the schema descriptor {http://example/schema/OrdersService}GetOrders is not defined in the schema imported/included in the WSDL. You can either add such imports/includes or run wsimport and provide the schema location using -b switch.
  line 35 of file:test.wsdl

2 个答案:

答案 0 :(得分:5)

虽然问题相当陈旧,但这是一个有效的WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="OrdersService"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns:os="http://example/schema/OrdersService"
  xmlns:tns="http://example/ns/OrdersService"
  targetNamespace="http://example/ns/OrdersService">

  <wsdl:types>
    <xsd:schema targetNamespace="http://example/schema/OrdersService">

      <xsd:element name="GetOrders">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="criteria" type="xsd:string" />
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>

      <xsd:element name="GetOrdersResponse">
        <xsd:complexType>
          <xsd:all>
            <xsd:element name="orders" type="xsd:string" />
          </xsd:all>
        </xsd:complexType>
      </xsd:element>

    </xsd:schema>
  </wsdl:types>

  <wsdl:message name="GetOrdersRequest">
    <wsdl:part name="parameters" element="os:GetOrders" />
  </wsdl:message>

  <wsdl:message name="GetOrdersResponse">
    <wsdl:part name="parameters" element="os:GetOrdersResponse" />
  </wsdl:message>

  <wsdl:portType name="GetOrdersPortType">
    <wsdl:operation name="GetOrders">
      <wsdl:input message="tns:GetOrdersRequest" />
      <wsdl:output message="tns:GetOrdersResponse" />
    </wsdl:operation>
  </wsdl:portType>

  <wsdl:binding name="GetOrdersBinding" type="tns:GetOrdersPortType">
    <soap:binding style="document"
       transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="GetOrders">
      <soap:operation soapAction="" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>

  <wsdl:service name="OrdersService">
    <wsdl:port name="GetOrdersPort" binding="tns:GetOrdersBinding">
      <soap:address
         location="http://localhost:8080/svc/OrdersService/GetOrders" />
    </wsdl:port>
  </wsdl:service>

</wsdl:definitions>

我改变的事情:

  • xmlns:xsd设置为http://www.w3.org/2001/XMLSchema而非http://www.w3.org/1999/XMLSchema(1999版本已过时)

  • 删除了从架构元素(GetOrders而不是o:GetOrdersGetOrdersResponse而不是os:GetOrdersResponse标识的命名空间(name内不允许使用命名空间限定符1}}元素或类型定义的属性)

  • 使用了子元素criteriaorders的正确类型:xsd:string而不是string


我同意,WSDL在开始时可能很难,但是,一旦掌握了它,没有比明确定义的界面更好的了。如果我有一个选择,我宁愿选择wsdl而不是json-REST-API。但我想这是一个品味问题; - )

答案 1 :(得分:0)

如果我没记错的话,wsimport需要导入外部名称空间才能在WSDL文件中使用它们的元素。在你的情况下:

 <import namespace="http://example/schema/OrdersService"/>