0

Recently I've been trying to publish a Restful service in IIS7 but didn't have luck with it. When published it doesn't recognize the endpoint i have assigned at the web.config. The IIS 7 is a localhost for now, once i get it started I will move it to my client server. Below is the Interface:

[ServiceContract]
public interface ICOService
{
    /// <summary>
    /// Devuelve la lista de los anos de los autos (lol)
    /// </summary>
    /// <returns></returns>
    [OperationContract]
    [WebInvoke(Method = "GET", UriTemplate = "/AnosAutos", ResponseFormat = WebMessageFormat.Json, 
        RequestFormat = WebMessageFormat.Json)]
    List<AnosAutos> GetAnosAutos();

    /// <summary>
    /// Returns the result of Autos Search
    /// </summary>
    /// <returns></returns>
    [OperationContract(Name="GetAutosAll")]
    [WebInvoke(Method = "POST", UriTemplate = "/Autos", ResponseFormat = WebMessageFormat.Json,
        RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
    List<Autos> GetAutos(string allYear, string marca, string categoria, string lowerPrice, string upperPrice);

}

Below is the Service implementation:

    public class COService : ICOService
{
    private COEntities context = new COEntities();

    public List<AnosAutos> GetAnosAutos()
    {
        List<AnosAutos> list = new List<AnosAutos>();
        list = ConvertFromEntityToObject(list);
        return list;
    }

    /// <summary>
    /// Convert entity WP_AnosAutos to class AnosAutos
    /// </summary>
    /// <param name="list">Contains list of type AnosAutos</param>
    /// <returns>Returns the converted list</returns>
    private List<AnosAutos> ConvertFromEntityToObject(List<AnosAutos> list)
    {
        List<WP_AnosAutos> temp = context.WP_AnosAutos.ToList();
        foreach (WP_AnosAutos wp in temp)
        {
            AnosAutos aa = new AnosAutos();
            //aa.ID = wp.ID;
            aa.AutoYear = wp.AutoYear;
            list.Add(aa);
        }
        return list;
    }

    /// <summary>
    /// Returns all Autos without being filtered by year.
    /// </summary>
    /// <param name="allYear"></param>
    /// <param name="marca"></param>
    /// <param name="categoria"></param>
    /// <param name="lowerPrice"></param>
    /// <param name="upperPrice"></param>
    /// <returns></returns>
    public List<Autos> GetAutos(string allYear, string marca, string categoria, string lowerPrice, string upperPrice)
    {
        List<Autos> list = new List<Autos>();
        list = ConvertFromEntityToObject(list, allYear, marca, categoria, lowerPrice, upperPrice);
        return list;
    }

    /// <summary>
    /// Convert entity WP_Autos to class Autos
    /// </summary>
    /// <param name="list">Contains list of type Autos</param>
    /// <returns>Returns the converted list</returns>
    private List<Autos> ConvertFromEntityToObject(List<Autos> list,
        string year, string marca, string categoria, string lowerPrice, string upperPrice)
    {
        List<WP_Autos> temp = context.GetFilteredAutos(Convert.ToInt32(year), null, null, 
            marca, categoria, Convert.ToInt32(lowerPrice), Convert.ToInt32(upperPrice)).ToList();
        foreach (WP_Autos wp in temp)
        {
            Autos a = new Autos();
            a.ID = wp.ID;
            a.SocioID = wp.SocioID;
            a.SocioLogo = wp.SocioLogo;
            a.Marca = wp.Marca;
            a.Modelo = wp.Modelo;
            a.Descripcion = wp.Descripcion;
            a.Foto = wp.Foto;
            a.Nombre = wp.Nombre;
            a.PersonaContacto = wp.PersonaContacto;
            a.Email = wp.Email;
            a.Tel = wp.Tel;
            a.Tel2 = wp.Tel2;
            a.Categoria = wp.Categoria;
            a.Municipio = wp.Municipio;
            a.Millaje = wp.Millaje;
            a.Precio = wp.Precio;
            a.Comentario_Precio = wp.Comentario_Precio;
            a.Ano = wp.Ano;
            list.Add(a);
        }
        return list;
    }

Below is the Web.Config :

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="COWebService">
        <endpoint name="AnosAutos" address="/AnosAutos" binding="webHttpBinding" contract="COWebService.ICOService.GetAnosAutos" behaviorConfiguration="JsonBehavior">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint name="AutosAll" address="/Autos" binding="webHttpBinding" contract="COWebService.ICOService.GetAutosAll" behaviorConfiguration="JsonBehavior">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="JsonBehavior">
          <enableWebScript />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <connectionStrings>
        <remove name="LocalSqlServer" />
    <add name="COEntities" connectionString="metadata=res://*/COModel.csdl|res://*/COModel.ssdl|res://*/COModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=DataSourceHere;Initial Catalog=DBNameHere;User ID=IDHere;Password=PassHere;Application Name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

Database Hosting: Azure but soon on a local premises as soon as I get home I'll make the migration. Current Problem: Can't download information from the internet using the WebService I've created. Problem Encountered: Returns HTTP 405: Method not allowed. Sometimes depending in the place that I am the endpoint returns an error related to the entity framework. More Info:Trying to host a service using .Net Framework 4 Lucky Shots: Got one endpoint running(AnosAutos) but other returned method not allowed HTTP 405. I have been three weeks into this an decided to post it in stackoverflow. If you need more info please say it.

Darren
  • 68,902
  • 24
  • 138
  • 144
Roberto Durand
  • 137
  • 1
  • 1
  • 13

1 Answers1

-1

you should call GetAutos() with HTTP POST

Rajes
  • 1,036
  • 10
  • 15