Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a WSDL to its respective HTTP Bindings

I'm simply trying to convert a WSDl into a number of different HTTP-requests from data supplied by the WSDL. I have read through a ton of similar questions, but none really provided an answer.

Some say to use SOAPUI - I am familiar with this application and do use it. But I need to create these HTTP-requests from the WSDL on my own.

Some say to try JAXWS - I looked at a number of tutorials on this as well as on Axis and these translate the WSDL into Java class bindings and you use those methods to test the web services. I really would like to just generate the HTTP-request myself so that at one point I can manipulate the request and send my own tests.

I started using wsdl4j to begin parsing the WSDL myself but would rather not go down this path until I'm absolutely sure I'm not reinventing the wheel. Seems to me there has been a need for this in past? But with WSDL4J and every other library I do not see a WSDL to Soap message translation.

Any suggestions would be very helpful. The goal is I want to be able to take a WSDL, examine it and create HTTP-SOAP requests for each method in the WSDL and be able to than test them for security issues. The first step is to create those requests!

like image 515
steve Avatar asked Nov 04 '22 07:11

steve


1 Answers

When calling a SOAP web service you can use a static invocation or a dynamic invocation.

Static invocation means creating a stub from the WSDL and using that to perform the call. This creates all the "plumbing" code for you, but is tightly tied to just that web service and you can't use it for other web services with different contracts. For each WSDL you need to create another stub.

With dynamic invocation, you read the WSDL at runtime and figure out how to call the web service based on the info you get from the WSDL. Feed it multiple WSDLs and the client adapts.

The dynamic invocation is what SoapUI uses to generate the sample requests and responses.

It reads the WSDL you feed it, extracts the XML schema from the types section and generates XML instances. To do so, it uses Wsdl4j and XmlBeans under the hood.

Your decision to use Wsdl4j is good as it gives you control when parsing the WSDL. But also have a look at XmlBeans; it has some other tools you might find useful, like the schema to instance class for example.

If you need to see it in action (maybe debug it to see what's going on) you could create a quick dirty test with the SoapUI API:

import com.eviware.soapui.impl.wsdl.WsdlInterface;
import com.eviware.soapui.impl.wsdl.WsdlProject;
import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlImporter;

public class Test {
    public static void main(String[] args) throws Exception {
        WsdlProject project = new WsdlProject();
        WsdlInterface[] wsdls = WsdlImporter.importWsdl(project, "http://www.html2xml.nl/Services/Calculator/Version1/Calculator.asmx?wsdl");
        WsdlInterface wsdl = wsdls[0];
        System.out.println(wsdl.getOperationByName("Add").createRequest(true));
        System.exit(0); // just to clear up some threads created by the project 
    }
}

The message you should see printed (for the Add operation of the Calculator WS) would be something like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:Add>
         <tem:a>?</tem:a>
         <tem:b>?</tem:b>
      </tem:Add>
   </soapenv:Body>
</soapenv:Envelope>

Hope this helps you move beyond the first step.

like image 71
Bogdan Avatar answered Nov 07 '22 22:11

Bogdan