Click here to Skip to main content
15,883,458 members
Please Sign up or sign in to vote.
0.00/5 (No votes)

I have the following error creating and simple service with WCF REST (just for Simplifying the code, I don't create an interface)

  public class Regiones
      RegionesServiceEntities db = new RegionesServiceEntities();

      [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/Ciudad/{NombreCiudad}")]
      public string Ciudades(int id)
          var query = from t in db.Ciudad
                      where t.CiudadID == id
                      select new { t.NombreCiudad };
          var mObjeCiudad = query.SingleOrDefault();
          return mObjeCiudad.ToString();

      [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/Departamento/{NombreDepartamento}")]
      public string Departamento(int id)
          var query = from t in db.Departamento
                      where t.DepartamentoID == id
                      select new { t.NombreDepartamento };
          var mObjDepto = query.SingleOrDefault();
          return mObjDepto.ToString();

      [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/Pais/{NombrePais}")]
      public string Paises(int id)
          var query = from t in db.Pais
                      where t.PaisID == id
                      select new { t.NombrePais};
          var mObjPais = query.SingleOrDefault();
          return mObjPais.ToString();

and the web.config was organized like this...

<?xml version="1.0" encoding="utf-8"?>
    <!-- For more information on Entity Framework configuration, visit -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2" />
      <service behaviorConfiguration="ServiceBehavior" name="coRegionesService.Regiones">
        <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding"
          bindingConfiguration="webHttpBindingWithJsonP" contract="coRegionesService.IRegiones" />

        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false" />
        <behavior name="web">
          <webHttp />
      <add binding="basicHttpsBinding" scheme="https" />
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
        <binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" />

    <modules runAllManagedModulesForAllRequests="true" />
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
    <directoryBrowse enabled="true" />
    <add name="RegionesServiceEntities" connectionString="metadata=res://*/RegionesModel.csdl|res://*/RegionesModel.ssdl|res://*/RegionesModel.msl;provider=System.Data.SqlClient;provider connection string="data source=Express/database;initial catalog=RegionesService;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
        <parameter value="mssqllocaldb" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />

and the error that shows me is this

The operation 'Cities' contract 'Regions' has a UriTemplate that expects a parameter called 'NameCity', but there is no parameter entry with that name in the operation.

any help??

What I have tried:

[WebInvoke(Method = "GET", UriTemplate = "ciudades/{NombreCiudad}", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
public string Ciudades(int id)
[WebInvoke(Method = "GET", UriTemplate = "departamento/{NombreDepartamento}", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
public string Departamento(int id)
David_Wimbley 8-Aug-16 11:32am    
Have you tried changing "/Ciudad/{NombreCiudad}" to "/Ciudad/{id}" in your URI templates. I believe the URI template paramter ( the text inside the curly brackets) needs to be the same as what is in the signature of your method.

So if you have a parameter of string id, your URI template should reference {id}. Either that or you need to change your parameter name in your methods to match what is in the curly brackets. ex: ciudades/{NombreCiudad} template needs to have a parameter being passed into the method public string Ciudades(string NombreCiudad)
GREG_DORIANcod 8-Aug-16 11:49am    
yes!! I did that!! a new error shows The ends using 'UriTemplate' can not be used with 'System.ServiceModel.Description.WebScriptEnablingBehavior'.
David_Wimbley 8-Aug-16 14:11pm    
I think this link may be of help for the new error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900