使用KSOAP的Android中的Web服务

时间:2012-06-11 07:38:01

标签: android web-services ksoap2

我想使用KSOAP2创建Web服务的连接,我已经完成了代码及其获取错误,所以请建议我在哪里做错了。另外我需要一些关于web服务的帮助,什么是命名空间,我们调用的方法,soap_action,url以及我们在web-services中使用的一些方法。我搜索了很多但没有找到任何关于web服务的完整描述

 public class Web_ServicesActivity extends Activity {
    private static String SOAP_ACTION = "http://service.fun2shoot.com/getLive";

    private static String NAMESPACE = "http://service.fun2shoot.com/";
    private static String METHOD_NAME = "getLive";

    private static String URL = "http://119.82.75.91:8084/Fun2Shoot-WebService/Fun2ShootAndroid?wsdl";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        System.out
                .println("After mail******************************************");
        // Initialize soap request + add parameters
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        System.out.println("****************After Request call");
        // Use this to add parameters
        // request.addProperty("Parameter","Value");

        // Declare the version of the SOAP request
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.setOutputSoapObject(request);

        // Needed to make the internet call
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        try {
            // this is the actual part that will call the webservice
            androidHttpTransport.call(SOAP_ACTION, envelope);
        } catch (Exception e) {
            e.printStackTrace();
        }

        // Get the SoapResult from the envelope body.
        SoapObject result = (SoapObject) envelope.bodyIn;

        if (result != null) {
            TextView t = (TextView) this.findViewById(R.id.tv);
            System.out
                    .println("***************************************Inside null condition");
            // Get the first property and change the label text
            t.setText("SOAP response:\n\n" + result.getProperty(0).toString());
        }

    }
}

1 个答案:

答案 0 :(得分:0)

您可以在项目的 Build Path 中添加库,以及在java中创建Web服务的参考,请使用此教程How to create java based web service

如果您对此或任何其他疑问有任何疑问,可以写信给我。