3

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

  • 尝试了 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
4

2 回答 2

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:xsdhttp://www.w3.org/2001/XMLSchema而不是http://www.w3.org/1999/XMLSchema(1999 年的版本已经过时了)

  • 从架构元素中删除的命名空间(GetOrders代替o:GetOrdersGetOrdersResponse代替)(元素或类型定义os:GetOrdersResponse的属性中不允许使用命名空间限定符)name

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


我同意,WSDL 一开始可能很困难,但是,一旦你掌握了它,没有什么比明确定义的接口更好的了。如果可以选择,我会毫不犹豫地选择 wsdl 而不是 json-REST-API。但我想这是一个品味问题;-)

于 2012-01-03T04:14:57.347 回答
0

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

 <import namespace="http://example/schema/OrdersService"/>
于 2009-11-05T22:17:39.647 回答