title: How to get response from SOAP endpoint in java?
body: <p>I am very new to SOAP, so was looking into some programs online, this is what I came up with but I get a null response, must be some silly thing, but need little help</p>
  
  <p>Please take a look at my code and output below. Thanks</p>
  
  <p>Code</p>
  
  <pre><code>import java.net.URL;
  
  import javax.xml.namespace.QName;
  import javax.xml.soap.MessageFactory;
  import javax.xml.soap.SOAPBody;
  import javax.xml.soap.SOAPBodyElement;
  import javax.xml.soap.SOAPConnection;
  import javax.xml.soap.SOAPConnectionFactory;
  import javax.xml.soap.SOAPElement;
  import javax.xml.soap.SOAPHeader;
  import javax.xml.soap.SOAPHeaderElement;
  import javax.xml.soap.SOAPMessage;
  
  public class AtomicNumber {
    public static void main(String[] args) {
      try {
        SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = sfc.createConnection();
  
        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage smsg = mf.createMessage();
  
        SOAPHeader shead = smsg.getSOAPHeader();
  
        SOAPBody sbody = smsg.getSOAPBody();
        shead.detachNode();
        QName bodyName = new QName("http://www.webserviceX.NET", "GetAtomicNumber", "web");
        SOAPBodyElement bodyElement = sbody.addBodyElement(bodyName);
        QName qn = new QName("ElementName");
        SOAPElement quotation = bodyElement.addChildElement(qn);
  
        quotation.addTextNode("iron");
  
        System.out.println("\n Soap Request:\n");
        smsg.writeTo(System.out);
        System.out.println();
  
        URL endpoint = new URL("http://www.webservicex.net/periodictable.asmx");
        SOAPMessage response = connection.call(smsg, endpoint);
  
      System.out.println("\n Soap Response:\n");
  
       System.out.println(response.getContentDescription());
  
  
      } catch (Exception ex) {
        ex.printStackTrace();
      }
  }
  }
  </code></pre>
  
  <p>My Output </p>
  
  <pre><code> Soap Request:
  
  &lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;SOAP-ENV:Body&gt;&lt;web:GetAtomicNumber xmlns:web="http://www.webserviceX.NET"&gt;&lt;ElementName&gt;sodium&lt;/ElementName&gt;&lt;/web:GetAtomicNumber&gt;&lt;/SOAP-ENV:Body&gt;&lt;/SOAP-ENV:Envelope&gt;
  
   Soap Response:
  
  null
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>This is what I am getting (Exception)</p>
  
  <pre><code>&lt;faultcode&gt;soap:Server&lt;/faultcode&gt;
       &lt;faultstring&gt;System.Web.Services.Protocols.SoapException: Server was unable to process request. ---&gt; System.Data.SqlClient.SqlException: Procedure or function 'GetAtomicNumber' expects parameter '@ElementName', which was not supplied.
  at WebServicex.periodictable.GetAtomicNumber(String ElementName)
   --- End of inner exception stack trace ---&lt;/faultstring&gt;
  </code></pre>