Removing i:type field in SOAP request generated by kSoap2 on Android
Asked Answered
N

3

5

I already tried reading the internet about my issue, but I could not find the right information I need, so I try to explain my issue:

I am using kSoap2 to "talk" to a webservice over SOAP. To generate my SOAP request I use the following code:

// Generate SOAP request XML
SoapObject request = new SoapObject(PUB_NAMESPACE,
"testSoapInterface");   

// Add request header
PropertyInfo requestHeader = new PropertyInfo();
requestHeader.setNamespace(PUB_NAMESPACE);
requestHeader.setName("requestheader");

// Generate username property
PropertyInfo usernameProp = new PropertyInfo();
usernameProp.setNamespace(BASE_NAMESPACE);
usernameProp.setName("username");
usernameProp.setValue(username);

// Generate applicationId property
PropertyInfo applicationIdProp = new PropertyInfo();
applicationIdProp.setNamespace(BASE_NAMESPACE);
applicationIdProp.setName("applicationId");
applicationIdProp.setValue("test");

// Add properties to requestHeader (nested)
requestHeader.setValue(new SoapObject(PUB_NAMESPACE, "requestheader")
.addProperty(usernameProp)
.addProperty(applicationIdProp));

request.addProperty(requestHeader);

Now, to serialize this, I use the following:

// Serialize SOAP request to the non .NET based SOAP server
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = false;
soapEnvelope.implicitTypes = true;
soapEnvelope.setAddAdornments(false);
soapEnvelope.setOutputSoapObject(request);

Because I am using nested soap (the requestheader consists of applicationId and username) I can imagine that this might be the cause. I also have to use different namespaces for the different lines, which can also be a cause.

Can anybody help me on this?? Thanks!

Nils answered 24/4, 2012 at 21:20 Comment(2)
Additional info: I am using kSoap 2.6.3 and I want to get rid of the i:type field in the generated start tag for the "requestheader".Nils
@Niels_D..did you solve the problem..it would be great if you post a solution..Fifty
D
6

You can use implicitTypes property of your envelope:

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.implicitTypes = true;

In this way the generated xml will not contain i:type.

Dodder answered 6/6, 2014 at 12:27 Comment(0)
P
2

Had the same Problem, seems to be impossible to use PropertyInfo without generating any i:type with it. Nice solution would be to Override AddProperty(PropertyInfo pi) so it works on any case without the i:Type.

Got three solutions to offer:

1

If u dont need the Namespace then request.AddProperty(name,value) does it!

2

U could make your request header an own SoapObject, it wont use the "i:type".

SoapObject requestHeader = new SoapObject(NAMESPACE,"requestheader"); 

and in the last line

request.AddSoapObject(requestHeader);

3

For me it worked to set the Version of the SoapEnvelope to "VER10" since the types are ignored then. They're still in your request but ignored. Replace:SoapEnvelope.VER11 with:SoapEnvelope.VER10

Pisano answered 11/10, 2012 at 9:36 Comment(0)
P
0

Where ever you are creating

 SoapSerializationEnvelope sEnvelop;

just assign sEnvelop.implicitTypes = true;

it will not create "i:type="d:string"" or "i:type="d:long"" inner datatype tag and web service can execute successfully

Poaceous answered 12/1, 2017 at 13:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.