Wednesday, February 03, 2010

Building a Basic Web Server Using WCF

In my last post, I talked about how WCF actually can handle a lot more than basic web service communication. Today, I’m going to take that a little further, by showing you how you could build a very basic web server on top of WCF.

If you are familiar with ASP.NET, you have probably heard of a little class called IRequestHandler. In ASP.NET, if you wanted to create a handler that simply streamed a file from disk, you might write a little code like this:
view plaincopy to clipboardprint?

  1. public class FileRequestHandler : IHttpHandler  
  2. {  
  3.     #region IHttpHandler Members  
  4.  
  5.     public bool IsReusable  
  6.     {  
  7.         get { return false;  }  
  8.     }  
  9.  
 10.     public void ProcessRequest(HttpContext context)  
 11.     {  
 12.         context.Response.WriteFile(context.Request.PhysicalPath);  
 13.     }  
 14.  
 15.    

Posted via email from jasper22's posterous