Capoaguilar / ksoap2-android

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

XML node names for Vector (array) properties. #29

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am working with a WebService that receives an array as a parameter. I found 
that this kind of parameters is passed using Vectors.

The problem is that kSoap always renders xml nodes with "item" as the node name 
of each element in the Vector.

Because I am developing my WebService with .NET and I have more than one 
methods that receive array parameters of various types, I can't map the "item" 
node name to multiple types on .NET because this causes errors at runtime.

Given this, we fall on the need to download the kSoap sources and make a slight 
change to have correct communication between kSoap and my WebServices.

As I believe this change could be useful for other people, I am submitting the 
patch file throught this list so that you can evaluate it and, if you thinks is 
appropiate, apply the patch to the official code.

Thank you.

Original issue reported on code.google.com by hz.ed...@gmail.com on 6 Sep 2010 at 5:01

Attachments:

GoogleCodeExporter commented 9 years ago
Can you confirm that you are happy to license these patches as Apache V2 for 
inclusion and provide your contact details to add to the license file? 

Original comment by mosa...@gmail.com on 12 Oct 2010 at 6:57

GoogleCodeExporter commented 9 years ago

Original comment by mosa...@gmail.com on 12 Oct 2010 at 6:57

GoogleCodeExporter commented 9 years ago
Yes, I have no problem licensing the patches as Apache V2. How should I provide 
my contact details?

Original comment by hz.ed...@gmail.com on 20 Oct 2010 at 7:57

GoogleCodeExporter commented 9 years ago
Just your full name and email address to add to the license.txt file. You can 
email me personally instead of posting here.

Original comment by mosa...@gmail.com on 21 Oct 2010 at 4:42

GoogleCodeExporter commented 9 years ago

Original comment by mosa...@gmail.com on 21 Oct 2010 at 4:42

GoogleCodeExporter commented 9 years ago
Applied patch to github: 
http://github.com/mosabua/ksoap2-android/commit/a5231af66fad440a0ade78dce5ba4ac0
e954abb0

It will make it out with the next release. Can you verify it works for you in 
the meantime?

Original comment by mosa...@gmail.com on 22 Oct 2010 at 3:55

GoogleCodeExporter commented 9 years ago
Yes, I will verify it on this ongoing week. I will let you know on 
Saturday-Sunday. I have mailed you my contact details.

Thank you!

Original comment by hz.ed...@gmail.com on 4 Nov 2010 at 7:07

GoogleCodeExporter commented 9 years ago
You are already in the license file and this patch went out with the last 
release. 2.5.2

Original comment by mosa...@gmail.com on 4 Nov 2010 at 7:13

GoogleCodeExporter commented 9 years ago
Ok, there is no problem. Sorry for the late response. I will update and start 
using the official release.

Thank you again!

Original comment by hz.ed...@gmail.com on 4 Nov 2010 at 7:25

GoogleCodeExporter commented 9 years ago
No problem. Thank you. Keep the patches coming ;-)

Original comment by mosa...@gmail.com on 4 Nov 2010 at 7:56

GoogleCodeExporter commented 9 years ago
Is this patch already released and does it work fine? Do I need to do anything 
special to get rid of <Item> tag while serializing vectors? I tried 2.5.2 and 
2.5.4 and I still get <Item> tag while serializing vector and that throws off 
JAXWS based webservice on the server side. Please advise...

Original comment by perry.lu...@gmail.com on 12 Apr 2011 at 4:10

GoogleCodeExporter commented 9 years ago
Is this patch already released and does it work fine? Do I need to do anything 
special to get rid of <Item> tag while serializing vectors? I tried 2.5.2 and 
2.5.4 and I still get <Item> tag while serializing vector and that throws off 
JAXWS based webservice on the server side. Please advise...

Original comment by perry.lu...@gmail.com on 12 Apr 2011 at 4:11

GoogleCodeExporter commented 9 years ago
Is this patch already released and does it work fine? Do I need to do anything 
special to get rid of <Item> tag while serializing vectors? I tried 2.5.2 and 
2.5.4 and I still get <Item> tag while serializing vector and that throws off 
JAXWS based webservice on the server side. Please advise...

Original comment by perry.lu...@gmail.com on 12 Apr 2011 at 4:11

GoogleCodeExporter commented 9 years ago
Is this patch already released and does it work fine? Do I need to do anything 
special to get rid of <Item> tag while serializing vectors? I tried 2.5.2 and 
2.5.4 and I still get <Item> tag while serializing vector and that throws off 
JAXWS based webservice on the server side. Please advise...

Original comment by perry.lu...@gmail.com on 12 Apr 2011 at 4:12

