title: How do I tell ksoap to prefix custom objects with the right namespace?
body: <p>I am trying to send a custom object to my WCF service via ksoap on Android. I have the following code below.</p>
  
  <pre><code>String METHOD_NAME = "MyMethod";
  String INTERFACE = "IMyInterface";
  String NAMESPACE = "http://tempuri.org/";
  String SOAP_ACTION = NAMESPACE + INTERFACE + "/" + METHOD_NAME; 
  
  request = new SoapObject(NAMESPACE, METHOD_NAME);
  request.addProperty("APIKey", API_KEY);
  request.addProperty("AuthToken",  AuthToken);
  request.addProperty("UserID", 1);
  
  SoapObject test1 = new SoapObject(DATA_NAMESPACE, "MyCustomObject");
  test1.addProperty("ID", 1);
  test1.addProperty("UserID", 1);
  test1.addProperty("Name", "Test");
  request.addSoapObject(test1);
  
  
  SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
  envelope.dotNet = true;
  envelope.addMapping(DATA_NAMESPACE, "MyCustomObject", new MyCustomObject().getClass());
  envelope.setOutputSoapObject(request);
  
  
  HttpTransportSE httpTransport = new HttpTransportSE(URL);
  httpTransport.debug = true;
  
  
  int id = 0;
  try {
      httpTransport.call(SOAP_ACTION, envelope);
      SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
      id = Integer.parseInt(result.toString());
  } catch (Exception e) {
      String requestDump = httpTransport.requestDump;
      String responseDump = httpTransport.responseDump;
      throw e;
  }
  </code></pre>
  
  <p>I know that the call is actually making it to the web server. Values from APIKey, AuthToken, &amp; UserID all make it there successfully. However, in the <code>MyCustomObject</code> none of the values make it there. The object does but it has been stripped of the values. </p>
  
  <p>I took a look at the <code>requestDump</code> and I found the following. </p>
  
  <pre><code>&lt;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/"&gt;
  &lt;v:Header /&gt;
  &lt;v:Body&gt;
  &lt;MyMethod xmlns="http://tempuri.org/" id="o0" c:root="1"&gt;
    &lt;APIKey i:type="d:string"&gt;MyAPIKey&lt;/APIKey&gt;
    &lt;AuthToken i:type="d:string"&gt;MyAuthToken&lt;/AuthToken&gt;
    &lt;UserID i:type="d:int"&gt;1&lt;/UserID&gt;
    &lt;MyCustomObject i:type="n0:MyCustomObject" xmlns:n0="http://schemas.datacontract.org/2004/07/MyDataNamespace.Data"&gt;
      &lt;ID i:type="d:int"&gt;1&lt;/ID&gt;
      &lt;UserID i:type="d:int"&gt;1&lt;/UserID&gt;
      &lt;Name i:type="d:string"&gt;Test&lt;/Name&gt;
    &lt;/MyCustomObject&gt;
  &lt;/MyMethod&gt;
  &lt;/v:Body&gt;
  &lt;/v:Envelope&gt;
  </code></pre>
  
  <p>I then constructed a quick little .net console client and performed the exact same action. However, I analyzed the requestDump from the .net client and got the following. </p>
  
  <pre><code>{&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    &lt;s:Header&gt;
      &lt;Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none"&gt;http://tempuri.org/IMyInterface/MyMethod&lt;/Action&gt;
    &lt;/s:Header&gt;
    &lt;s:Body&gt;
      &lt;MyMethod xmlns="http://tempuri.org/"&gt;
        &lt;APIKey&gt;MyAPIKey&lt;/APIKey&gt;
        &lt;AuthToken&gt;MyAuthToken&lt;/AuthToken&gt;
        &lt;UserID&gt;1&lt;/UserID&gt;
        &lt;MyCustomObject xmlns:d4p1="http://schemas.datacontract.org/2004/07/MyDataNamespace.Data" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
          &lt;d4p1:Name&gt;Test&lt;/d4p1:Name&gt;
          &lt;d4p1:ID&gt;1&lt;/d4p1:ID&gt;
          &lt;d4p1:UserID&gt;1&lt;/d4p1:UserID&gt;
        &lt;/MyCustomObject&gt;
      &lt;/MyMethod&gt;
    &lt;/s:Body&gt;
  &lt;/s:Envelope&gt;}
  </code></pre>
  
  <p>Now given those pieces and the comparison between XML the only thing I notice is that the MyCustomObject's properties are prefixed with the namespace prefix d4p1. On the java client the properties are not prefixed with n0 like they should be. This would tell me that this is the disconnect and why the object is getting its properties stripped. Now the question is how do I tell ksoap to add that namespace prefix to the document??</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Also, here is my class that implements KVMSerializable.</p>
  
  <pre><code>public class MyCustomObject implements KvmSerializable {
      public int ID;
      public int UserID;
      public String Name;
  
      public MyCustomObject() { }
  
      public String getName() { return Name; }
      public int getID() { return ID; }
      public int getUserID() { return UserID; }
      public void setName(String name) { Name = name; }
      public void setID(int ID) { ID = ID; }
      public void setUserID(int userID) { UserID = userID; }
  
      public Object getProperty(int index) {
          switch (index) {
              case 0: return ID;
              case 1: return UserID;
              case 2: return Name;
          }
          return null;
      }
  
      public void setProperty(int index, Object value) {
          switch (index) {
              case 0: ID = Integer.parseInt(value.toString()); break;
              case 1: UserID = Integer.parseInt(value.toString()); break;
              case 2: Name = value.toString(); break;
          }
      }
  
      public int getPropertyCount() { return 3; }
  
      public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
          switch (index) {
              case 0: 
                  info.type = PropertyInfo.INTEGER_CLASS;
                  info.name = "ID";
                  break;
              case 1:
                  info.type = PropertyInfo.INTEGER_CLASS;
                  info.name = "UserID";
                  break;
              case 2:
                  info.type = PropertyInfo.STRING_CLASS;
                  info.name = "Name";
                  break;
          }
      }
  }
  </code></pre>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>So on my 2nd problem the issue was the ordering of the properties. Using SoapUI as suggested showed me the layout of the properties as expected by my server. I need to do this instead of what I had above.</p>
  
  <pre><code>test1.addProperty("Name", "Test");
  test1.addProperty("ID", 1);
  test1.addProperty("UserID", 1);
  </code></pre>