I am new to the management of web services I have finished my class product and my webservice.asmx I show the code, well the fact is that when I publish correctly the web service in IIS no there are errors all right, long before returning the application, in the Admin panel of the IIS add the extensions .asmx in the MIME, then go to convert the folder of the web service into application, activate the examination of directories and then I gave in examine and the next result is this:
I do not know what the error is but I still leave the code Class Products :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebDrinks
{
public class Productos
{
public int id { get; set; }
public int id_categoria { get; set; }
public int id_subcategoria { get; set; }
public String titulo { get; set; }
public String titular { get; set; }
public String descripcion { get; set; }
public int stock { get; set; }
public decimal precio { get; set; }
public String imagen { get; set; }
public Productos()
{
this.id = 0;
this.id_categoria = 0;
this.id_subcategoria = 0;
this.titulo = "";
this.titular = "";
this.descripcion = "";
this.stock = 0;
this.precio = 0;
this.imagen = "";
}
public Productos(int id, int cat, int subc, String ti, String titu, String des, int stock, decimal precio, String img)
{
this.id = id;
this.id_categoria = cat;
this.id_subcategoria = subc;
this.titulo = ti;
this.titular = titu;
this.descripcion = des;
this.stock = stock;
this.precio = precio;
this.imagen = img;
}
}
}
WebService
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
namespace WebDrinks
{
/// <summary>
/// Descripción breve de WebDrinks
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 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 WebDrinks : System.Web.Services.WebService
{
SqlConnection con = new SqlConnection
(@"data source=DESKTOP-9695OA0\MSSQLSERVER1; initial catalog=drinks2u;user id=sa;password=sahc");
[WebMethod]
public string HelloWorld()
{
return "Hola a todos";
}
[WebMethod]
public Productos[] listarProductos()
{
Productos[] lista = null;
con.Open();
string query = "SELECT * FROM Productos";
SqlCommand cmd = new SqlCommand(query, con);
SqlDataReader dr = cmd.ExecuteReader();
List<Productos> list = new List<Productos>();
while (dr.Read())
{
list.Add(new Productos(dr.GetInt32(0), dr.GetInt32(1), dr.GetInt32(2), dr.GetString(3), dr.GetString(4), dr.GetString(5),
dr.GetInt32(6), dr.GetDecimal(7), dr.GetString(8)));
}
lista = list.ToArray();
con.Close();
return lista;
}
[WebMethod]
public void InsertarUsuario(String nom, String correo, String pass, Char dir, String img)
{
con.Open();
string query = "INSERT INTO usuarios VALUES (@nom,@correo,@pass,@dir,@img)";
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.Add("@nom", System.Data.SqlDbType.NVarChar).Value = nom;
cmd.Parameters.Add("@correo", System.Data.SqlDbType.NVarChar).Value = correo;
cmd.Parameters.Add("@pass", System.Data.SqlDbType.NVarChar).Value = pass;
cmd.Parameters.Add("@dir", System.Data.SqlDbType.NChar).Value = dir;
cmd.Parameters.Add("@img", System.Data.SqlDbType.NVarChar).Value = img;
cmd.ExecuteNonQuery();
con.Close();
}
}
}