2012-09-22 38 views
0

以下方法返回錯誤socket is not connected。我試圖通過android模擬器中的localhost連接到我的電腦。Android中的套接字未連接錯誤

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(); 

    } 
} 
} 
+0

誤差數端口本地主機。新錯誤:例外org.ksoap2.serialization.soapprimitive – user1689493

回答

0

您的防火牆或設置訪問時關閉與「1727」