Tema: Web Services
Ver Mensaje Individual
  #7 (permalink)  
Antiguo 14/06/2010, 14:35
Veronica_ctes
 
Fecha de Ingreso: diciembre-2005
Mensajes: 3
Antigüedad: 18 años, 4 meses
Puntos: 0
Respuesta: Web Services - Nueva consulta

Hola amigos.. estoy probando códigos para intentar comprender como funciona un web service leyendo de una base de datos y mostrando los mismos a través d eun DataSet.. el problema con este código es que a pesar de compilar sólo me devuelve un xml así <DataSet xsi:nil="true"/>

Probé quitar y agregar muchas cosas en el código pero siempre me devuelve lo mismo. Posteo el código para que me digan que estoy haciendo mal .. Aclaro que estoy utilizando Visual Studio 2008 y el web service en c#. Desde ya muchas gracias

using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

using System.Data;
using System.Data.SqlClient;


[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// Para permitir que se llame a este servicio web desde un script, usando ASP.NET AJAX, quite la marca de comentario de la línea siguiente.
// [System.Web.Script.Services.ScriptService]
public class ComplexTypes : System.Web.Services.WebService {


public string cConnectString = "server=(local);database=pubs;uid=sa;pwd=;";
public SqlConnection oConn = null;
public DataSet oDS = null;
public string cErrormsg = "";
public bool lError = false;

private void SetError(string mensaje) {
mensaje = "Ocurrió un error.";
}

protected bool Open() {
if (this.oConn == null) {
try {
this.oConn = new SqlConnection(this.cConnectString);
}
catch(Exception e) {
this.SetError(e.Message);
return false;
}
}
if (this.oConn.State != ConnectionState.Open) {
try {
oConn.Open();
}
catch(Exception e) {
this.SetError(e.Message);
return false;
}
}
/// make sure our dataset object exists
if (oDS == null)
{
oDS = new DataSet();
}
return true;
}

private int Execute(string lcSQL, string lcCursor)
{
if (!this.Open())
return 0;

SqlDataAdapter oDSCommand = new SqlDataAdapter();
oDSCommand.SelectCommand = new SqlCommand(lcSQL, oConn);
DataSet oDS = new DataSet();


oDSCommand.Fill(oDS, lcCursor);

return oDS.Tables[lcCursor].Rows.Count;
}

public ComplexTypes () {

//Eliminar la marca de comentario de la línea siguiente si utiliza los componentes diseñados
//InitializeComponent();
}


[WebMethod]
public DataSet GetAuthorList(string lcNameFilter) {
if (lcNameFilter.Length == 0)
lcNameFilter = "%";
/// Open the connection to the database

int lnResult = this.Execute("select au_lname,au_fname AS name, pk " +
"from authors where au_lname like '" +
lcNameFilter + "%'" +
" order by au_lname","Authors");
if (this.lError) {
this.Close();
return null;
}
return this.oDS;
}

private void Close()
{
throw new NotImplementedException();
}

}