generate from example ejemplo create consume classes java wsdl java-metro-framework wsimport

java - from - O WSDL o wsimport y wsdl(mono) están horriblemente rotos



wsimport generate java classes (2)

EDITAR Empecé con el ejemplo que figura a continuación, pero ahora tengo:

  • Intenté el ejemplo de la especificación W3C. Después de corregir otro error (el enlace se llamó StockQuoteSoapBinding en un lugar, StockQuoteBinding en otro), da el mismo problema.
  • Probé el generador mono wsdl para ver si wsimport era el culpable. Da un error equivalente.

Por lo tanto, me parece que a pesar de todo el bombo sobre SOAP, en realidad no funciona, al menos no como se anuncia. No puedo creer que nadie haya ejecutado los ejemplos más fáciles de encontrar de wsdl a través de estos generadores.

Pregunta original

wsimport está fallando en el siguiente 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>

Con:

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


Aunque la pregunta es bastante antigua, aquí hay un WSDL en funcionamiento:

<?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>

Cosas que he cambiado:

  • establezca xmlns:xsd en http://www.w3.org/2001/XMLSchema lugar de http://www.w3.org/1999/XMLSchema (la versión de 1999 está bastante desactualizada)

  • espacio de nombres eliminado identificado de los elementos de esquema ( GetOrders lugar de o:GetOrders y GetOrdersResponse lugar de os:GetOrdersResponse ) (los calificadores de espacios de nombres no están permitidos dentro del atributo de name de un elemento o definición de tipo)

  • utilizó los tipos correctos para los criteria y orders los subelementos: xsd:string lugar de string

Estoy de acuerdo en que un WSDL puede ser difícil al principio, sin embargo, una vez que lo controlas, no hay nada mejor que una interfaz claramente definida. Si tuviera una opción, preferiría un wsdl sobre un json-REST-API sin dudarlo. Pero supongo que es una cuestión de gusto ;-)


Si mal no recuerdo, wsimport requiere que se importen espacios de nombres externos para usar elementos de ellos en el archivo WSDL. En tu caso:

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