kvin024 / ksoap2-android

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

Issue sending a complex type object to KSOAP2 - The .net webservice getting paramerts as null #80

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. The .net web service API accepts 4 paramaters(DiningOrderDTO, DiningItemDTO, 
int, string)
2. Added respected values to Request.addProperty(key, value);
3. Added following mapping for both the objects mentioned above 
soapEnvelope.addMapping(NAMESPACE, 
DiningOrderDTO.class.getSimpleName(),DiningOrderDTO.class); 
4. Both the objects implemented KvmSerializable interface and overrided methods 
approriately.

What is the expected output? What do you see instead?
The .net API should get DiningOrderDTO, DiningItemDTO but the the service 
recieved both objects as null.

What version of the product are you using? On what operating system?
Clinet is Java using KSOAP2 and service is in .net

Please provide any additional information below.
Please check all my code below and let me know your thoughts 

SoapObject Request = new SoapObject(NAMESPACE,METHOD_NAME);
//DiningOrderDTO - values populated
//DiningItemDTO - values populated
Request.addProperty("DiningOrderDTO", diningOrderDTO);
Request.addProperty("DiningItemDTO", diningItemDTO);
Request.addProperty(key, object);
Request.addProperty(key, object);

  SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        soapEnvelope.dotNet = true;
        soapEnvelope.setOutputSoapObject(Request);

 MarshalDate md = new MarshalDate();
        md.register(soapEnvelope);

        MarshalDouble marshalDouble = new MarshalDouble();
        marshalDouble.register(soapEnvelope);

AndroidHttpTransport aht = new AndroidHttpTransport(URL);

        try
        {
            aht.debug = true;
            aht.call(SOAP_ACTION,soapEnvelope);
            Object object =  soapEnvelope.getResponse();
            return object;
        }
        catch (Exception e)
        {
            String s=e.getMessage();
        }

Original issue reported on code.google.com by jul...@gmail.com on 30 Aug 2011 at 9:23

GoogleCodeExporter commented 9 years ago
check that the requestDump is as expected by the .net webservice using 
debugging as documented on the wiki

Original comment by mosa...@gmail.com on 30 Aug 2011 at 9:45

GoogleCodeExporter commented 9 years ago
Thank for the reply, I checked my request dump its mentioned below
The .net service method 
PlaceDiningOrder(DiningOrderDTO orderDetails, List<DiningItemDTO> items, int 
gID, int pID)
Am I missing anything here ?

<PlaceDiningOrder xmlns="http://tempuri.org/" id="o0" c:root="1">

<DiningOrderDTO i:type="n0:DiningOrderDTO" xmlns:n0="http://tempuri.org/">
    <gID i:type="d:int">2444</gID>
    <isInitialOrder i:type="d:boolean">true</isInitialOrder>
    <paymentType i:type="d:string">cash</paymentType>
    <requestedDeliveryDatetime i:type="d:dateTime"></requestedDeliveryDatetime>
    <serveFor i:type="d:int">1</serveFor>
    <totalAmount i:type="d:decimal">19</totalAmount>
</DiningOrderDTO>

<DiningItemDTO i:type="n1:DiningItemDTO" xmlns:n1="http://tempuri.org/">
    <active i:type="d:boolean">true</active>
    <counterID i:type="d:int">0</counterID>
    <description i:type="d:string">Wilted Swiss chard and bean cassoulet with choice of 2 sides and 1 sauce.</description>
    <diningCategoryID i:type="d:int">18</diningCategoryID>
    <diningItemID i:type="d:int">54</diningItemID>
    <diningItemModifierCategories i:null="true" />
    <hasModifiers i:type="d:boolean">false</hasModifiers>
    <imageURL i:null="true" /><instructions i:null="true" />
    <itemOrder i:type="d:double">0.0</itemOrder>
    <name i:type="d:string">Half Chicken Cooked Under a Brick</name>
    <price i:type="d:decimal">19</price>
    <quantity i:type="d:int">1</quantity>
    <totalPriceWithModifiers i:type="d:decimal">19</totalPriceWithModifiers>
</DiningItemDTO>

<gID i:type="d:int">2444</gID>

<pID i:type="d:int">1</ID>

</PlaceDiningOrder>

Original comment by jul...@gmail.com on 1 Sep 2011 at 5:23

GoogleCodeExporter commented 9 years ago
Hi, I have been stuck on the same issue for about a week.
Finally found what the problem is, just not sure how to resolve.

<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>
    <n0:GetDate id="o0" c:root="1" xmlns:n0="http://tempuri.org/">
      <dt i:type="d:dateTime">1970-01-01T00:00:00.033Z</dt>
    </n0:GetDate>
  </v:Body>
</v:Envelope>

Using the code requestDump above. This section "xmlns:n0="http://tempuri.org/"" 
is breaking .net ws calls, causing it to ignore input parameters. What is 
should look like is something like this "xmlns="http://tempuri.org/" and also 
remove the "n0" reference all over the request.

so your final xml should ideally look this, 

<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>
    <GetDate id="o0" c:root="1" xmlns="http://tempuri.org/">
      <dt i:type="d:dateTime">1970-01-01T00:00:00.033Z</dt>
    </GetDate>
  </v:Body>
</v:Envelope>

This xml above works, however i am not sure how to fix my Ksoap2 jar file 
without the actual source. Please can you advise as to how to resolve?

Original comment by spoon...@gmail.com on 2 Sep 2011 at 4:48

GoogleCodeExporter commented 9 years ago
The source is on github so feel free to investigate with it and fix. However 
there might be a different issue since it works for me and many others with 
.net web services.

Original comment by mosa...@gmail.com on 2 Sep 2011 at 4:53

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Sorry... but I do not have the time to do that without being paid.. 

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

GoogleCodeExporter commented 9 years ago
Hi all,

To get the type of xml you need just especify:
  envelope.dotNet = true;

I spent the whole day trying to pass a String to my webservice and there are a 
lot of rules to follow for a parameter not to be null. On some posts all over 
the internet you will read about setting this property to false, but at first I 
was having this:

<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>
    <n0:LeerCodigo id="o0" c:root="1" xmlns:n0="uplatform/entrada">
      <psParametrosJSON i:type="d:string">Param</psParametrosJSON>
    </n0:LeerCodigo>
  </v:Body>
</v:Envelope>

... and after setting envelope.dotNet = true I get:
<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>
    <LeerCodigo xmlns="uplatform/entrada" id="o0" c:root="1">
      <psParametrosJSON i:type="d:string">Param</psParametrosJSON>
    </LeerCodigo>
  </v:Body>
</v:Envelope>

and finally I can receive the String parameter.

Hope this helps, at least for you to get the xml format you were expecting.

Regards.

Original comment by ramon.ru...@gmail.com on 1 Nov 2011 at 6:58

GoogleCodeExporter commented 9 years ago
Evidently setting .net to true did the trick as expected.

Original comment by mosa...@gmail.com on 18 Nov 2011 at 5:33