WCF, Self-Hosted through IIS, RESTFul

Looking into WCF for a couple projects I’ve involved with and so far its great. If you are one of those dev teams who need to configure your service for consummation across myriad of technologies. WCF is an extremely powerful technology. Being involved in a primarily microsoft shop though sometimes causes you to pick products through convenience oppose to them being the right tools. I’m in that boat as of right now. Do I need a way to deploy service oriented technologies? Yes. Do I need to configure the same service in terms of its binding/address or can I pretty much just get by with using a HttpWebRequest and hosting through IIS. Yes. With that an aspect of what makes WCF so great is kind of out the door. Additionally with its host of configurable facilities, its difficult to sift through all the tech to find out exactly what you need.

What I need is something hosted through IIS and is RESTFul for simplicity.

Three things you need.

  • 1. Any web application.
  • 2. WebGetAttribute found in System.ServiceModel.Web.
    • Used as follows
      [OperationContract]
      [WebGet(UriTemplate="*")]
      string CheckStatus();
    • So basically in the case where you simply access http://…/Service.svc, it would access CheckStatus()
    • Using the WebInvoke method you can access post requests as well.
    • UriTemplate is also very important as that allows you do define more descriptive routes or requests.
      • Consider the following piece code.[WebGet(UriTemplate="/User/{userName}")]
        string GetUserInfo(string userName)
      • Now accessing the following resource http://…/Service.svc/User/Evan will route to GetUserInfo passing in “Evan” as userName
  • Now so assuming that you can just have httpWebBinding and its hosted through IIS you can skip the web.config changes access the markup in Service.svc and add the attribute Factory=”System.ServiceModel.Activation.WebServiceHostFactory” into node in there. (Note .NET 3.5 intellisense doesn’t appear to acknowledge this attribute)
  • One other note is if you are adding this service into an MVC web application, you’ll might want to tell your app to ignore routes which access your service.svc. public static void RegisterRoutes(RouteCollection routes)
    {
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.IgnoreRoute("{resource}.svc/{*pathInfo}");
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.