Phumz88 / ksoap2-android

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

envelope.implicitTypes = false; being ignored #66

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Trying to remove the "n0=" from the "xmlns:n0=" within the soap envelope. From 
what I understand, the implicitTypes=false should accomplish this, but it seems 
to be ignored.

CODE:
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME_SEND);
SoapSerializationEnvelope envelope = new 
SoapSerializationEnvelope(SoapEnvelope.VER10);

// build our data elements
SoapObject instructions = new SoapObject(NAMESPACE, "instructions");
instructions.addProperty("messageId", message.getId());
instructions.addProperty("recipients", recipient.getId());
instructions.addProperty("shortText", shortText);
instructions.addProperty("longText", detailText);
request.addSoapObject(instructions);

// set the envelope and make the request
envelope.encodingStyle = SoapEnvelope.ENC;
envelope.dotNet = false;
envelope.setAddAdornments(false);
envelope.implicitTypes = false;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(soapUrl, 
CONNECTION_TIMEOUT);
httpTransport.debug = true;
httpTransport.call(SOAP_ACTION, envelope, headerPropertyList);

Traffic capture:
<v:Envelope xmlns:i="http://www.w3.org/1999/XMLSchema-instance" 
xmlns:d="http://www.w3.org/1999/XMLSchema" 
xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header 
/><v:Body><n0:sendMessage 
xmlns:n0="http://informacast.singlewire.com/MessageService/v2"><n0:instructions>
<messageId i:type="d:string">191</messageId><recipients 
i:type="d:string">924</recipients><shortText 
i:type="d:string"></shortText><longText 
i:type="d:string"></longText></n0:instructions></n0:sendMessage></v:Body></v:Env
elope>

Original issue reported on code.google.com by jam.mon...@gmail.com on 6 Jul 2011 at 3:08

GoogleCodeExporter commented 9 years ago
I have been having the same problem I have been working on this for over a week 
is there an alternative?

Original comment by Daysa...@gmail.com on 18 Jul 2011 at 10:17

GoogleCodeExporter commented 9 years ago
The only alternative I found (which I hate) was to build the request by hand:

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope 
SoapEnvelope.VER10);

envelope.encodingStyle = SoapEnvelope.ENC;
StringBuilder envelopeXml = new StringBuilder();
envelopeXml.append("<soap:Envelope ");
envelopeXml.append("xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" ");
envelopeXml.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");
envelopeXml.append("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">");
envelopeXml.append("<soap:Body xmlns:ms='http://feh.com/FehService/v2'>");
envelopeXml.append("<ms:sendMessage>");
envelopeXml.append("<instructions>");
envelopeXml.append("<messageId>"123</messageId>");
envelopeXml.append("<recipients>"456"</recipients>");
envelopeXml.append("<shortText>"+shortText+"</shortText>");
envelopeXml.append("<longText>"+longText+"</longText>");
envelopeXml.append("</instructions>");
envelopeXml.append("</ms:sendMessage>");
envelopeXml.append("</soap:Body>");
envelopeXml.append("</soap:Envelope>");

String soapXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
envelopeXml.toString();

URL url = new URL(soapUrl);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestProperty("SOAPAction", SOAP_ACTION_SEND);
connection.setRequestProperty("Content-Type", "text/xml");
connection.setRequestProperty("Content-Length","" + soapXML.getBytes().length);
connection.setRequestProperty("User-Agent", "kSOAP/2.0");
connection.setRequestProperty("Authorization", login);

connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setConnectTimeout(CONNECTION_TIMEOUT);

// send the request
OutputStream os = null;
try {
    os = connection.getOutputStream();
    os.write(soapXML.getBytes(), 0, soapXML.getBytes().length);
} catch (Exception e) {
    Log.e(LOG_TAG, "Error sending request.", e);
} finally {
    if (os != null) {
        try {
            os.close();
        } catch (Exception e2) {
        // don't care
        }
    }
}

Original comment by jam.mon...@gmail.com on 18 Jul 2011 at 2:47

GoogleCodeExporter commented 9 years ago
Why dont you debug and see what adds the ns in the framework and provide a 
patch that changes it?

Original comment by mosa...@gmail.com on 18 Jul 2011 at 4:23

GoogleCodeExporter commented 9 years ago
Project time constraints.

Original comment by jam.mon...@gmail.com on 18 Jul 2011 at 5:57

GoogleCodeExporter commented 9 years ago
Have you tried implict types = true?

Original comment by mosa...@gmail.com on 25 Aug 2011 at 7:00

GoogleCodeExporter commented 9 years ago
Hi, Is there an update on this solution, I am facing same problem in ksoap2.5.7 
version. Appreciate your inputs in this regard.

Original comment by mukund.r...@gmail.com on 7 Sep 2011 at 2:47

GoogleCodeExporter commented 9 years ago
Not from my end. 

Original comment by mosa...@gmail.com on 7 Sep 2011 at 3:32

GoogleCodeExporter commented 9 years ago
I am not a contributor to this project and have since dropped using it, so 
unless someone else fixed it I can only assume the bug still exists.

Original comment by jam.mon...@gmail.com on 8 Sep 2011 at 1:16

GoogleCodeExporter commented 9 years ago
there is an ugly hack/workaround, comment // xsi = SoapEnvelope.XSI; in ctor of 
SoapEnvelope class.

Original comment by rkovh...@gmail.com on 17 Apr 2012 at 1:39

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
There is a proposed fix in the master branch on github now. Could those 
affected by it please test and verify that it is working? 

See https://github.com/mosabua/ksoap2-android/pull/21

Original comment by mosa...@gmail.com on 5 Jun 2012 at 5:00

GoogleCodeExporter commented 9 years ago
Or  maybe provide a test case in SoapSerializationEnvelope that fails with a 
desired output so we can fix it.. 

Original comment by mosa...@gmail.com on 5 Jun 2012 at 6:13

GoogleCodeExporter commented 9 years ago
This fix works, but I also wnat to eliminate attributes such as "root" element 
from base object:

<?xml version="1.0" encoding="UTF-8"?>
<v:Envelope xmlns:v="http://schemas.xmlsoap.org/soap/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/">
   <v:Header />
   <v:Body>
      <n0:get-method xmlns:n0="urn:mynamespace" id="o0" c:root="1">
         <n0:mode>mm</n0:mode>
      </n0:get-method>
   </v:Body>
</v:Envelope>

Original comment by Dmitriy....@gmail.com on 17 Aug 2012 at 9:28

GoogleCodeExporter commented 9 years ago
That fix is in master now. I am not sure about removing the rest... maybe look 
at the code and provide a pull request.. 

Original comment by mosa...@gmail.com on 17 Aug 2012 at 7:30

GoogleCodeExporter commented 9 years ago

Original comment by mosa...@gmail.com on 13 Sep 2012 at 4:59