GoogleCodeExporter commented 9 years ago
First of all, this patch was intended for .NET server, although it may work for 
servers based on php, java, etc.

When you create your envelope your envelope, specify that you are using a 
dotNet server and you are using implicitTypes:

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

Lastly, when you add your object to the envelope, you should add it with the 
help of PropertyInfo class like this:

PropertyInfo pi = new PropertyInfo();
pi.setName("NameOfTheTagForYourVector");
pi.setValue(YourVector);
pi.setType(PropertyInfo.VECTOR_CLASS); 
pi.elementType = new PropertyInfo();
pi.elementType.type = YourVectorItemsClass.class;
pi.elementType.name = "NameOfTheTagForTheItems"; // <-- This is what will be 
sent in the output instead of the "<Item>".
yourRequest.addProperty(pi); 

That should print "NameOfTheTagForTheItems" instead of "Item" on the child 
nodes of the vector.

Original comment by hz.ed...@gmail.com on 12 Apr 2011 at 4:46

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
How do I do this if I am passing object A with embedded vector of Object B in A?

Original comment by perry.lu...@gmail.com on 12 Apr 2011 at 5:31

GoogleCodeExporter commented 9 years ago
In my example, I was adding an array in the toplevel of the request. If you 
have a soap object that contains an array inside, the code is exactly the same. 
The only difference is that instead calling "yourRequest.addProperty(pi);" you 
call "yourSoapObject.addProperty(pi)";

If you are implementing KmlSerializable, you should add this to the 
getPropertyInfo method of your class.

Original comment by hz.ed...@gmail.com on 12 Apr 2011 at 7:47

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Can you please give me a quick snippet of getPropertyInfo with two vectors 
embedded into the top level object? I am still not clear as "yourSoapObject" in 
your comment above does not seem to have "addProperty"" method. That's really 
my top level object which is KmlSerializable.

Original comment by perry.lu...@gmail.com on 12 Apr 2011 at 8:54

GoogleCodeExporter commented 9 years ago
I only use this on one of my objects, and my class that implements 
KmlSerializable has only one vector, and the method getPropertyInfo is as 
follows:

    public Vector<PointSerializable> Vertices;

    public void getPropertyInfo(int idx, Hashtable hash, PropertyInfo propInfo) {
        Field f = this.getClass().getFields()[idx];

        propInfo.name = f.getName();
        propInfo.type = f.getType();

        PropertyInfo arrType = new PropertyInfo();
        arrType.name = "point";
        arrType.type = PointSerializable.class;
        arrType.namespace "businessNS";
        propInfo.elementType = arrType;
    }

This is exactly as I have implemented the code (I copied and pasted the method) 
on a class implementing KmlSerializable with only ONE attribute. If your class 
has more attributes, you only need to make a switch on "idx" and fill propInfo 
with the correct data for every case.

Hope this is more clear. If not, feel free to ask more details.

Original comment by hz.ed...@gmail.com on 12 Apr 2011 at 9:04

GoogleCodeExporter commented 9 years ago
If you could please see attached the code and let me know what i am doing 
wrong. 
I am expecting this in the body:
<person><contacts<kind>Phone</kind><type>Home</type><value>4809998888</value><pr
eferred 
i:type="d:boolean">false</preferred></contacts><company>MyCo</company><displayNa
me>MyDisplayName</displayName><firstName>F222</firstName><lastName>L222</lastNam
e><middleName/><modifiedDate/><personId></person>

-----------------------------

But getting something like this: Notice double <contacts> tags...that's the 
major issue.

<person><contacts 
c:arrayType="d:anyType[1]"><contacts><kind>Phone</kind><type>Home</type><value>4
809998888</value><preferred 
i:type="d:boolean">false</preferred></contacts></contacts><addresses 
c:arrayType="d:anyType[0]" 
/><company>MyCo</company><displayName>MyDisplayName</displayName><firstName>F222
</firstName><lastName>L222</lastName><middleName i:null="true" /><modifiedDate 
i:null="true" /><personId i:null="true" /></person>

Original comment by perry.lu...@gmail.com on 12 Apr 2011 at 9:40

Attachments:

GoogleCodeExporter commented 9 years ago
In the output you provided, kSoap is working correctly. My provided patch was 
done to work this way.

As far I know, vector support in kSoap (I think that this should be confirmed 
by the project owner) was included to generate an output like this:

<object>
 <vectorItemsContainer>
  <vectorItem1/>
  <vectorItem2/>
  [...]
  <vectorItemN/>
 </vectorItemsContainer>

 <attribute1/>
 <attribute2/>
 [...]
 <attributeN/>
</object>

But... I understand that you want an output like this (ommiting the container 
for the items of the vector):

