如何调用SOAP的Web服务在android系统? [英] how to call soap web-service in android?

查看:149
本文介绍了如何调用SOAP的Web服务在android系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试调用Android中肥皂的WebServices以下行后

  androidHttpTransport.call(SOAP_ACTION,信封);

程序捕捉到程序直接跳转应调用结果= envelope.getResponse(); ,但我还没有恢复的响应什么是可能的解决方案任何一个帮助在这?感谢andvance ..

  {尝试
        的System.out.println(令牌=== sssTTTTTT);        SoapObject要求=新SoapObject空间(namespace,METHOD_NAME);        request.addProperty(encAppName,dsakjsfj);
        request.addProperty(sessionInfo,sadsadsdf);        SoapSerializationEnvelope信封=新SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = TRUE;
        envelope.setOutputSoapObject(请求);
        HttpTransportSE androidHttpTransport =新HttpTransportSE(URL);
        androidHttpTransport.call(SOAP_ACTION,信封);          结果= envelope.getResponse();
           Toast.makeText(getBaseContext(),结果+\\ N+ result.toString(),Toast.LENGTH_SHORT).show();
           的System.out.println(回应===+ result.toString());    }赶上(例外五){
        // txtprint.setText(e.getMessage());
    }


解决方案

请该试试这个我工作code。只是做你必要的修改。
如果你说这是怎么回事直接向catch块,这意味着它抛出一些例外。请试试,看看那是什么。 使用的AsyncTask后台线程(请求响应)

  //这里把你的网址..
    私人最终字符串URL =htt​​p://192.192.192.192/DemoService/Demo.asmx;
        私人最终字符串SOAP_ACTION =htt​​p://tempuri.org/AndroidTestRequest;
        私人最终字符串METHOD_NAME =AndroidTestRequest;
SoapObject要求=新SoapObject空间(namespace,METHOD_NAME);
        request.addProperty(用户,abcd@gmail.com);
        request.addProperty(密码,测试@ 123);
        SoapSerializationEnvelope信封=新SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.headerOut =新的元素[1];
        envelope.headerOut [0] = buildAuthHeader();
        envelope.dotNet = TRUE;
        envelope.setOutputSoapObject(请求);//你可以,如果你想在这里添加您的属性。
        / *
         *的PropertyInfo cityProp =新的PropertyInfo();
         *
         * cityProp.setType(为String.class); request.addProperty(cityProp);
         * /        Log.e(的请求值,request.toString());
        Log.e(envolope的值,envelope.toString());        HttpTransportSE androidHttpTransport =新HttpTransportSE(URL);        尝试{            androidHttpTransport.call(SOAP_ACTION,信封);                    Log.i(myAppEnvelope,envelope.toString());            SoapObject响应=(SoapObject)envelope.getResponse();            SoapObject对象=(SoapObject)response.getProperty(值);
        }赶上(例外五){
            e.printStackTrace();
        }

when i try to call soap webservices in android after below line

androidHttpTransport.call(SOAP_ACTION, envelope);

program direct jump in to catch program should be call result = envelope.getResponse(); but i haven't revived a response what is the possible solution any one help in this ??? thanks in andvance ..

    try {
        System.out.println("Token ===sssTTTTTT " );

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        request.addProperty("encAppName", "dsakjsfj");
        request.addProperty("sessionInfo", "sadsadsdf");

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.call(SOAP_ACTION, envelope);

          result = envelope.getResponse();
           Toast.makeText(getBaseContext(), "  Result " + "\n" + result.toString(), Toast.LENGTH_SHORT).show();
           System.out.println("response === " + result.toString());

    } catch (Exception e) {
        // txtprint.setText(e.getMessage());
    }

解决方案

Please try this this my working code. just do your necessary changes. And if you are saying it is going direct to catch block, it means it is throwing some exception. please try to see what is that. use asynctask for background thread(request response)

// put here your url's..
    private final String URL = "http://192.192.192.192/DemoService/Demo.asmx";
        private final String SOAP_ACTION = "http://tempuri.org/AndroidTestRequest";
        private final String METHOD_NAME = "AndroidTestRequest";


SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("User", "abcd@gmail.com");
        request.addProperty("Password", "test@123");
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.headerOut = new Element[1];
        envelope.headerOut[0] = buildAuthHeader();
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);

// you can add your properties here if you want to.
        /*
         * PropertyInfo cityProp = new PropertyInfo();
         * 
         * cityProp.setType(String.class); request.addProperty(cityProp);
         */

        Log.e("value of request", request.toString());
        Log.e("Value of envolope ", envelope.toString());

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        try {

            androidHttpTransport.call(SOAP_ACTION, envelope);

                    Log.i("myAppEnvelope", envelope.toString());

            SoapObject response = (SoapObject) envelope.getResponse();

            SoapObject object = (SoapObject) response.getProperty("value");


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

这篇关于如何调用SOAP的Web服务在android系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