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
Please take a look at my code and output below. Thanks
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();
}
}
}
My Output
Soap Request:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><web:GetAtomicNumber xmlns:web="http://www.webserviceX.NET"><ElementName>sodium</ElementName></web:GetAtomicNumber></SOAP-ENV:Body></SOAP-ENV:Envelope>
Soap Response:
null
Update
This is what I am getting (Exception)
<faultcode>soap:Server</faultcode>
<faultstring>System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> 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 ---</faultstring>