Я пытаюсь вызвать веб-службу SOAP, но получаю исключение с сообщением «W / System.err: java.net.SocketTimeoutException». Я протестировал веб-службу в SOAPUI, и все в порядке.Конкретный WebService не отправляет никаких параметров, он только принимает ответ с некоторой информацией от сервера.Вот мой код ...
package com.example.soaptest6;
import android.os.AsyncTask;
import android.os.Build;
import android.os.StrictMode;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public class MainActivity extends AppCompatActivity {
Button btn;
ListView lView;
String resp="";
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button)findViewById(R.id.btn);
lView = (ListView)findViewById(R.id.lView);
textView = (TextView)findViewById(R.id.textView);
}
public void getWs(View v){
MyTask mt = new MyTask();
mt.execute();
}
class MyTask extends AsyncTask{
@Override
protected Object doInBackground(Object[] objects) {
loadData();
return null;
}
@Override
protected void onPostExecute(Object o) {
super.onPostExecute(o);
parseXML();
}
}
public void loadData() {
String wsdl_url = "http:............";
String soap_action = "urn:..........#........";
String name_space = "urn:........";
String method_name = ".........";
//Initialize soap request + add parameters
SoapObject soapObject = new SoapObject(name_space, method_name);
//Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//put all required data into a soap envelope
envelope.setOutputSoapObject(soapObject);
//Needed to make the internet call
HttpTransportSE htse = new HttpTransportSE(wsdl_url);
try {
//this is the actual part that will call the webservice
htse.call(soap_action, envelope);
// Get the SoapResult from the envelope body.
SoapObject obj = (SoapObject) envelope.bodyIn;
resp = obj.getProperty(0).toString();
System.out.println(resp);
} catch (Exception e) {
e.printStackTrace();
}
}
А вот ошибка
W/System.err: java.net.SocketTimeoutException
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:130)
at com.example.soaptest6.MainActivity.loadData(MainActivity.java:98)
W/System.err: at com.example.soaptest6.MainActivity$MyTask.doInBackground(MainActivity.java:62)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
W/System.err: org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: no element found
at org.apache.harmony.xml.ExpatParser.finish(ExpatParser.java:549)
at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:479)
W/System.err: at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:316)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:279)
W/System.err: at javax.xml.parsers.SAXParser.parse(SAXParser.java:390)
W/System.err: at javax.xml.parsers.SAXParser.parse(SAXParser.java:187)
at com.example.soaptest6.MainActivity.parseXML(MainActivity.java:117)
at com.example.soaptest6.MainActivity$MyTask.onPostExecute(MainActivity.java:69)
at android.os.AsyncTask.finish(AsyncTask.java:695)
at android.os.AsyncTask.access$600(AsyncTask.java:180)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Как мне решить эту проблему?