Android中没有连接套接字错误

时间:2022-09-14 20:51:10

The following method returns an error socket is not connected. I am trying to connect to my pc via localhost in android emulator.

以下方法返回错误套接字未连接。我试图通过android模拟器中的localhost连接到我的电脑。

public class Service {
private static final String SOAP_ACTION = "http://tempuri.org/buscaProdutos";
private static final String METHOD_NAME = "buscaProdutos";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL =  "http://10.0.2.2:1727/Service1.asmx"; //localhost


public String GetRespostas(int valor) { //metod return string

    HttpParams httpParameters = new BasicHttpParams();

    HttpConnectionParams.setConnectionTimeout(httpParameters, 19000);

    int timeoutSocket = 9000;
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); //conect 
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);


    try { 

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.call(SOAP_ACTION, envelope);
        SoapObject result=(SoapObject)envelope.getResponse();

        return  result.getProperty(valor).toString();

    } catch (Exception e) {// e = "socket is not connected

        Log.d("erro", e.getMessage());
        return e.getMessage();

    }
}
}

1 个解决方案

#1


0  

Turn off your firewall Or set access to "1727"

关闭防火墙或设置“1727”的访问权限

#1


0  

Turn off your firewall Or set access to "1727"

关闭防火墙或设置“1727”的访问权限