0

I have a problem with create SOAP request. I have a works request from command line with usage curl

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
 <s:Body>
  <u:SetVolume xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1">
   <InstanceID>0</InstanceID>
   <Channel>Master</Channel>
   <DesiredVolume>20</DesiredVolume>
  </u:SetVolume>
 </s:Body>
</s:Envelope> | curl -v -d @-  -H 'SOAPAction: "urn:schemas-upnp-org:service:RenderingControl:1#SetVolume"'  -H 'content-type: text/xml; charset="utf-8"'  http://192.168.0.172:1400/MediaRenderer/RenderingControl/Control

I tried crate equivalent in JAVA

  import javax.xml.namespace.QName;
import javax.xml.soap.*;

public class SOAPClientSAAJ {


    public static void main(String args[]) {
        try {
                MessageFactory mf = MessageFactory.newInstance();
                SOAPMessage sm = mf.createMessage();
                SOAPHeader sh = sm.getSOAPHeader();
                SOAPBody sb = sm.getSOAPBody();
                sh.detachNode();

                QName bodyName = new QName("urn:schemas-upnp-org:service:RenderingControl:1#SetVolume", "SetVolume", "u");
                SOAPBodyElement bodyElement = sb.addBodyElement(bodyName);

                QName instanceID = new QName("InstanceID");
                QName channel = new QName("Channel");
                QName volumeLevel = new QName("DesiredVolume");

                SOAPElement qInstanceID = bodyElement.addChildElement(instanceID);
                SOAPElement qChannel = bodyElement.addChildElement(channel);
                SOAPElement qVolumeLevel = bodyElement.addChildElement(volumeLevel);

                qInstanceID.addTextNode("0");
                qChannel.addTextNode("Master");
                qVolumeLevel.addTextNode("30");

                sm.writeTo(System.out);
                System.out.println();
        } catch(Exception e) {

        }
    }
}

This give me build request

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Body>
      <u:SetVolume xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1#SetVolume">
         <InstanceID>0</InstanceID>
         <Channel>Master</Channel>
         <DesiredVolume>30</DesiredVolume>
      </u:SetVolume>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Unfortunately this don't want to works. I supose that problem is in HEADER, but actualy I don't know how to pass them in other way to my request. I also try solution from, but also get error

SOAP request to WebService with java

Mbded
  • 1,754
  • 4
  • 23
  • 43

1 Answers1

0

It seems like you are setting wrong QName. What you are setting is action so apart from that your generated soap envelope is fine I would suggest you to try calling this using SOAP UI.

Eshu
  • 499
  • 4
  • 15