larry03 / ksoap2-android

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

Sending complex objects with ksoap2 #144

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.The wcf service accepts a complex object and some strings as parameter
2.With the strings there is no problem
3.The complex object implements the Kvmserializable correctly I've also caught 
the message with a packet sniffer to see that is sent correctly
4.I use soapObjectRequest.addProperty("School","8"); for strings and
    PropertyInfo propertyInfo = new PropertyInfo();             
        propertyInfo.setName("objStudentAbsences"); 
for the object.

What is the expected output? What do you see instead?
I get an object reference from the wcf server.Though when i set 
soapSerializationEnvelope.implicitTypes = true; I don't get an object reference 
but the values aren't correct.I can't see them but my guess
is that they are zero(How i know: i get an sql exception)

What version of the product are you using? On what operating system?
Java platform, android application, 
ksoap2-android-assembly-2.6.2-jar-with-dependencies

Please provide any additional information below.
I'will provide only the sender class not the one which implements the 
kvserializable.This one is working correctly since I've seen the message i'm 
sending.I know that since it's sent correctly the mapping on the server side is 
problematic.So it is about the namespaces i guess.I will also post the soap 
request from the wcftestclient (meaning how i should send it) and the soap from 
what i actually send.Thank you for your time.

public class MainActivity extends Activity {
    private Button btn;
    private Button btn1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        StrictMode.ThreadPolicy policy = new  StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);

        btn=(Button) findViewById(R.id.button1);
        btn.setOnClickListener(new OnClickListener() {            
            public void onClick(View v) { 

                SoapObject soapObjectRequest = new SoapObject("http://microsoft.com/webservices/","InsertStudentAbsences");

                SRV_Students_Absence objStudentAbsences = new SRV_Students_Absence();

                PropertyInfo propertyInfo = new PropertyInfo();             
                propertyInfo.setName("objStudentAbsences");
                propertyInfo.setType(SRV_Students_Absence.class);
                propertyInfo.setValue(objStudentAbsences);

                PropertyInfo propertyInfo1 = new PropertyInfo();                
                propertyInfo1.setName("connString");
                propertyInfo1.setType(String.class);
                propertyInfo1.setValue("server=vertitech-sql,1524;Database=VertiSchoolDB;UID=sa;Password=7Esta#KAz");

//              PropertyInfo propertyInfo2 = new PropertyInfo();                
//              propertyInfo2.setName("Lng");
//              propertyInfo2.setType(String.class);
//              propertyInfo2.setValue("00");

                //soapObjectRequest.addProperty("connString","server=vech-sql,1524;Database=VertiSchoolDB;UID=sa;Password=7Az");
                soapObjectRequest.addProperty(propertyInfo1);
                soapObjectRequest.addProperty(propertyInfo);
                soapObjectRequest.addProperty("Company","8");
                soapObjectRequest.addProperty("Lng","00");
                soapObjectRequest.addProperty("MainPeriod","80");
                soapObjectRequest.addProperty("UserID","14453");
                soapObjectRequest.addProperty("CourseDate","2012-11-06");

                SoapSerializationEnvelope soapSerializationEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                soapSerializationEnvelope.dotNet = true;
                soapSerializationEnvelope.implicitTypes = true;             

                soapSerializationEnvelope.setOutputSoapObject(soapObjectRequest);

                soapSerializationEnvelope.addMapping(soapObjectRequest.getNamespace(), "SRV_Students_Absence", objStudentAbsences.getClass());
                //soapSerializationEnvelope.addMapping(soapObjectRequest.getNamespace(), "SRV_Absence_Category", SRV_Absence_Category.class);
//            
    soapSerializationEnvelope.addMapping("http://schemas.datacontract.org/2004/07/W
cfService_StudentGrades", "SRV_Student", SRV_Student.class);

                try {
                    /**
                     * Mail the letter.
                     */
                    HttpTransportSE httpTransportSE = new HttpTransportSE("http://androidwcf.school.gr");               
                    httpTransportSE.call("http://microsoft.com/webserv/"+"IVechool_SRV/InsertStudentAbsences", soapSerializationEnvelope);

                    httpTransportSE.debug=true;

                    SoapObject soapObjectResponse = (SoapObject)soapSerializationEnvelope.getResponse();

                } catch (Exception exception) {
                    exception.printStackTrace();

                }

            }
        });

    }

this is the soap-message of the wcftestclient:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://microsoft.com/webservices/IVertiSchool_SRV/InsertStudentAbsences</Action>
  </s:Header>
  <s:Body>
    <InsertStudentAbsences xmlns="http://microsoft.com/webservices/">
      <connString>server=vehl,152UID=sa;Password=7Esta#KAz</connString>
      <objStudentAbsences xmlns:d4p1="http://schemas.datacontract.org/2004/07/WcfService_StudentGrades" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <d4p1:AbCode>0</d4p1:AbCode>
        <d4p1:AbNum i:nil="true" />
        <d4p1:AbsCatID>421</d4p1:AbsCatID>
        <d4p1:ActID i:nil="true" />
        <d4p1:Cause i:nil="true" />
        <d4p1:ClCode>375</d4p1:ClCode>
        <d4p1:CoCode>7628</d4p1:CoCode>
        <d4p1:CompanyCode>8</d4p1:CompanyCode>
        <d4p1:CourseDate>2012-11-06T09:50:00</d4p1:CourseDate>
        <d4p1:Flag>false</d4p1:Flag>
        <d4p1:InsDate i:nil="true" />
        <d4p1:InsWay>3</d4p1:InsWay>
        <d4p1:IsParentsInf i:nil="true" />
        <d4p1:IsVerified i:nil="true" />
        <d4p1:LngCode i:nil="true" />
        <d4p1:MainPeriod i:nil="true" />
        <d4p1:SmsFlag i:nil="true" />
        <d4p1:StuCode>1359</d4p1:StuCode>
        <d4p1:TimeCode>1963</d4p1:TimeCode>
        <d4p1:UserIdName i:nil="true" />
        <d4p1:WPCID i:nil="true" />
        <d4p1:WPGID i:nil="true" />
        <d4p1:objAC i:nil="true" />
        <d4p1:objStudent i:nil="true" />
      </objStudentAbsences>
      <Company>8</Company>
      <Lng>00</Lng>
      <MainPeriod>80</MainPeriod>
      <UserID>14453</UserID>
      <CourseDate>2012-11-06</CourseDate>
    </InsertStudentAbsences>
  </s:Body>
</s:Envelope>

Original issue reported on code.google.com by libat...@gmail.com on 13 Nov 2012 at 10:16

GoogleCodeExporter commented 9 years ago
Ok I figured it out.Actually it has nothing to do with ksoap.It was about the 
namespace in the wcf.I'll just send post the article that literally saved me: 
http://stackoverflow.com/questions/12846149/passing-objects-to-wcf-soap-service-
from-android-using-ksoap2-it-sends-and-rece

Original comment by libat...@gmail.com on 15 Nov 2012 at 8:08

GoogleCodeExporter commented 9 years ago

Original comment by mosa...@gmail.com on 16 Nov 2012 at 3:31