VOSID
VOSID
CC#
Created by VOSID on 6/22/2024 in #help
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);
}
}
}
}
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);
}
}
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);
}
}
1 replies