3G 网络中 KSOAP2 的问题:XmlPullParserException
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论