title: Getting a nullreference when passing a complex object from KSOAP2 to WCF
body: <p>So guys I know that there exist a lot of similar question in here, but none of them have been able to resolve my issue. </p>
  
  <p>I’m trying to send a custom Object User from an Android device to a WCF service, but no matter what I do the webservice receive a null.</p>
  
  <p>Here's the code for the object im trying to send:</p>
  
  <pre><code>public class User implements KvmSerializable {
  
  private int id; 
  private String userName;
  private String mac;
  private int proppertyCount = 3;
  
  
  public User(int _id, String _userName, String _mac)
  {
      this.id =_id;
      this.userName = _userName;
      this.mac = _mac;
  }
  
  public User()
  {
  
  }
  
  
  public int getId() {
      return id;
  }
  public void setId(int id) {
      this.id = id;
  }
  public String getUserName() {
      return userName;
  }
  public void setUserName(String userName) {
      this.userName = userName;
  }
  public String getMac() {
      return mac;
  }
  public void setMac(String mac) {
      this.mac = mac;
  }
  
  @Override
  public Object getProperty(int arg0) {
  
      switch(arg0)
      {
          case 0: return id;
  
          case 1: return userName;
  
          case 2: return mac;
  
      }
      return null;
  }
  
  @Override
  public int getPropertyCount() {
  
      return proppertyCount;
  }
  
  @Override
  public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
  
      switch(index)
      {
      case 0:
          info.type = PropertyInfo.INTEGER_CLASS;
          info.name = "CategoryId";
          break;
      case 1:
          info.type = PropertyInfo.STRING_CLASS;
          info.name = "Name";
          break;
      case 2:
          info.type = PropertyInfo.STRING_CLASS;
          info.name = "Description";
          break;
      default:break;
      }
  
  }
  
  @Override
  public void setProperty(int index, Object value) {
      switch(index)
      {
      case 0:
          id = Integer.parseInt(value.toString());
          break;
      case 1:
          userName = value.toString();
          break;
      case 2:
          mac = value.toString();
          break;
      default:
          break;
      }
  
  }
  </code></pre>
  
  <p>My method to pass the object through ksoap2:</p>
  
  <pre><code>        private static String SOAP_ACTION = "http://nordahl.org/IWcfFoodAndAllergi/";
      private static  String METHOD_NAME;
      private static final String NAMESPACE = "http://nordahl.org/";
      private static final String URL = "http://192.168.0.18/WcfFoodAndAllergi.svc";
  
      public void InsertUser(User _user)
      {
  
          METHOD_NAME = "InsertUser"; 
          SOAP_ACTION = SOAP_ACTION + METHOD_NAME;
          SoapObject result;
          int retInt = -1;
  
              SoapObject req = new SoapObject(NAMESPACE, METHOD_NAME);
  
  
  
              PropertyInfo p = new PropertyInfo();
  
              p.setName("User");
              p.setNamespace(NAMESPACE);
              p.setValue(_user);
              p.setType(_user.getClass());
              p.setType(_user.getClass());
  
              req.addProperty(p);
  
              SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
              envelope.dotNet = true;
              envelope.implicitTypes = true;
              envelope.setAddAdornments(false);
              envelope.setOutputSoapObject(req);    
  
              envelope.addMapping(NAMESPACE, "User", new User().getClass());
  
              HttpTransportSE ht = new HttpTransportSE(URL); 
  
              try{
                      ht.debug= true;
                      ht.call(SOAP_ACTION, envelope);
                      result = (SoapObject)envelope.getResponse();
              }
              catch (Exception e)
              {
                  e.printStackTrace();
  
  
              }
      }
  </code></pre>
  
  <p>And finally my wsdl file:</p>
  
  <pre><code>    &lt;wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://nordahl.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" name="WcfFoodAndAllergi" targetNamespace="http://nordahl.org/"&gt;
  &lt;wsdl:types&gt;
  &lt;xsd:schema targetNamespace="http://nordahl.org/Imports"&gt;
  &lt;xsd:import schemaLocation="http://192.168.0.18/WcfFoodAndAllergi.svc?xsd=xsd0" namespace="http://nordahl.org/"/&gt;
  &lt;xsd:import schemaLocation="http://192.168.0.18/WcfFoodAndAllergi.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/&gt;
  &lt;xsd:import schemaLocation="http://192.168.0.18/WcfFoodAndAllergi.svc?xsd=xsd2" namespace="http://schemas.datacontract.org/2004/07/ModelLayer"/&gt;
  &lt;/xsd:schema&gt;
  &lt;/wsdl:types&gt;
  &lt;wsdl:message name="IWcfFoodAndAllergi_InsertUser_InputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:InsertUser"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="IWcfFoodAndAllergi_InsertUser_OutputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:InsertUserResponse"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="IWcfFoodAndAllergi_GetUser_InputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:GetUser"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="IWcfFoodAndAllergi_GetUser_OutputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:GetUserResponse"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="IWcfFoodAndAllergi_InsertRecipe_InputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:InsertRecipe"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="IWcfFoodAndAllergi_InsertRecipe_OutputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:InsertRecipeResponse"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="IWcfFoodAndAllergi_GetRecipeByAllergi_InputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:GetRecipeByAllergi"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="IWcfFoodAndAllergi_GetRecipeByAllergi_OutputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:GetRecipeByAllergiResponse"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="IWcfFoodAndAllergi_GetRecipeByType_InputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:GetRecipeByType"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="IWcfFoodAndAllergi_GetRecipeByType_OutputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:GetRecipeByTypeResponse"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="IWcfFoodAndAllergi_GetRecipeByName_InputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:GetRecipeByName"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="IWcfFoodAndAllergi_GetRecipeByName_OutputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:GetRecipeByNameResponse"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:portType name="IWcfFoodAndAllergi"&gt;
  &lt;wsdl:operation name="InsertUser"&gt;
  &lt;wsdl:input wsaw:Action="http://nordahl.org/IWcfFoodAndAllergi/InsertUser" message="tns:IWcfFoodAndAllergi_InsertUser_InputMessage"/&gt;
  &lt;wsdl:output wsaw:Action="http://nordahl.org/IWcfFoodAndAllergi/InsertUserResponse" message="tns:IWcfFoodAndAllergi_InsertUser_OutputMessage"/&gt;
  &lt;/wsdl:operation&gt;
  &lt;wsdl:operation name="GetUser"&gt;
  &lt;wsdl:input wsaw:Action="http://nordahl.org/IWcfFoodAndAllergi/GetUser" message="tns:IWcfFoodAndAllergi_GetUser_InputMessage"/&gt;
  &lt;wsdl:output wsaw:Action="http://nordahl.org/IWcfFoodAndAllergi/GetUserResponse" message="tns:IWcfFoodAndAllergi_GetUser_OutputMessage"/&gt;
  &lt;/wsdl:operation&gt;
  &lt;wsdl:operation name="InsertRecipe"&gt;
  &lt;wsdl:input wsaw:Action="http://nordahl.org/IWcfFoodAndAllergi/InsertRecipe" message="tns:IWcfFoodAndAllergi_InsertRecipe_InputMessage"/&gt;
  &lt;wsdl:output wsaw:Action="http://nordahl.org/IWcfFoodAndAllergi/InsertRecipeResponse" message="tns:IWcfFoodAndAllergi_InsertRecipe_OutputMessage"/&gt;
  &lt;/wsdl:operation&gt;
  &lt;wsdl:operation name="GetRecipeByAllergi"&gt;
  &lt;wsdl:input wsaw:Action="http://nordahl.org/IWcfFoodAndAllergi/GetRecipeByAllergi" message="tns:IWcfFoodAndAllergi_GetRecipeByAllergi_InputMessage"/&gt;
  &lt;wsdl:output wsaw:Action="http://nordahl.org/IWcfFoodAndAllergi/GetRecipeByAllergiResponse" message="tns:IWcfFoodAndAllergi_GetRecipeByAllergi_OutputMessage"/&gt;
  &lt;/wsdl:operation&gt;
  &lt;wsdl:operation name="GetRecipeByType"&gt;
  &lt;wsdl:input wsaw:Action="http://nordahl.org/IWcfFoodAndAllergi/GetRecipeByType" message="tns:IWcfFoodAndAllergi_GetRecipeByType_InputMessage"/&gt;
  &lt;wsdl:output wsaw:Action="http://nordahl.org/IWcfFoodAndAllergi/GetRecipeByTypeResponse" message="tns:IWcfFoodAndAllergi_GetRecipeByType_OutputMessage"/&gt;
  &lt;/wsdl:operation&gt;
  &lt;wsdl:operation name="GetRecipeByName"&gt;
  &lt;wsdl:input wsaw:Action="http://nordahl.org/IWcfFoodAndAllergi/GetRecipeByName" message="tns:IWcfFoodAndAllergi_GetRecipeByName_InputMessage"/&gt;
  &lt;wsdl:output wsaw:Action="http://nordahl.org/IWcfFoodAndAllergi/GetRecipeByNameResponse" message="tns:IWcfFoodAndAllergi_GetRecipeByName_OutputMessage"/&gt;
  &lt;/wsdl:operation&gt;
  &lt;/wsdl:portType&gt;
  &lt;wsdl:binding name="BasicHttpBinding_IWcfFoodAndAllergi" type="tns:IWcfFoodAndAllergi"&gt;
  &lt;soap:binding transport="http://schemas.xmlsoap.org/soap/http"/&gt;
  &lt;wsdl:operation name="InsertUser"&gt;
  &lt;soap:operation soapAction="http://nordahl.org/IWcfFoodAndAllergi/InsertUser" style="document"/&gt;
  &lt;wsdl:input&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:input&gt;
  &lt;wsdl:output&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:output&gt;
  &lt;/wsdl:operation&gt;
  &lt;wsdl:operation name="GetUser"&gt;
  &lt;soap:operation soapAction="http://nordahl.org/IWcfFoodAndAllergi/GetUser" style="document"/&gt;
  &lt;wsdl:input&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:input&gt;
  &lt;wsdl:output&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:output&gt;
  &lt;/wsdl:operation&gt;
  &lt;wsdl:operation name="InsertRecipe"&gt;
  &lt;soap:operation soapAction="http://nordahl.org/IWcfFoodAndAllergi/InsertRecipe" style="document"/&gt;
  &lt;wsdl:input&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:input&gt;
  &lt;wsdl:output&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:output&gt;
  &lt;/wsdl:operation&gt;
  &lt;wsdl:operation name="GetRecipeByAllergi"&gt;
  &lt;soap:operation soapAction="http://nordahl.org/IWcfFoodAndAllergi/GetRecipeByAllergi" style="document"/&gt;
  &lt;wsdl:input&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:input&gt;
  &lt;wsdl:output&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:output&gt;
  &lt;/wsdl:operation&gt;
  &lt;wsdl:operation name="GetRecipeByType"&gt;
  &lt;soap:operation soapAction="http://nordahl.org/IWcfFoodAndAllergi/GetRecipeByType" style="document"/&gt;
  &lt;wsdl:input&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:input&gt;
  &lt;wsdl:output&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:output&gt;
  &lt;/wsdl:operation&gt;
  &lt;wsdl:operation name="GetRecipeByName"&gt;
  &lt;soap:operation soapAction="http://nordahl.org/IWcfFoodAndAllergi/GetRecipeByName" style="document"/&gt;
  &lt;wsdl:input&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:input&gt;
  &lt;wsdl:output&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:output&gt;
  &lt;/wsdl:operation&gt;
  &lt;/wsdl:binding&gt;
  &lt;wsdl:service name="WcfFoodAndAllergi"&gt;
  &lt;wsdl:port name="BasicHttpBinding_IWcfFoodAndAllergi" binding="tns:BasicHttpBinding_IWcfFoodAndAllergi"&gt;
  &lt;soap:address location="http://192.168.0.18/WcfFoodAndAllergi.svc"/&gt;
  &lt;/wsdl:port&gt;
  &lt;/wsdl:service&gt;
  &lt;/wsdl:definitions&gt;
  </code></pre>
  
  <p>I know that its a wall of text, Im just completely lost at this point.</p>
  
  <p>Any pointers would be greatly appreciated</p>