Video Tutorial: Web Service SoftWare Factory 2010 & VS 2010 (4-4) Implementando y consumiendo el Servicio

Esta esta la cuarta entrega del video tutorial Web Service SoftWare Factory 2010 & VS 2010 , en esta ultima entrega veremos “Implementando y consumiendo el servicio” , si usted llego a este link directamente le recomiendo revisar las entregas anteriores , las mismas se encuentran en los  siguientes enlaces:

Video Tutorial: Web Service SoftWare Factory 2010 & VS 2010 (1-4) Introducción ,Creando Data Contracts
Video Tutorial: Web Service SoftWare Factory 2010 & VS 2010 (2-4) Creando Service Contract
Video Tutorial: Web Service SoftWare Factory 2010 & VS 2010 (3-4) Creando Host

Como siempre el Video tutorial esta detallado y no busca ser extremadamente técnico ni hacer gala de amplitud o profundidad y tener como resultado algo que no puedan hacer , todo lo contrario la intención es que conozcan y tengan una buena experiencia usando WSSF a través de este material , disfruten esta ultima entrega y bienvenidos serán vuestros comentarios.



 

Código para la implementación y consumir el servicio

 

Product.cs
----------------------------------
public class Product
{
    public int ProductId { get; set; }
    public String ProductName { get; set; }
    public int CategoryId { get; set; }
}


ConnectionManager.cs
------------------------------------

   internal sealed class ConnectionManager
    {
        public static SqlConnection GetConnection()
        {
            string connectionString = ConfigurationManager.ConnectionStrings["NorthWind"].ConnectionString;
            SqlConnection connection = new SqlConnection(connectionString);
            connection.Open();
            return connection;
        }

 


ProductDataAccess.cs
------------------------------------------
  public List<Product> GetAllFromProducts()
        {
            SqlDataReader readerproduct;
            List<Product> products = new List<Product>();
            using (SqlCommand cmdGetAllFromProducts = new SqlCommand("Select ProductId,ProductName,CategoryId From Products", ConnectionManager.GetConnection()))
            {
                cmdGetAllFromProducts.CommandType = CommandType.Text;
                readerproduct = cmdGetAllFromProducts.ExecuteReader(CommandBehavior.CloseConnection);
                while (readerproduct.Read())
                {
                    Product obj = new Product();
                    obj.ProductId = readerproduct.GetInt32(0);
                    obj.ProductName = readerproduct.GetString(1);
                    obj.CategoryId = readerproduct.GetInt32(2);

                    products.Add(obj);
                }
            }
            return products;

        }
     
    }

 

ProductBusinessLogic.cs
-------------------------------
    public List<Product> GetAllFromProducts()
        {
            ProductDataAccess objProducto = new ProductDataAccess();
            return objProducto.GetAllFromProducts();
        }


NWService.cs
------------------------------
  ResponseMessage respuesta = new ResponseMessage();
            ProductBusinessLogic objlogic = new ProductBusinessLogic();
            List<Product> listaProductos = objlogic.GetAllFromProducts();
            ProductDataContract objProducto;
            respuesta.ListaProductosPart = new ProductDataContractCollection();

            foreach (Product item in listaProductos)
            {
                objProducto = new ProductDataContract();
                objProducto.ProductId = item.ProductId;
                objProducto.ProductName = item.ProductName;
                objProducto.CategoryId = item.CategoryId;
                respuesta.ListaProductosPart.Add(objProducto);
            }
            return respuesta;

 

Web.Config
----------------------
    <connectionStrings>
        <add name="NorthWind" connectionString="Data Source=CARLOS-PC\SQLEXPRESS;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Password=P@$$w0rd"

providerName="System.Data.SqlClient"/>
    </connectionStrings>

 

ResultGrid

--------------------

//Close();
NWServiceContractClient Proxy1 = new NWServiceContractClient();
this.dataResults.DataSource = Proxy1.SelectAllOperation();
List<Product> listaProductos = new List<Product>();
Product objProducto;
var resultado = Proxy1.SelectAllOperation();

foreach (var item in resultado)
{
    objProducto = new Product();
    objProducto.ProductId = item.ProductId;
    objProducto.ProductName = item.ProductName;
    objProducto.CategoryId = item.CategoryId;
    listaProductos.Add(objProducto);
}

this.dataResults.DataSource = listaProductos;

Published 31/1/2012 1:42 por Carlos Chavez
Comparte este post:
http://geeks.ms/blogs/cchavez/archive/2012/01/31/video-tutorial-web-service-software-factory-2010-amp-vs-2010-4-4-implementando-y-consumiendo-el-servicio.aspx

Comentarios

# Agenda de la Comunidad (6 Feb – 12 Feb)

Agenda Lunes, 6 febrero Entranamiento Windows Phone Intructores De laboratorio de Windows Phone Hora

Monday, February 06, 2012 7:16 PM por MVP Factor

# Agenda de la Comunidad (6 Feb – 12 Feb)

Agenda Lunes, 6 febrero Entranamiento Windows Phone Intructores De laboratorio de Windows Phone Hora

Monday, February 06, 2012 7:16 PM por MVP Factor