Per generarare il wsdl a partire dal file xsd occorre utilizzare una classe fornita da spring ws che in automatico nel rispetto di determinate convenzioni genera il nostro wsdl.
La classe da utilizzare è la DefaultWsdl11Definition
<bean id="libreria" class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition"> <property name="schema"> <bean class="org.springframework.xml.xsd.SimpleXsdSchema"> <property name="xsd" value="/WEB-INF/libreria.xsd"/> </bean> </property> <property name="portTypeName" value="Libreria"/> <property name="locationUri" value="http://localhost:10000/libreria/services"/> </bean>
<?xml version="1.0" encoding="UTF-8" standalone="no" ?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"xmlns:sch="http://www.example.org/schema"xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"xmlns:tns="http://www.example.org/schema" targetNamespace="http://www.example.org/schema"><wsdl:types><schema xmlns="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified"elementFormDefault="qualified" targetNamespace="http://www.example.org/schema"><complexType name="LibroType"><sequence><element name="titolo" type="string" /><element name="nome" type="string" /><element name="cognome" type="string" /></sequence></complexType><element name="RicercaLibroRequest"><complexType><sequence><element minOccurs="0" name="titolo" type="string" /><element minOccurs="0" name="nome" type="string" /><element minOccurs="0" name="cognome" type="string" /></sequence></complexType></element><element name="RicercaLibroResponse"><complexType><sequence><element maxOccurs="unbounded" minOccurs="0" name="libro" type="string" /></sequence></complexType></element></schema></wsdl:types><wsdl:message name="RicercaLibroResponse"><wsdl:part element="tns:RicercaLibroResponse" name="RicercaLibroResponse" /></wsdl:message><wsdl:message name="RicercaLibroRequest"><wsdl:part element="tns:RicercaLibroRequest" name="RicercaLibroRequest" /></wsdl:message><wsdl:portType name="Libreria"><wsdl:operation name="RicercaLibro"><wsdl:input message="tns:RicercaLibroRequest" name="RicercaLibroRequest" /><wsdl:output message="tns:RicercaLibroResponse" name="RicercaLibroResponse" /></wsdl:operation></wsdl:portType><wsdl:binding name="LibreriaSoap11" type="tns:Libreria"><soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /><wsdl:operation name="RicercaLibro"><soap:operation soapAction=" " /><wsdl:input name="RicercaLibroRequest"><soap:body use="literal" /></wsdl:input><wsdl:output name="RicercaLibroResponse"><soap:body use="literal" /></wsdl:output></wsdl:operation></wsdl:binding><wsdl:service name="LibreriaService"><wsdl:port binding="tns:LibreriaSoap11" name="LibreriaSoap11"><soap:address location="http://localhost:10000/libreria/webservice" /></wsdl:port></wsdl:service></wsdl:definitions>
Nel nostro caso la classe ha individuato un solo servizio RicercaLibro che riceve in ingresso la RicercaLibroRequest e restituisce in uscita la RicercaLibroResponse. Tale servizio è disponibile all'url http://localhost:10000/libreria/webservice.
Per poter avere un riscontro agevole di quanto fatto possiamo caricare il nostro wsdl tramite il tool soap ui, ottimo strumento per il testing dei servizi SOA.
Nel prossimo articolo vedremo come mettere in piedi il nostro server con l'aiuto di spring-ws.