在3G网络中使用KSOAP2的问题:XmlPullParserException

时间:2011-11-11 12:01:24

标签: android soap ksoap2 socketexception xmlpullparser

我使用KSOAP2进行网络服务调用。这是我的代码:

SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        soapEnvelope.dotNet = true;
        soapEnvelope.setOutputSoapObject(request);

        HttpTransportSE aht = new HttpTransportSE(URL);

        try {

            aht.call(SOAP_ACTION, soapEnvelope);

            SoapObject result;
            try{
                result = (SoapObject) soapEnvelope.getResponse();
            }catch (ClassCastException e) {
                result = (SoapObject)soapEnvelope.bodyIn; 
            }

            // parse the SOAP object


        } catch (Exception e) {
            e.printStackTrace(); // here it is throwing  XmlPullParserException in a #G network
        }

当我们在设备和网络中测试时,代码运行正常。我在不同的位置和不同的Wifi和3g网络测试了它。它工作正常。当我的客户使用他的设备和Wifi网络测试它时,它也可以正常工作。但当他尝试使用3G网络时,它正在提供XmlPullParserException预期:START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelopre(位置:START_TAG @ 1:6)在java.io.InputStreamReader )中。这个特定网络SocketException背后的问题可能是什么。

这里我想提一下,在调用SOAP之前,我已经使用以下代码检查了网络状态:

if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
                .getState() == NetworkInfo.State.CONNECTED
                || connectivityManager.getNetworkInfo(
                        ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) {
            // we are connected to a network
            //go for SOAP call
        }

0 个答案:

没有答案