在Android中,如果不使用KSOAP2,如何调用web服务?

在Android中,如果不使用KSOAP2,如何调用web服务?,android,Android,我可以从android用KSOAP2调用Web服务,现在我想知道是否可以不用KSOAP调用它。如果有人知道答案,请帮助我。如果Web服务可以使用rest api,我会使用。我有一些博客文章展示了使用这个库的简单示例 这是SOAP web服务的简单代码 public class SOAPActivity extends Activity { private final String NAMESPACE = "http://www.webserviceX.NET/"; pr

我可以从android用KSOAP2调用Web服务,现在我想知道是否可以不用KSOAP调用它。如果有人知道答案,请帮助我。

如果Web服务可以使用rest api,我会使用。我有一些博客文章展示了使用这个库的简单示例

这是SOAP web服务的简单代码

public class SOAPActivity extends Activity {
     private final String NAMESPACE = "http://www.webserviceX.NET/";
        private final String URL = "http://www.webservicex.net/ConvertWeight.asmx";
        private final String SOAP_ACTION = "http://www.webserviceX.NET/ConvertWeight";
        private final String METHOD_NAME = "ConvertWeight";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        SoapObject soapObject=new SoapObject(NAMESPACE, METHOD_NAME);

        String weight = "700";
        String fromUnit = "Kilograms";
        String toUnit = "Grams";

        PropertyInfo weightProp =new PropertyInfo();
        weightProp.setName("Weight");
        weightProp.setValue(weight);
        weightProp.setType(double.class);
        soapObject.addProperty(weightProp);

        PropertyInfo fromProp =new PropertyInfo();
        fromProp.setName("FromUnit");
        fromProp.setValue(fromUnit);
        fromProp.setType(String.class);
        soapObject.addProperty(fromProp);

        PropertyInfo toProp =new PropertyInfo();
        toProp.setName("ToUnit");
        toProp.setValue(toUnit);
        toProp.setType(String.class);
        soapObject.addProperty(toProp);

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

        try {
            androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
            Log.i("myApp", response.toString());

            TextView tv = new TextView(this);
            tv.setText(weight+" "+fromUnit+" equal "+response.toString()+ " "+toUnit);
            setContentView(tv);

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

    }