Sorry, I have not seen an example using self-defined templates
except the defaults in Starter Kit 2. If you want to use your own UriTemplates, I think you can try in this way.
1. delete the default svc file and related code file.
2. add a new WCF Service item (3 files will be added, here suppose they are IService.cs, Service.svc and Service.svc.cs)
3. edit the content is the three files.
IService.cs
using System.ServiceModel;
using System.ServiceModel.Web;
namespace CollectionService
{
[ServiceContract]
public interface IEmployeeService
{
[OperationContract]
[WebGet(UriTemplate = "{id}")]
string GetEmployee(string id);
[OperationContract]
[WebGet(UriTemplate = "{id}/{departmentId}")]
string AddEmployee(string id, string departmentId);
}
}
Service.svc.cs
using System;
namespace CollectionService
{
public class Service :IEmployeeService
{
public string GetEmployee(string id)
{
return String.Format("U R requesting employee '{0}'", id);
}
public string AddEmployee(string id, string departmentId)
{
return String.Format("U R requesting employee '{0}' department '{1}'"
, id, departmentId);
}
}
}
Service. svc ( Add the WebServiceHostFactory)
<%@ ServiceHost Language="C#" Debug="true" Service="CollectionService.Service"
CodeBehind="Service.svc.cs"
Factory="System.ServiceModel.Activation.WebServiceHostFactory"%>
4. At last, delete the tag and its content in the config file.
5. View Service.svc in browser , and add "/ddd" or "/ddd/eee" to the end of the URI you will see:
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">U R requesting employee 'ddd'</string>
and
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">U R requesting employee 'ddd' department 'eee'</string>
Besides, you can also install the Starter Kit Preview 1, because it automatically adds a 'service.base.svc.cs' file, in which you can modify the UriTemplates .