Foros del Web » Programación para mayores de 30 ;) » .NET »

Consumir un WebMethod de tipo Lista Generica

Estas en el tema de Consumir un WebMethod de tipo Lista Generica en el foro de .NET en Foros del Web. Hola a todos. Pues resulta que tengo un webservice con un WebMethod tipo Lista Generica, mas o menos así: [WebMethod(Description = "Lista Habilitaba para Combos ...
  #1 (permalink)  
Antiguo 12/11/2008, 19:29
Avatar de DevCH  
Fecha de Ingreso: marzo-2003
Ubicación: Villahermosa, Tabasco, Mé
Mensajes: 60
Antigüedad: 21 años, 2 meses
Puntos: 0
Consumir un WebMethod de tipo Lista Generica

Hola a todos.

Pues resulta que tengo un webservice con un WebMethod tipo Lista Generica, mas o menos así:

[WebMethod(Description = "Lista Habilitaba para Combos 2")]
public List<lstCombo> get_lstCombo2(Int32 pTipo)
{
List<lstCombo> MyList = new List<lstCombo>();
SqlDataAdapter da;
DataSet dsTabla = new DataSet();
SqlCommand sc = new SqlCommand();

sc.Connection = sqlConn;
sc.CommandType = CommandType.StoredProcedure;
switch (pTipo)
{
case 1:
sc.CommandText = "llena_combo_get";
break;
}

OpenConnection();
da = new SqlDataAdapter(sc);
da.Fill(dsTabla);
CloseConnection();

if (dsTabla.Tables[0].Rows.Count > 0)
{
foreach (DataRow item in dsTabla.Tables[0].Rows)
{
lstCombo registro = new lstCombo();
registro.data = (Int32)item["data"];
registro.label = (string)item["label"];
MyList.Add(registro);
}
}
else
{
lstCombo registro = new lstCombo();
registro.data = 0;
registro.label = "Ninguno";
MyList.Add(registro);
}

return MyList;
}


Y desde un una Aplicación Windows hecha tambien con C#, no se como invocarla e intentado de esta forma:

ExalAr.WS.exalar ws = new ExalAr.WS.exalar();
Lista lst = ws.ws.get_lstCombo2(1)

me devuelve el siguiente error:

Error 1 Cannot implicitly convert type 'ExalAr.WS.lstCombo[]' to 'Lista' C:\Working.NET\ExalAr\ExalAr\Controlador.cs 116 25 ExAlAr

______________________
LISTA es una clase:

using System;
using System.Collections.Generic;
using System.Text;

public class Lista
{
public Lista() { }

Int32 _data = 0;
string _label = "";

public Int32 data
{
set { _data = value; }
get { return _data; }
}

public string label
{
set { _label = value; }
get { return _label; }
}


}
______________________________
listCombo tiene la misma estructura

_________________________________
que será que puede estar pasando, el WS lo he probado desde el web y si funciona bien, pero no se como recoibir los datos devueltos en un Form de C#

Les agradezco toda la ayuda que me puedan brindar...

Saludos
__________________
Carlos Hidalgo
[email protected]
Villahermosa, Tabasco, México.

"Locura es: Obtener siempre el mismo resultado, y seguir insistendo con lo mismo, esperando que algún día, algo nuevo suceda."

--Albert Einstein--

:si:
  #2 (permalink)  
Antiguo 12/11/2008, 19:33
Avatar de Peterpay
Colaborador
 
Fecha de Ingreso: septiembre-2007
Ubicación: San Francisco, United States
Mensajes: 3.858
Antigüedad: 16 años, 8 meses
Puntos: 87
Respuesta: Consumir un WebMethod de tipo Lista Generica

pues es un error de tipos ,

ExalAr.WS.exalar ws = new ExalAr.WS.exalar();
Lista lst = ws.ws.get_lstCombo2(1)

ws.ws.get_lstCombo2(1) retorna un List<lstcombo> y lo quieres pasar a uno de tipo Lista q no tiene pinta de ser mas q un simple objeto plano no una coleccion ni mucho menos.
__________________
Curso WF4
http://cursos.gurudotnet.com/ DF
Aprende HTML5
  #3 (permalink)  
Antiguo 12/11/2008, 22:29
Avatar de DevCH  
Fecha de Ingreso: marzo-2003
Ubicación: Villahermosa, Tabasco, Mé
Mensajes: 60
Antigüedad: 21 años, 2 meses
Puntos: 0
Respuesta: Consumir un WebMethod de tipo Lista Generica

Que tal Sr Peterpay, veo que usted sabe un poco de c#, eso me da gusto.

Lo intenté a como usted me indica<.

ExalAr.WS.exalar ws = new ExalAr.WS.exalar();
List<ExalAr.WS.lstCombo> lst = ws.get_lstCombo2(1);
y nada

me envia es error:

Cannot implicitly convert type 'ExalAr.WS.lstCombo[]' to 'System.Collections.Generic.List<ExalAr.WS.lstComb o>'


También intenté así:

ExalAr.WS.exalar ws = new ExalAr.WS.exalar();
List<Lista> lst = ws.get_lstCombo2(1);

y tampoco, no jala.

Me envía este error:

Cannot implicitly convert type 'ExalAr.WS.lstCombo[]' to 'System.Collections.Generic.List<Lista>'

Me podría iluminar un poco? porque para mi esto no es tan trivial.

qué estaré haciendo mal?
__________________
Carlos Hidalgo
[email protected]
Villahermosa, Tabasco, México.

"Locura es: Obtener siempre el mismo resultado, y seguir insistendo con lo mismo, esperando que algún día, algo nuevo suceda."

--Albert Einstein--

:si:
  #4 (permalink)  
Antiguo 13/11/2008, 08:44
Avatar de Peterpay
Colaborador
 
Fecha de Ingreso: septiembre-2007
Ubicación: San Francisco, United States
Mensajes: 3.858
Antigüedad: 16 años, 8 meses
Puntos: 87
Respuesta: Consumir un WebMethod de tipo Lista Generica

ExalAr.WS.exalar ws = new ExalAr.WS.exalar();
List<ExalAr.WS.lstCombo> lst = ws.get_lstCombo2(1);

pero puedes probar

ExalAr.WS.exalar ws = new ExalAr.WS.exalar();
List<ExalAr.WS.lstCombo> lst = new List<ExalAr.WS.lstCombo>( ws.get_lstCombo2(1));


me cuentas como te fue.
__________________
Curso WF4
http://cursos.gurudotnet.com/ DF
Aprende HTML5
  #5 (permalink)  
Antiguo 13/11/2008, 14:51
 
Fecha de Ingreso: julio-2008
Mensajes: 24
Antigüedad: 15 años, 9 meses
Puntos: 0
Respuesta: Consumir un WebMethod de tipo Lista Generica

Dada la naturaleza de los web service no vas a poder hacer que te devuelva una collection...

Si te fijaras en el error verias que te esta devolviendo un array de objectos por lo tanto:

ExalAr.WS.exalar ws = new ExalAr.WS.exalar();
ExalAr.WS.lstCombo[] lst = (ExalAr.WS.lstCombo[]) ws.get_lstCombo2(1);
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:58.