larry03 / ksoap2-android

Automatically exported from code.google.com/p/ksoap2-android
0 stars 0 forks source link

Option to not produce a SOAP Header on the request #198

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Creating a new issue as this one was closed due to inactivity:
https://code.google.com/p/ksoap2-android/issues/detail?id=37

I was starting to use ksoap2-android for a project and hit a wall.  Basically 
the webservice provider I am interacting with does not like it when the SOAP 
header is sent into the request.

Basically what I am asking here is it possible to provide an option in the 
SoapSerializationEnvelope to skip the SOAP header element?

I don't mind working on this enhancement just wanted to make sure this hasn't 
already been solved.

Original issue reported on code.google.com by mba...@gmail.com on 13 Sep 2014 at 7:47

GoogleCodeExporter commented 9 years ago
I had some time today and did a quick fix just so I could use ksoap and get 
past my issue.  Here is my class, but basically I was hoping this option could 
be rolled into org.ksoap2.serialization.SoapSerializationEnvelope.  Let me know 
what you think:

public class SoapSerializationEnvelope extends 
org.ksoap2.serialization.SoapSerializationEnvelope {
        private boolean outputSoapHeader = true;

        public SoapSerializationEnvelope(int version) {
            super(version);
        }

        public boolean isOutputSoapHeader() {
            return outputSoapHeader;
        }

        public void setOutputSoapHeader(boolean outputSoapHeader) {
            this.outputSoapHeader = outputSoapHeader;
        }

        @Override
        public void write(XmlSerializer writer) throws IOException {
            writer.setPrefix("i", xsi);
            writer.setPrefix("d", xsd);
            writer.setPrefix("c", enc);
            writer.setPrefix("v", env);
            writer.startTag(env, "Envelope");

            if (outputSoapHeader) {
                writer.startTag(env, "Header");
                writeHeader(writer);
                writer.endTag(env, "Header");
            }

            writer.startTag(env, "Body");
            writeBody(writer);
            writer.endTag(env, "Body");
            writer.endTag(env, "Envelope");
        }
    }

Original comment by mba...@gmail.com on 14 Sep 2014 at 2:43

GoogleCodeExporter commented 9 years ago
Thought about this a little more and it would probably be better to detect if 
anything has been added in the soap header or not.  Then the option would only 
suppress the element if it's empty.

At least the example I have above shows if you have a service provider that 
doesn't like this I guess it's a temporary workaround.

Original comment by mba...@gmail.com on 14 Sep 2014 at 2:45