Error with kSOAP2

548 views Asked by At

I am trying to submit a username and the device ID of the phone to my Server but I keep getting following error:

W/System.err﹕ SoapFault - faultcode: 'soap:Client' faultstring: 'Unmarshalling Error: unexpected element (uri:"http://eventmanagement.management.de/", local:"username"). Expected elements are <{}deviceID>,<{}username> ' faultactor: 'null' detail: null

This is my code:

       PropertyInfo pi = new PropertyInfo();
       pi.setNamespace(NAMESPACE);
       pi.setName("username");
       pi.setValue(userName.getText().toString());
       pi.setType(PropertyInfo.STRING_CLASS);
       request.addProperty(pi); 
       pi.setNamespace(NAMESPACE);
       pi.setName("deviceID");

       pi.setValue(android.provider.Settings.Secure.getString(
       getContentResolver(), 
       android.provider.Settings.Secure.ANDROID_ID));
       pi.setType(PropertyInfo.STRING_CLASS);
       request.addProperty(pi);

        SoapSerializationEnvelope envelope = 
         new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

This is the wsdl file:

 <xs:complexType name="addUser">
   <xs:sequence>
    <xs:element minOccurs="0" name="username" type="xs:string"/>
    <xs:element minOccurs="0" name="deviceID" type="xs:string"/>
   </xs:sequence>
  </xs:complexType>

Can somebody help me pls? I have searched for 2 hours and found nothing.

Edit2: Top-left corner the http-Request dump Right corner the SoapUI generated request which works http://www.directupload.net/file/d/4013/5iwbvowk_png.htm

2

There are 2 answers

8
Mithun On BEST ANSWER

Have you tried simply adding property using below flavor of addProperty

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("username", username);
request.addProperty("deviceID", deviceID);

Also, you can make sure that you have a valid value and you are not hitting any NPE while accessing userName.getText().toString()

6
Lee On

You should remember to declare your property as new after u add the first one.

pi = new PropertyInfo();

   PropertyInfo pi = new PropertyInfo();
   pi.setNamespace(NAMESPACE);
   pi.setName("username");
   pi.setValue(userName.getText().toString());
   pi.setType(PropertyInfo.STRING_CLASS);
   request.addProperty(pi); 

   // here
   pi = new PropertyInfo();  
   pi.setNamespace(NAMESPACE);
   pi.setName("deviceID");
   pi.setValue(android.provider.Settings.Secure.getString(
   getContentResolver(), 
   android.provider.Settings.Secure.ANDROID_ID));
   pi.setType(PropertyInfo.STRING_CLASS);
   request.addProperty(pi);

and one more thing, remember to call your androidHttpTransport

androidHttpTransport.call(SOAP_ACTION,envelope,null);
SoapPrimitive respond = (SoapPrimitive) envelope.getResponse();

UPDATED: Is your request pass in exact parameter you want to? When debugging, you can see the webservice name along with value name and parameter you pass in.

ConnectionString{username=manager; password=password123; }