Saturday, February 07, 2009
Self-Hosting Basic HTTP WCF Services
Milos provides a real simple way to develop and host (both in runtime as well as debug scenarios) WCF services. This is especially true for binary, TCP/IP based services that are great to use when both the client and the server are .NET applications. Another common scenario is hosting WCF services as HTTP and XML based web services. Especially with Silverlight, basic HTTP based services have gained more importance again. Of course, it is simple to host such services in IIS, and thus we have not provided any special features around that in Milos.
At least not so far. One of the scenarios people have pointed out to us (and frankly, we've run into ourselves too) is a deployment of the same service using multiple bindings. Why deploy one app for TCP/IP and then create a separate, ASP.NET based web app for XML web service support?
We have now created support for Milos aided, self-hosted Basic HTTP services. This is supported both in the ServiceGarden and development host environments. Here is an example of hosting a service in both TCP/IP and Basic HTTP configurations at the same time:
ServiceGarden.AddServiceHostNetTcp(typeof(EventService));
ServiceGarden.AddServiceHostBasicHttp(typeof(EventService));This example was from a runtime deployed service (likely hosted in a Windows Service). The following example shows the same service hosted in the development environment with support for both protocols.
var host = new TestServiceHost();
host.AddNetTcpService(typeof(EventService));
host.AddBasicHttpService(typeof(EventService));
Accordingly, the ServiceClient class can now also natively open a connection to a Basic HTTP driven service. (Application configuration now supports "BasicHttp" as an additional service binding).
Enjoy!
Posted @ 4:46 PM by Egger, Markus (markus@code-magazine.com)
Post a Comment:
Comment Title (required):
Your Name (optional):
Your Email (optional):
Your Web Site (optional):
Your Comment (required):