3G 网络中 KSOAP2 的问题:XmlPullParserException

发布于 2024-12-15 03:16:39 字数 1585 浏览 0 评论 0原文

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

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 (position:START_TAG @ 网络特定SocketException背后可能存在什么问题。

1:6 in java.io.InputStreamReader)。这种类型的 提到在调用 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
        }

I have used KSOAP2 for a web-service call. Here is my code:

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
        }

The code is running fine when we are testing it in our device and network. I have tested it in different location and different Wifi and 3g network. It is working fine. When my client has tested it using his device and Wifi network, it works fine also. But when he tried the same using 3G network, it is giving XmlPullParserException(expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelopre (position:START_TAG @1:6 in java.io.InputStreamReader). What may be the problem behind this tye of network specific SocketException.

Here I like to mention that before calling the SOAP, I have checked the network status using the following code:

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
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文