In the keynote yesterday, Don Box and Chris Anderson showed how Indigo can be used in a REST style by sending Plain Old XML (POX) over HTTP. It’s a great testament to the quality of the Indigo extensibility architecture that they could do this. By supporting both the REST and SOAP styles it takes the heat out of the debate that one is better than the other.
One of the Hands On Labs goes through the code they used in detail. The example uses a HTTP GET request to return a plain XML payload, in this case a RSS feed. An extra level of detail was the fact that the RSS added a custom element indicating an 'adult content rating' system, which was signed. There were several interesting points from the Hands On Lab.
One complexity around supporting a REST style with Indigo comes from the fact that the HTTP GET request does not have any WS-Address-style action. To get around this you can use the mapAddresssHeadersToHttpHeaders attribute of the HttpBindingElelement to make the URI of the HTTP GET request the To value on the Indigo Message object.
Since no action is specified on the HTTP GET request the ServiceContract needs to trap any unmatched action using the OperationContract's Action named parameter:
public interface IRestStyleRequestResponse
{
[OperationContract(Action="*")]
Message GetRequest(Message request);
}
Since the HTTP GET request on the HTTP transport in Indigo usually returns a description of the service, this needs to be turned off using the Description property of an instance of the ServiceHost type:
// service is an instance of ServiceHost
// stop the HTTP GET returning the site description.
service.Description.Behaviors.Remove(typeof(ServiceMetadataBehavior));
To hook in this binding a custom BindingElement extension was written. The lab walked through creating a IChannelFactory and IListenerFactory and the rest of the necessary objects as part of the WCF stack. Just before the transport binding element in the Binding stack there's a custom encoder which does the job of writing out the Message to the wire as plain XML, rather than a SOAP message (as Don Box said yesterday, 'it lathers the SOAP off the message on the way out and SOAPs up the message on the way back in').