开发者

Is it possible to set a default operation when setting up a service route

I'm evaluating setting up a REST system using WCF against using MVC (which I currently have). I've got it running but would like to be able to replicate some functionality that I get with MVC.

That is, I need to be able 开发者_C百科to specify the WCF equivalent of a 'default action'. Whilst service route has a defaults property, I've not found any docs on what to set in here (assuming that it is even used in WCF).

The next step, that I can see, would be to write my own service host factory and have a custom attribute but that takes me one step to far (potentially anyway) as I'm already using Autofac to DI the service dependencies.

Is a default 'operation contract' possible with REST over WCF?


Creating a new project using the REST 4.0 Template includes the following:

[WebGet(UriTemplate = "")]
public List<SampleItem> GetCollection()
{
 // TODO: Replace the current implementation to return a collection of SampleItem instances
 return new List<SampleItem>() { new SampleItem() { Id = 1, StringValue = "Hello" } };
}

The /service1/help screen then lists the following:

Uri Method                                       Description

GET Service at http://localhost:60888/Service1/

So the default 'action' is that specified with an empty UriTemplate.


Ok, I feel a little foolish as the URI template in the WebGet attribute does what I need, ie:

[OperationContract]
[WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "{id}")]
User GetUser(String id);

Serves me right for late night coding.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