I want to send an envelope with an empty body like this:
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns:d="http://www.w3.org/2001/XMLSchema"
xmlns:c="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header />
<v:Body>
</v:Body>
</v:Envelope>
Is it possible and how? I've tried with开发者_Python百科 this:
HttpsTransportSE transport = new HttpsTransportSE(HOST, PORT, ENDPOINT, TIMEOUT);
SoapObject request = new SoapObject(null, null);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
transport.call(SOAP_ACTION, envelope);
I can't seem to figure out how to do it, can anyone please help?
I have fixed the problem by creating my own SoapSerializationEnvelope extending the original one and overridering the writeBody method with this: public class MySoapEnvelope extends SoapSerializationEnvelope
{
public MySoapEnvelope(int version) {
super(version);
}
@Override
public void writeBody(XmlSerializer writer) throws IOException
{
if (bodyOut!=null){
super.writeBody(writer);
}
}
}
To use it, you just have to use the MySoapSerializationEnvelope and set envelope.bodyOut=null;
HttpsTransportSE transport = new HttpsTransportSE(host, port, endpoint, timeout);
MySoapEnvelope emptySoapEnvelope = new MySoapEnvelope(SoapEnvelope.VER11);
emptySoapEnvelope.bodyOut = null;
transport.call(methodname, emptySoapEnvelope);
I dont know if you want to cut a new release with this code. I would possibly make a new method in the original SoapEnvelope called setEmptyEnvelope(). But that's up to you. You could get along with this, but then you should make a respectable documentation so people would know this is how it's done.
Interesting. You might want to debug into the framework to see what is going on. If you can create a fix for it I am happy to pull it into upstream and cut a new release.
精彩评论