I am trying to call a SOAP .NET webservice from Android that requires a request that contains an element like this (generated from a .NET webservice client):
<InputVariable>
<Id>MyVariable</Id>
<Value i:type="a:string" xmlns:a="http://www.w3.org/2001/XMLSchema">Hello</Value>
</InputVariable>
There are a couple of odd things here that kSOAP doesn't appear to support directly. One, is I could not find a way in kSOAP to generate a property that also had an attribute. I found this answer which was able to get me further, but still not exact. Here is what I get with that solution:
<InputVariable>
<Id>MyVariable</Id>
<Value i:type="http://www.w3.org/2001/XMLSchema:string">Hello</Value>
</InputVariable>
SoapObject inputVariable = new SoapObject("", "InputVariable");
inputVariable.addProperty("Id", "MyVariable");
AttributeInfo att = new AttributeInfo();
att.setName("type");
att.setNamespace("http://www.w3.org/2001/XMLSchema-instance");
// I need some way to set the value of this to a namespaced string
att.setValue("http://www.w3.org/2001/XMLSchema:string");
ValueSoapObject valueProperty = new ValueSoapObject("", "Value");
valueProperty.setText("Hello");
valueProperty.addAttribute(att);
inputVariable.addSoapObject(valueProperty);
At runtime, the server fails with an error that it can't deserialize:
Value' contains data from a type that maps to the name '://www.w3.org/2001/XMLSchema:string'. The deserializer has no knowledge of any type that maps to this name.
How can I generate this type of SOAP property using kSOAP for Android?
Im not really sure if this is panaceum for Your problem, but SoapSerializationEnvelope::implicitTypes set to false, forces adding types to values. So fe. simple vesion of Your request built like that:
SoapObject request = new SoapObject("", "InputVariable");
request.addProperty("Id", "MyVariable");
request.addProperty("Value", "Hello");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.implicitTypes = false;
envelope.setOutputSoapObject(request);
produces such request:
<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>
<InputVariable xmlns="" id="o0" c:root="1">
<Id i:type="d:string">MyVariable</Id>
<Value i:type="d:string">Hello</Value>
</InputVariable>
</v:Body>
</v:Envelope>
Possibly Your WS will like this ;) Regards, Marcin