Android中没有连接套接字错误

时间:2012-09-22 20:57:52

标签: java android sockets

以下方法返回错误socket is not connected。我试图通过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 个答案:

答案 0 :(得分:0)

关闭防火墙或设置“1727”

的访问权限