« March 2008 | Main | June 2008 »

May 2008

Smells like a domain-specific language for using WCF


No, not these kinds of domain-specific languages (DSL)...
I must admit, the following code has a not too small degree of sexiness. The DSL-iness is not just for WCF but for a number of mainly dependency-injection-related scenarios, but obviously I tend to care more about WCF :)

Service side:

var windsorContainer = new WindsorContainer()
  .AddFacility<WcfFacility>()
  .Register(
    Component.For<LoggingInterceptor>(),
    Component.For<IMyContract>().ImplementedBy<MyService>()
      .ActAs(new DefaultServiceModel().AddEndpoints(
        WcfEndpoint
          .BoundTo(new NetTcpBinding())
          .At("net.tcp://localhost/MyService/internal")
          )
      )
  );


Consumer side:

var windsorContainer = new WindsorContainer()
  .AddFacility<WcfFacility>()
  .Register(WcfClient.ForChannels(
    new DefaultClientModel()
    {
      Endpoint = WcfEndpoint.ForContract<IMyContract>()
        .BoundTo(new NetTcpBinding())
        .At("net.tcp://localhost/MyService/internal")
    })
   )
  );

                    
I am currently investigating a bit into Windsor Castle and its WCF facility. What I see until now I like, but I am just at the beginning.
There is a lot more in Windsor's WCF support which is worth digging into - all in all these features are aimed to make using WCF a bit more natural and a  bit more straight-forward.

Some feature points from the latest release:

*Client Side:
  • Automatic generation of WCF client channels when a component has been configured for WCF Client capabilities.
  • Any Endpoint or Operation behaviors registered in the kernel will be attached to the channels.
  • Automatic cleanup of channel proxy when component is released (channel.Close() vs channel.Abort), i.e. no need to cast proxy to IChannel and call Dispose.
  • Automatic detection of unhanded channel faults and re-acquisition of new channel proxy. You can continue to use client proxy even after an exception occurs (by default WCF makes all faulted channels unavailable).
  • Ability to use the client channel configuration from app.config/web.config      
  • Custom registration provider to simplify batch registration of channels
  • Client extensibility interface IClientChannelBuilder. Supports plugging in other ways to create channels (e.g. REST-ful services)
 
*Service Side:
  • Automatic management of ServiceHost when a component is configured for WCF Service capabilities.
  • Any Service, Endpoint or Operation behaviors registered in the kernel will be attached to the channels.
  • Ability to use the service channel configuration from app.config/web.config
  • Service extensibility interface IServiceHostBuilder. Support for plugging in other ways to create ServiceHosts.
 More to investigate...


WCF-related features in .NET 3.5 SP1 & VS 2008 SP1


Update: Steve and Omri have the official voices :)

In addition what Scott has in its extensive article on SP1, lemme show you some more data on what is new and supported for WCF in SP1 of .NET 3.5 and Visual Studio 2008 - this list is not authoritative, it is my list and not Microsoft's official one.
  • DataContractSerializer can now serialize types without the need to annotate them with [DataContract] & DataContract-related attributes, aka POCO support
  • Better support for object references in DataContractSerializer
  • Support for interoperable object references in DataContractSerializer
  • Support for fault detail serialization by XmlSerializer
  • Event Logging is now enabled in partial trust
  • Syndication object model supports the ServiceDocument in Atom Publishing Protocol (APP)
  • URI templates & URI template table extended to better support ASP.NET MVC
  • Hosting Wizard for Visual Studio WCF Service projects in IIS
  • Expanded support in WCF Test Client
    • Support for RM Sessions
    • Support MessageContract + XmlSerializer
    • Support Nullable<T> types
    • Support to run stand-alone
  • WCF Service Application template enabled in Visual Web Developer Express