C#C
C#2y ago
VOSID

EndPoints not working WCF, service is running

Hii! I'm trying my hands on WCF but facing problem.
My http://localhost:37176/PokemonService.svc is running but the endpoints (http://localhost:37176/PokemonService.svc/GetPokemon) is not showing This site can’t be reached. The connection was reset.

My PokemonService.svc is
c#
using System.Collections.Generic;
using System.Linq;

namespace WcfService1
{
    public class PokemonService : IPokemonService
    {
        public List<Pokemon> GetPokemon()
        {
            using (var db = new PokemonEntities())
            {
                return db.Pokemons.ToList();
            }
        }

        public Pokemon GetPokemonById(string id)
        {
            int pokemonId = int.Parse(id);
            using (var db = new PokemonEntities())
            {
                return db.Pokemons.FirstOrDefault(p => p.Id == pokemonId);
            }
        }
    }
}

IPokemonService.cs is
C#
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Web;

namespace WcfService1
{
    [ServiceContract]
    public interface IPokemonService
    {
        [OperationContract]
        [WebGet(UriTemplate = "/GetPokemon", ResponseFormat = WebMessageFormat.Json)]
        List<Pokemon> GetPokemon();

        [OperationContract]
        [WebGet(UriTemplate = "/GetPokemonById/{id}", ResponseFormat = WebMessageFormat.Json)]
        Pokemon GetPokemonById(string id);
    }
}
Was this page helpful?