0

How to create a soap WSDL file from this XML that was sent to me?

Or would it be possible to point me to some link for some Java sample that calls a soap web service without the WSDL?

Request:

<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ver="http://www.turismodeportugal.pt/SRJSchema/VerificacaoIdentidade">
<soap:Header/>
<soap:Body>
    <ver:PedidoVerificacaoTP>
        <ver:CodEntidadeExploradora>000</ver:CodEntidadeExploradora>
        <ver:Nome>John Doe</ver:Nome>
        <ver:NumeroIdentificacao>90909090</ver:NumeroIdentificacao>
        <ver:TipoIdentificacao>1</ver:TipoIdentificacao>
        <ver:DataNascimento>1900-06-27</ver:DataNascimento>
    </ver:PedidoVerificacaoTP>
</soap:Body>
</soap:Envelope>

Response:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
   <soap:Header xmlns:ver="http://www.turismodeportugal.pt/SRJSchema/VerificacaoIdentidade"/>
   <soap:Body xmlns:ver="http://www.turismodeportugal.pt/SRJSchema/VerificacaoIdentidade">
      <RespostaVerificacaoTP xmlns="http://www.turismodeportugal.pt/SRJSchema/VerificacaoIdentidade">
         <Sucesso>true</Sucesso>
         <Valido>S</Valido> 
      </RespostaVerificacaoTP>
   </soap:Body>
</soap:Envelope>
Cœur
  • 37,241
  • 25
  • 195
  • 267
Antonio Roque
  • 165
  • 2
  • 3
  • 12
  • Possible duplicate of [Generate WSDL for existing SOAP Service using captured traffic](https://stackoverflow.com/questions/9264048/generate-wsdl-for-existing-soap-service-using-captured-traffic) – Victor Mar 05 '18 at 11:27

1 Answers1

0

No wsdl, no problem. If you would like to build the soap request yourself without needing a wsdl, you can use the Dispatch client. This requires you however to have intimate knowledge of the service and know how the soap request should be formatted. Please see the example below and replace the endpoint string with the endpoint of your service and replace the soapRequest with the soap message that you plan on sending.

import java.io.StringReader;
import java.io.StringWriter;

import javax.xml.namespace.QName;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
import javax.xml.ws.http.HTTPBinding;

public class Main {
    public static void main(String[] args) throws Exception{
        //Name of Service and Port. Doesn't need to match the wsdl.
        Service service = Service.create(new QName("", ""));
        QName port = new QName("", "");

        //This is the endpoint of the SOAP Service
        String endpoint = "http://localhost:8008/soap";
        service.addPort(port, HTTPBinding.HTTP_BINDING, endpoint);

        //Create a dispatch client to send the request
        Dispatch<Source> input = service.createDispatch(port, Source.class, Service.Mode.PAYLOAD);

        //SoapRequest
        String soapRequest = "<S:Envelope xmlns:S=\\\"http://schemas.xmlsoap.org/soap/envelope/\\\" xmlns:SOAP-ENV=\\\"http://schemas.xmlsoap.org/soap/envelope/\\\"><SOAP-ENV:Header/><S:Body xmlns:ns2=\\\"http://service.calvinmmiller.com/\\\"><ns2:echo><arg0>Calvin</arg0></ns2:echo></S:Body></S:Envelope>";
        Source output = input.invoke(new StreamSource(new StringReader(soapRequest)));

        //Print the Results
        StreamResult xml = new StreamResult(new StringWriter());
        Transformer newTransformer = TransformerFactory.newInstance().newTransformer();
        newTransformer.transform(output, xml);
        System.out.println(xml.getWriter());
    }
}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
cbones4321
  • 46
  • 1
  • 2