views:

48

answers:

1
    public class a extends Activity {

    public static final String SOAP_ACTION = "http://vladozver.org/GetAllCategories";
    public static final String METHOD_NAME = "GetAllCategories";
    public static final String NAMESPACE = "http://vladozver.org/";
    public static final String URL = "http://192.168.1.3/Services/CategoryServices.asmx";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView tv = (TextView)findViewById(R.id.TextView01);

        SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);

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

        envelope.addMapping(NAMESPACE, "Category",new Category().getClass());

        AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);

        try
        {
            androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapObject response = (SoapObject)envelope.getResponse();

            Object o = (Object)envelope.getResponse();
            SoapObject obj = (SoapObject)o;             
// DOESNT WORK ... 
            Category[] res = new Category[obj.getPropertyCount()];
            for (int i = 0; i < res.length; i++) {
                res[i] = (Category)obj.getProperty(i);
            }
// DOESNT WORK ...
                Vector<Category> cat = (Vector<Category>)response.getProperty(0);




        }
        catch(SoapFault sf)
        {

            sf.printStackTrace();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}



public class Category implements KvmSerializable
{
    public int CategoryId;
    public String Name;
    public String Description;
    @Override
    public Object getProperty(int arg0) {

        switch(arg0)
        {
        case 0:
            return CategoryId;
        case 1:
            return Name;
        case 2:
            return Description;
        }

        return null;
    }
    @Override
    public int getPropertyCount() {
        // TODO Auto-generated method stub
        return 3;
    }
    @Override
    public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
        // TODO Auto-generated method stub
        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) {
        // TODO Auto-generated method stub
        switch(index)
        {
        case 0:
            CategoryId = Integer.parseInt(value.toString());
            break;
        case 1:
            Name = value.toString();
            break;
        case 2:
            Description = value.toString();
            break;
        default:
            break;
        }
    }
}
A: 

Are you using KSoap2 for android? I hate to tell you this, but soap is some really tricky stuff. you could be experiencing any number of issues. I would need more information about your errors in order to tell you what's wrong. When i did this i had to implement my own ServiceConnection/HttpTransport. My response came in the form of xml which i had to parse into list items.

mtmurdock