Java and Soap

Since JDK 6 you have built in support for SOAP (SAAJ ).

There are many services that still use it, therefore consuming soap service is always usefull.

By creating a SOAP message you can add some attributes to the evlelop.

    try {
        SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
    } catch(SOAPException e) {

Then you can add your elements to the soap body.

    try {

        SOAPBody body = envelope.getBody();
        SOAPElement bodyElement = body.addChildElement(envelope.createName("Connect" , "ns1", ""));                                                      
        SOAPElement findItem = bodyElement.addChildElement("ItemName");
        findItem.setAttribute("xsi:type", "xsd:string");

    } catch(SOAPException e) {

After you are done you can use SOAPConnection to send your message and get the response as a SOAP message.

    try {

        SOAPConnection soapConnection = SOAPConnectionFactory.newInstance().createConnection();
        SOAPMessage returnMessage =,serverUrl);
    } catch(SOAPException e) {

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.