---------IserviceHorarios----
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfService2
{
// NOTA: puede usar el comando "Rename" del menú "Refactorizar" para cambiar el nombre de interfaz "IService1" en el código y en el archivo de configuración a la vez.
[ServiceContract]
public interface IServiHorarios
{
[OperationContract]
Boolean insertarprofesor(string nom, string app, string apm, string area, string cat, ref string mensaje);
[OperationContract]
List<string> MostrarProfesores(ref string mensaje);
// TODO: agregue aquí sus operaciones de servicio
}
// Utilice un contrato de datos, como se ilustra en el ejemplo siguiente, para agregar tipos compuestos a las operaciones de servicio.
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
}
-------------------ServiHorarios-----------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using ClassADO;
using System.Data.SqlClient;
namespace WcfService2
{
// NOTA: puede usar el comando "Rename" del menú "Refactorizar" para cambiar el nombre de clase "Service1" en el código, en svc y en el archivo de configuración.
// NOTE: para iniciar el Cliente de prueba WCF para probar este servicio, seleccione Service1.svc o Service1.svc.cs en el Explorador de soluciones e inicie la depuración.
public class ServiHorarios : IServiHorarios
{
//UsaSql obdat = new UsaSql() { Cadconex= "Data Source=IDEA-PC; Initial Catalog=Grupos_Uni; Integrated Security=true"};
UsaSql obdat = new UsaSql() { Cadconex = @"Data source=DESKTOP-GVCS8DD; Initial catalog=Grupos_Uni; Integrated security=true;" };
public bool insertarprofesor(string nom, string app, string apm, string area, string cat, ref string mensaje)
{
Boolean salida = false;
SqlConnection cn1 = null;
cn1 = obdat.Conectar(ref mensaje);
string sql1 = "insert into Profesor(nombre,app,apm,area,categoria) values ('" + nom + "','" + apm + "','" + apm + "','" + area + "','" + cat + "')";
salida = obdat.modificarBD(cn1, sql1, ref mensaje);
return salida;
}
public List<string> MostrarProfesores(ref string mensaje)
{
SqlConnection cn1 = null;
cn1 = obdat.Conectar(ref mensaje);
string consulta = "select * from Profesor";
SqlDataReader contenedor = null;
contenedor = obdat.ConsultaReader(cn1, consulta, ref mensaje);
List<string> resultados = new List<string>();
if(contenedor!=null)
{
while(contenedor.Read())
{
resultados.Add(contenedor[0].ToString() + " " + contenedor[1].ToString() + " " + contenedor[2].ToString() + " " + contenedor[3].ToString());
}
}
return resultados;
}
}
}
----------------------------------
----------------------------------------------------
<connectionStrings>
<add name="cn1" providerName="System.Data.SqlClient" connectionString="Data Source=DESKTOP-GVCS8DD;Initial Catalog=Grupos_Uni;Integrated Security=true" />
<add name="cn_extra" connectionString="" />
</connectionStrings>
No hay comentarios.:
Publicar un comentario