title: How to access a SOAP Web Service URL Endpoint from Java
body: <p>How to access a SOAP Web Service URL Endpoint from Java? </p>
  
  <p>I've been searching for a concrete example for a while and I'm getting no-where. Unfortunately my preferred method using REST isn't available in this scenario I'm working on, so having to test a SOAP based approach. </p>
  
  <p>The setup is, there is a SOAP WSDL file located at <code>www.website.com/soap.wsdl</code> for example. And I'm trying to send and receive data from a CreateData endpoint. </p>
  
  <p>When I add the WSDL file into SoapUI software to test, this generates the following SOAP message template;</p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tic="{redacted}"&gt;
     &lt;soapenv:Header/&gt;
     &lt;soapenv:Body&gt;
        &lt;tic:CreateData&gt;
           &lt;tic:request&gt;{"testKey":"testValue"}&lt;/tic:request&gt;
        &lt;/tic:CreateData&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>(I added the test JSON data)</p>
  
  <p>What I can't seem to figure out is how to turn this request which works correctly in SoapUI into a functioning piece of test Java code. </p>
  
  <p>When I import the WSDL into my IDE, it generates a single Java file which looks like this;</p>
  
  <pre><code>import javax.jws.WebService;
  
  @WebService(serviceName = "{redacted}", portName = "{redacted}", endpointInterface = "{redacted}", targetNamespace = "{redacted}", wsdlLocation = "WEB-INF/wsdl/null/null.wsdl")
  public class NewWebServiceFromWSDL {
  
      public java.lang.String createData(java.lang.String request) {
          //TODO implement this method
          throw new UnsupportedOperationException("Not implemented yet.");
      }
  
  }
  </code></pre>
  
  <p>Naturally, I now have no idea what to do next. How do I go about creating a SOAP Envelope in Java? I would have expected to see some methods generated for things such as setSOAPEnvelopeHeader(), setSOAPEnvelopeBody(), setSOAPEnvelopeVariableRequest() etc. (or similar). </p>
  
  <p>Then once the SOAP Envelope object has been created (however that is done), how do I then go about actually sending the message and handling the response? </p>
  
  <p>Feeling confused...</p>