<object>
 <vectorItem1/>
 <vectorItem2/>
 [...]
 <vectorItemN/>

 <attribute1/>
 <attribute2/>
 [...]
 <attributeN/>
</object>

Sorry, but this goes out of the scope of vector support in kSoap (again, this 
should be confirmed by the project owner).

You can obtain the output that you need, but you need to do another kind of 
tricks in your Person class.

Original comment by hz.ed...@gmail.com on 13 Apr 2011 at 3:33

GoogleCodeExporter commented 9 years ago
Thanks for the response. I dont think I want to ommit the container. As you can 
see 
I want something like below where "contacts" is the vercor container. It is 
just that I am not able to achieve that with the example that you provided. Can 
you please give me a better code snippet that will work for me? 

<person><contacts<kind>Phone</kind><type>Home</type><value>4809998888</value><pr
eferred 
i:type="d:boolean">false</preferred></contacts><company>MyCo</company><displayNa
me>MyDisplayName</displayName><firstName>F222</firstName><lastName>L222</lastNam
e><middleName/><modifiedDate/><personId></person>

Original comment by perry.lu...@gmail.com on 13 Apr 2011 at 4:23

GoogleCodeExporter commented 9 years ago
On line 56 of your attached code, I would put arrType.name = "contact"; or 
arrType.name = "personContact", or whatever. This will remove the duplicate 
"contacts" tag. However, the output will be:

<person>
 <contacts>
  <personContact>
   <kind>Phone</kind>
   <type>Home</type>
   [...]
  </personContact>
  <personContact>
   <kind>Phone</kind>
   <type>Work</type>
   [...]
  </personContact>

  [... More contacts ...]
 </contacts>

 [...More fields...]
</person>

If the node "contacts" is the vector container (the one you say want to have in 
the output), then, there still remains the "personContact" tags. If you don't 
want these tags, you are removing the nodes that identify and delimit each item 
on the vector, which (again) is not possible with kSoap vector support. 

I don't know how you want your output if the vector contains more than one item 
(contact). You are giving an example of how it should be if the vector contains 
only one item. If your vector won't contain more than one item, simply don't 
use a vector and you will have your needed output. 

Original comment by hz.ed...@gmail.com on 13 Apr 2011 at 4:59

GoogleCodeExporter commented 9 years ago
So here is the working request going out from JAXWS generated client and that 
works. Notice there are two contacts going out. How do I achieve this?

<?xml version="1.0" ?><S:Envelope 
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:addPerson 
xmlns:ns2="http://test/"><accountID>123456</accountID><person><firstName>NB1</fi
rstName><lastName>NB2</lastName><contacts><kind>Phone</kind><value>5556667777</v
alue><type>Work</type><preferred>true</preferred></contacts><contacts><kind>Phon
e</kind><value>5556667777</value><type>Work</type><preferred>true</preferred></c
ontacts></person></ns2:addPerson></S:Body></S:Envelope>

Original comment by perry.lu...@gmail.com on 13 Apr 2011 at 5:10

GoogleCodeExporter commented 9 years ago
Your JAXWS generated client is effectively ommiting the node that acts as a 
container for the items of the vector. This is what I tried to explain in the 
comment #23, and you said you don't want to do on comment #24.

Sorry, but you can't get this output from kSoap using KmlSerializable and 
Vectors. You will need to use some tricks to get this request using 
KmlSerializable. Another option is use SoapObject class instead of implementing 
KmlSerializable.

I haven't needed the output for vectors like this, so I don't have any code to 
make suggestions to include in your Person class, and it is not very trivial. 
Sorry for not being able to help you too much.

On the other hand, SoapObject class is so easy to use, that I don't think you 
need too much help to achieve what you need. Just try first!

Please, note that this "Issues" list is for placing queries about potential 
problems (defects, errors, enhacements, etc) with the kSoap library, not for 
asking how to use kSoap. I have been answering having in mind that my patch may 
be causing an error and may have a bug, but it is clear that it isn't and the 
thread has gone out of scope. So, I think that I shouldn't answer anymore to 
you question on "how to achieve your required request".

If you need to ask more questions, please use any forum that you can find on 
the Internet. In forums, there is much more people that can help (including 
me). Here are only the mantainers of the project.

If you believe that kSoap should support vectors on the way require, please 
open a new Issue to see if it is approved. 

Original comment by hz.ed...@gmail.com on 13 Apr 2011 at 6:56

GoogleCodeExporter commented 9 years ago
Sir,i am new to android and want to know how to implement the above code in my 
application in order to call .Net webservice in my application.
Thanks in advance

Original comment by sneha.ra...@gmail.com on 14 Oct 2011 at 6:56