Ver Mensaje Individual
  #1  
Viejo 06/10/11, 09:37:53
Avatar de n3ok
n3ok n3ok no está en línea
Usuario novato en la web
Mensajes: 9
 
Fecha de registro: oct 2011
Localización: Tarragona
Mensajes: 9
Tu operador: Movistar
Mencionado: 0 comentarios
Tagged: 0 hilos
Exclamation Consumir recurso web des de ANDROID

Hola, muy buenas!

Soy nuevo en esto de las aplicaciones Android, y estoy haciendo una que requiere consultar a un servicio web que yo he creado.

El servicio web funciona porqué lo he probado solo y va bién.

El servicio web es este:

Código:
 [WebMethod]
        public Boolean ComprovarUsuari(String correu, string pass) {

            string sel = string.Concat("SELECT nom FROM usuaris WHERE correu='", correu, "'", " AND pass='", pass, "'");

            da = new SqlDataAdapter(sel, "Data Source=NombreMiOrdenador;Initial Catalog=baseDatos;Integrated Security=SSPI;");
            DataSet ds = new DataSet();
            try
            {
                da.Fill(ds);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (ds.Tables[0].Rows.Count < 1)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

Posiblemente no este optimizada ya que es la primera que hago, si alguien quiere aportar ideas se lo agradezco.
El codigo que he encontrado en algun tutorial de android es el siguiente:

Código:
        private static final String namespace = "http://localhost/WebService";
	private static final String url = "http://localhost:52711/Service1.asmx"; 
	private static final String Metodo = "ComprovarUsuari"; 
	private static final String accionSoap = "http://localhost:52711/Service1.asmx?op=ComprovarUsuari"; 




	public void onClick(View v) {
		Button button = (Button) v;
		if (button.getId() == R.id.regButton) 
		{
			Intent intent = new Intent(this, Reg.class);
			startActivity(intent);
		}
		else if (button.getId() == R.id.loginButton) {
			//Codi a executar per comprovar usuari
			SoapObject Solicitud = new SoapObject(namespace, Metodo);
			
			//paràmetres
			PropertyInfo correu = new PropertyInfo (); 
			PropertyInfo pass = new PropertyInfo ();
			
			//Valors dels paràmetres
			correu.setName ("correu"); 			
			correu.setValue (R.id.userText); 
			pass.setName ("pass"); 	
			pass.setValue (R.id.passText);
			
			Solicitud.addProperty (correu); 
			Solicitud.addProperty (pass);
			
			SoapSerializationEnvelope Envoltorio = new SoapSerializationEnvelope (SoapEnvelope.VER12);
			//Si el servei web es .NET
			Envoltorio.dotNet = true;
			
			Envoltorio.setOutputSoapObject (Solicitud);
			
			HttpTransportSE TransporteHttp = new HttpTransportSE(url);
			
			
			try {
				TransporteHttp.call (accionSoap, Envoltorio);  En esta línea me falla, y me salta a la IOException.
			} catch (IOException e) {
				e.printStackTrace();
			} catch (XmlPullParserException e) {
				e.printStackTrace();
			}
			
			String resposta = "prova";
			try {
				resposta = (String) Envoltorio.getResponse();
			} catch (SoapFault e) {
				e.printStackTrace();
			}
			
			Toast.makeText(this, resposta, Toast.LENGTH_SHORT).show();
		}
A ver si alguien me ilumina el camino!

Gracias de antemano
Responder Con Cita