<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Pablo M. Cibraro (aka Cibrax) </title><link>http://weblogs.asp.net/cibrax/default.aspx</link><description>My thoughts on Web Services and .NET development</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/cibrax" type="application/rss+xml" /><item><title>Disposing a WCF Proxy</title><link>http://feedproxy.google.com/~r/cibrax/~3/rGBuzuKL58Q/disposing-a-wcf-proxy.aspx</link><pubDate>Fri, 26 Jun 2009 13:39:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7134921</guid><dc:creator>cibrax</dc:creator><slash:comments>0</slash:comments><comments>http://weblogs.asp.net/cibrax/archive/2009/06/26/disposing-a-wcf-proxy.aspx#comments</comments><description>&lt;P&gt;A common misconception is to think that a WCF proxy can be used and disposed as any other regular class that implements IDisposable. However, the IDisposable implementation in the WCF client channel is not like any other, and it can throws exceptions. A phrase I got from &lt;A href="http://weblogs.asp.net/controlpanel/blogs/this%20discussion%20on%20the%20WCF%20forum"&gt;this thread&lt;/A&gt; in the WCF forum will give you a better context about this scenario,&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;“I think a key thing to notice is that Close() often implies doing "real work" that may fail, including network communication handshakes to shutdown sessions, committing transactions, etc.”&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;As consequence of this, we should add some code to handle any possible exception for network errors when a proxy is closed/disposed. &lt;/P&gt;
&lt;P&gt;The common pattern for cleaning up a proxy is the following,&lt;/P&gt;
&lt;P&gt;try &lt;BR&gt;{ &lt;BR&gt;... &lt;BR&gt;client.Close(); &lt;BR&gt;} &lt;BR&gt;catch (CommunicationException e) &lt;BR&gt;{ &lt;BR&gt;... &lt;BR&gt;client.Abort(); &lt;BR&gt;} &lt;BR&gt;catch (TimeoutException e) &lt;BR&gt;{ &lt;BR&gt;... &lt;BR&gt;client.Abort(); &lt;BR&gt;} &lt;BR&gt;catch (Exception e) &lt;BR&gt;{ &lt;BR&gt;... &lt;BR&gt;client.Abort(); &lt;BR&gt;throw; &lt;BR&gt;} &lt;BR&gt;&lt;/P&gt;
&lt;P&gt;The problem is, I do not want to have that code everywhere in my application. A good solution for that is to use a helper class like &lt;A href="http://bloggingabout.net/blogs/erwyn/archive/2006/12/09/WCF-Service-Proxy-Helper.aspx" mce_href="http://bloggingabout.net/blogs/erwyn/archive/2006/12/09/WCF-Service-Proxy-Helper.aspx"&gt;this one&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.dasblonde.net/" mce_href="http://www.dasblonde.net"&gt;Michelle&lt;/A&gt; recently announced a new project that automatically generates a proxy helper class like that in Visual Studio. &lt;A href="http://wcfproxygenerator.codeplex.com/" mce_href="http://wcfproxygenerator.codeplex.com/"&gt;http://wcfproxygenerator.codeplex.com/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;That is a feature I would like to see out of the box in the next version of WCF :).&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7134921" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/cibrax/~4/rGBuzuKL58Q" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/cibrax/archive/tags/WCF/default.aspx">WCF</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/.NET/default.aspx">.NET</category><feedburner:origLink>http://weblogs.asp.net/cibrax/archive/2009/06/26/disposing-a-wcf-proxy.aspx</feedburner:origLink></item><item><title>A Bad Idea, EF Entities over WCF</title><link>http://feedproxy.google.com/~r/cibrax/~3/8MXs2Te7UOk/a-bad-idea-ef-entities-over-wcf.aspx</link><pubDate>Thu, 25 Jun 2009 14:14:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7134097</guid><dc:creator>cibrax</dc:creator><slash:comments>4</slash:comments><comments>http://weblogs.asp.net/cibrax/archive/2009/06/25/a-bad-idea-ef-entities-over-wcf.aspx#comments</comments><description>&lt;P&gt;Do you want to see something very ugly ?. Try to send a complete EF entity directly as a data contract over the wire with WCF,&lt;/P&gt;
&lt;P&gt;&amp;lt;Order xmlns:i="&lt;A href="http://www.w3.org/2001/XMLSchema-instance" mce_href="http://www.w3.org/2001/XMLSchema-instance"&gt;http://www.w3.org/2001/XMLSchema-instance&lt;/A&gt;" z:Id="i1" xmlns:z="&lt;A href="http://schemas.microsoft.com/2003/10/Serialization/" mce_href="http://schemas.microsoft.com/2003/10/Serialization/"&gt;http://schemas.microsoft.com/2003/10/Serialization/&lt;/A&gt;" xmlns="&lt;A href="http://schemas.datacontract.org/2004/07/ClassLibrary2" mce_href="http://schemas.datacontract.org/2004/07/ClassLibrary2"&gt;http://schemas.datacontract.org/2004/07/ClassLibrary2&lt;/A&gt;"&amp;gt; &lt;BR&gt;&amp;nbsp; &amp;lt;EntityKey xmlns:d2p1="&lt;A href="http://schemas.datacontract.org/2004/07/System.Data" mce_href="http://schemas.datacontract.org/2004/07/System.Data"&gt;http://schemas.datacontract.org/2004/07/System.Data&lt;/A&gt;" i:nil="true" xmlns="&lt;A href="http://schemas.datacontract.org/2004/07/System.Data.Objects.DataClasses" mce_href="http://schemas.datacontract.org/2004/07/System.Data.Objects.DataClasses"&gt;http://schemas.datacontract.org/2004/07/System.Data.Objects.DataClasses&lt;/A&gt;" /&amp;gt; &lt;BR&gt;&amp;nbsp; &amp;lt;Description&amp;gt;My new order&amp;lt;/Description&amp;gt; &lt;BR&gt;&amp;nbsp; &amp;lt;OrderId&amp;gt;1&amp;lt;/OrderId&amp;gt; &lt;BR&gt;&amp;nbsp; &amp;lt;OrderItem&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;OrderItem z:Id="i2"&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;EntityKey xmlns:d4p1="&lt;A href="http://schemas.datacontract.org/2004/07/System.Data" mce_href="http://schemas.datacontract.org/2004/07/System.Data"&gt;http://schemas.datacontract.org/2004/07/System.Data&lt;/A&gt;" i:nil="true" xmlns="&lt;A href="http://schemas.datacontract.org/2004/07/System.Data.Objects.DataClasses" mce_href="http://schemas.datacontract.org/2004/07/System.Data.Objects.DataClasses"&gt;http://schemas.datacontract.org/2004/07/System.Data.Objects.DataClasses&lt;/A&gt;" /&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Currency&amp;gt;USD&amp;lt;/Currency&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Description&amp;gt;item 1&amp;lt;/Description&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ItemId&amp;gt;1&amp;lt;/ItemId&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Order z:Ref="i1" /&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;OrderReference xmlns:d4p1="&lt;A href="http://schemas.datacontract.org/2004/07/System.Data.Objects.DataClasses" mce_href="http://schemas.datacontract.org/2004/07/System.Data.Objects.DataClasses"&gt;http://schemas.datacontract.org/2004/07/System.Data.Objects.DataClasses&lt;/A&gt;"&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;d4p1:EntityKey xmlns:d5p1="&lt;A href="http://schemas.datacontract.org/2004/07/System.Data" mce_href="http://schemas.datacontract.org/2004/07/System.Data"&gt;http://schemas.datacontract.org/2004/07/System.Data&lt;/A&gt;" i:nil="true" /&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/OrderReference&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;UnitPrice&amp;gt;10&amp;lt;/UnitPrice&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/OrderItem&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;OrderItem z:Id="i3"&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;EntityKey xmlns:d4p1="&lt;A href="http://schemas.datacontract.org/2004/07/System.Data" mce_href="http://schemas.datacontract.org/2004/07/System.Data"&gt;http://schemas.datacontract.org/2004/07/System.Data&lt;/A&gt;" i:nil="true" xmlns="&lt;A href="http://schemas.datacontract.org/2004/07/System.Data.Objects.DataClasses" mce_href="http://schemas.datacontract.org/2004/07/System.Data.Objects.DataClasses"&gt;http://schemas.datacontract.org/2004/07/System.Data.Objects.DataClasses&lt;/A&gt;" /&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Currency&amp;gt;USD&amp;lt;/Currency&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Description&amp;gt;item 2&amp;lt;/Description&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ItemId&amp;gt;2&amp;lt;/ItemId&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Order z:Ref="i1" /&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;OrderReference xmlns:d4p1="&lt;A href="http://schemas.datacontract.org/2004/07/System.Data.Objects.DataClasses" mce_href="http://schemas.datacontract.org/2004/07/System.Data.Objects.DataClasses"&gt;http://schemas.datacontract.org/2004/07/System.Data.Objects.DataClasses&lt;/A&gt;"&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;d4p1:EntityKey xmlns:d5p1="&lt;A href="http://schemas.datacontract.org/2004/07/System.Data" mce_href="http://schemas.datacontract.org/2004/07/System.Data"&gt;http://schemas.datacontract.org/2004/07/System.Data&lt;/A&gt;" i:nil="true" /&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/OrderReference&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;UnitPrice&amp;gt;145&amp;lt;/UnitPrice&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/OrderItem&amp;gt; &lt;BR&gt;&amp;nbsp; &amp;lt;/OrderItem&amp;gt; &lt;BR&gt;&amp;lt;/Order&amp;gt;&lt;/P&gt;
&lt;P&gt;That is the result of serializing a complete object graph. I do not know what the folks in Microsoft were thinking when they decided to enable a feature like this. They made a good work teaching us about how evil Datasets were for interoperability with other platforms, and now they came up with a solution like this, no way.&lt;/P&gt;
&lt;P&gt;I always like the idea of making boundaries explicit, that is the approach the WCF team took with the first version of the framework (Every data contract should be decorated with DataContract and DataMember attributes).&amp;nbsp; If you break that rule, you will end up with things like this. &lt;/P&gt;
&lt;P&gt;I know this a solution for people that want to develop things quickly with no need to create DTOs, and do all the mapping stuff, but there are good tools and frameworks like &lt;A href="http://www.codeplex.com/AutoMapper" mce_href="http://www.codeplex.com/AutoMapper"&gt;AutoMapper&lt;/A&gt; to help with that. Or you can use ADO.NET Data Services today, which is also prepared to handle this kind of scenarios, all the transformations between layers are made by the framework itself, and still you get a very nice RESTful api. We still need some more features in ADO.NET DS to have a more complete framework, there is not good support today for injecting business logic, &lt;A href="http://weblogs.asp.net/cibrax/archive/2009/06/08/injecting-custom-logic-in-ado-net-data-services.aspx" mce_href="http://weblogs.asp.net/cibrax/archive/2009/06/08/injecting-custom-logic-in-ado-net-data-services.aspx"&gt;it can be done&lt;/A&gt; but it is complicated, it looks like the &lt;A href="http://johnpapa.net/silverlight/ado-net-data-services-v1-5-is-on-its-way/" mce_href="http://johnpapa.net/silverlight/ado-net-data-services-v1-5-is-on-its-way/"&gt;next version&lt;/A&gt; will address that aspect better.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7134097" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/cibrax/~4/8MXs2Te7UOk" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/cibrax/archive/tags/WCF/default.aspx">WCF</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/ADO.NET+Data+Services/default.aspx">ADO.NET Data Services</category><feedburner:origLink>http://weblogs.asp.net/cibrax/archive/2009/06/25/a-bad-idea-ef-entities-over-wcf.aspx</feedburner:origLink></item><item><title>Tellago esta contratando!!</title><link>http://feedproxy.google.com/~r/cibrax/~3/8glHdxbk2EI/tellago-esta-contratando.aspx</link><pubDate>Fri, 12 Jun 2009 20:38:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7119868</guid><dc:creator>cibrax</dc:creator><slash:comments>0</slash:comments><comments>http://weblogs.asp.net/cibrax/archive/2009/06/12/tellago-esta-contratando.aspx#comments</comments><description>&lt;P&gt;Como Jesus menciono en su &lt;A href="http://weblogs.asp.net/gsusx/archive/2009/06/12/we-are-still-hiring.aspx" mce_href="http://weblogs.asp.net/gsusx/archive/2009/06/12/we-are-still-hiring.aspx"&gt;post “We are still hiring..”&lt;/A&gt;, en Tellago estamos buscando gente que quieran unirse a nuestro equipo de desarrollo. En estos momentos tenemos algunas posiciones para Arquitectos y Desarrolladores con buenos conocimientos de Biztalk e idioma ingles. &lt;/P&gt;
&lt;P&gt;Si queres ser parte de una empresa joven, jugar con las ultimas tecnologias o involucrarte en proyectos con diversos equipos de trabajo en Microsoft, enviame tu curriculum a pablo [dot] cibraro [at] tellago [dot] com&lt;/P&gt;
&lt;P&gt;Las posiciones pueden ser tanto en Buenos Aires como en los Estados Unidos.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7119868" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/cibrax/~4/8glHdxbk2EI" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/cibrax/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/Tellago/default.aspx">Tellago</category><feedburner:origLink>http://weblogs.asp.net/cibrax/archive/2009/06/12/tellago-esta-contratando.aspx</feedburner:origLink></item><item><title>Injecting Custom Logic in ADO.NET Data Services</title><link>http://feedproxy.google.com/~r/cibrax/~3/cseZyoQPnsY/injecting-custom-logic-in-ado-net-data-services.aspx</link><pubDate>Mon, 08 Jun 2009 13:45:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7113383</guid><dc:creator>cibrax</dc:creator><slash:comments>4</slash:comments><comments>http://weblogs.asp.net/cibrax/archive/2009/06/08/injecting-custom-logic-in-ado-net-data-services.aspx#comments</comments><description>&lt;P&gt;ADO.NET Data services represent today one of the most powerful alternatives to build RESTful services in the .NET platform. This framework basically creates a RESTful API on top of any IQueryable data source. Most of the steps required to publish a set of resources through http and make them available for any client are automatically implemented.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Only Entity Framework data models are supported out of the box as read/write data sources, and any other IQueryable data source is considered by default read only. If you want to perform write operations on any other data source different from Entity Framework, you have to implement an additional interface IUpdatable as it is showed in this &lt;A href="http://blogs.msdn.com/astoriateam/archive/2008/04/10/iupdatable-ado-net-data-services-framework.aspx" mce_href="http://blogs.msdn.com/astoriateam/archive/2008/04/10/iupdatable-ado-net-data-services-framework.aspx"&gt;post&lt;/A&gt;. (Update: The new CTP 1.5 seems to have a new class to implement custom data providers, I have not had a chance to play with it yet)&lt;/P&gt;
&lt;P&gt;Usually, you will need to inject custom logic in the services for performing validations or implementing business rules. &lt;/P&gt;
&lt;P&gt;ADO.NET services comes with two built-in extensibility points for adding custom logic or code to a service, Service Operations and Interceptors.&lt;/P&gt;
&lt;P&gt;Service operations represent a simple way to define custom read/write views on top of the data source exposed by the service. It is intended to be used in scenarios where you need to create complex queries, or simple data aggregations that are not supported out of the box in framework. If you want to expose those queries directly as another resource in the service, you have to use service operations. &lt;/P&gt;
&lt;P&gt;The classic example given to show this feature in action is a query that returns all the customers in an specific city. That query would be translated in a service operation as follow,&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;public class MyService : DataService&amp;lt;MyDataSource&amp;gt; &lt;BR&gt;{ &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // This method is called only once to initialize service-wide policies. &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void InitializeService(IDataServiceConfiguration config) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; config.SetEntitySetAccessRule("Customers", EntitySetRights.AllRead); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; config.SetServiceOperationAccessRule("CustomersInCity", ServiceOperationRights.All); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [WebGet] &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public IQueryable&amp;lt;MyDataSource.Customers&amp;gt; CustomersInCity(string city) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return from c in this.CurrentDataSource.Customers &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where c.City == city &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select c; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp; &lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;}&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;As you can see in the code above, the service operation for this example is a simple method decorated with a WebGet attribute that returns an IQueryable implementation (With a pre-defined query in this example). The WebGet attribute specifies that&amp;nbsp; is a read-only view. As soon as we have that service running, you can navigate to that service operation with an URI like this, &lt;EM&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;A href="http://localhost/MyService.svc/CustomersInCity?city=BuenosAires" mce_href="http://localhost/MyService.svc/CustomersInCity?city=BuenosAires"&gt;http://localhost/MyService.svc/CustomersInCity?city=BuenosAires&lt;/A&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Since you are returning an IQueryable implementation, you are also free to define additional transformations on top of this base query, such as projections, filtering, or ordering among others. &lt;/P&gt;
&lt;P&gt;WebInvoke can be also used in case you want to implement a write operation. Since a service operation works as a black box, only the post verb is supported for WebInvoke, which means that you can not use other verbs like DELETE or PUT. Regarding this limitation, this is the answer you can find in the &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/thread/e546042f-c5f7-489d-b3e7-03b84a4f07ab" mce_href="http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/thread/e546042f-c5f7-489d-b3e7-03b84a4f07ab"&gt;forums&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;“We currently support only POST and GET verbs on the service operations (even in the recently released CTP). Is there a reason why you want to support&amp;nbsp; DELETE verb on service operation? The main reason for not supporting all the verbs is that from the client side, discovery becomes a issue - there is no way to know what verb to send for a service operation. Also service operations are black box to us - so we try and categorized them into side-effecting and non-side effecting ones. We recommend to use GET for non-side effection service opertions and use POST for side-effecting ones.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Please let us know if you think there is a good reason why DELETE verb should be supported.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Thanks &lt;BR&gt;Pratik”&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Another problem with service operations is that only scalar values are supported as arguments. Therefore, you can not pass entities or complex data types as arguments to a service operation.&lt;/P&gt;
&lt;P&gt;These limitations make hard to use service operations as a way to inject custom logic like validations or business rules into a data service.&lt;/P&gt;
&lt;P&gt;Fortunately, there is another extensibility point that becomes handy at the moment of implementing this kind of logic, the Interceptors. There are two kind of built-in interceptors, Query Interceptors, and Change Interceptors.&lt;/P&gt;
&lt;P&gt;A query interceptor represents a mechanism to change or transform the initial projection over an entity set. For example, if an user only allowed to see a subset of all the available data in an entity set, a query interceptor is the right place to filter the data for that user. &lt;/P&gt;
&lt;P&gt;&lt;EM&gt;[QueryInterceptor("Orders")] &lt;BR&gt;public Expression&amp;lt;Func&amp;lt;Orders, bool&amp;gt;&amp;gt; QueryOrders() { &lt;BR&gt;&amp;nbsp; return o =&amp;gt; o.Number &amp;gt; 100; &lt;BR&gt;}&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;The syntax of a query interceptor is quite simple, you basically returns an expression that describes a function (the Func), which takes an input value (an order being evaluated) and returns a bool value (whether the order passes the filter or not). Since an expression is used there rather than a piece of code, that expression can be passed directly to the query provider, which ultimately will generate the appropriate SQL in the database server. &lt;/P&gt;
&lt;P&gt;A change interceptor on the other hand, intercepts all the calls that generates changes in the data source exposed by the service. Therefore, this interceptor is the right mechanism for performing some validations before the data is changed in the data source. This is the place where we can enforce the business rules or validate the data for an specific entity set in our application (Entity set in this scenario also represents a collection of resources, where each resource is the entity itself).&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;[ChangeInterceptor("Orders")] &lt;BR&gt;public void OnChangeOrders(Order o, UpdateOperations operation) &lt;BR&gt;{ &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (operation == UpdateOperations.Add || operation == UpdateOperations.Change) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (o.Number &amp;gt; 100) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw new DataServiceException(400, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "You are not allowed to create or change an order with number greater than 100"); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;}&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;A change interceptor method receives two arguments, the entity that will be persisted, and an enumeration UpdateOperations that specifies the operation currently performed on the entity. Possible values for this enumeration are, Add, Change and Delete. &lt;/P&gt;
&lt;P&gt;This interceptor is not just to perform validations, you are still free to call additional services or change some data in the entity before it is persisted. However, this method call is synchronous, so you should be careful about executing long running code there.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7113383" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/cibrax/~4/cseZyoQPnsY" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/cibrax/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/REST/default.aspx">REST</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/ADO.NET+Data+Services/default.aspx">ADO.NET Data Services</category><feedburner:origLink>http://weblogs.asp.net/cibrax/archive/2009/06/08/injecting-custom-logic-in-ado-net-data-services.aspx</feedburner:origLink></item><item><title>What I like about OpenRasta</title><link>http://feedproxy.google.com/~r/cibrax/~3/MepLBqCaaao/what-i-like-about-openrasta.aspx</link><pubDate>Fri, 29 May 2009 19:10:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7102069</guid><dc:creator>cibrax</dc:creator><slash:comments>1</slash:comments><comments>http://weblogs.asp.net/cibrax/archive/2009/05/29/what-i-like-about-openrasta.aspx#comments</comments><description>&lt;P&gt;After having playing with the current bits of &lt;A href="http://serialseb.blogspot.com/2008/10/openrasta-status-update.html" mce_href="http://serialseb.blogspot.com/2008/10/openrasta-status-update.html"&gt;OpenRasta&lt;/A&gt; (OR) for a while, I&amp;nbsp; am now able to see great advantages in using this framework over other existing frameworks for building RESTful services such as WCF or the ASP.NET MVC.&lt;/P&gt;
&lt;P&gt;Let’s explore some of the good features that make OpenRasta an excellent alternative at the moment of developing RESTful services.&lt;/P&gt;
&lt;P&gt;1. Clean separation of resource representation from service implementation&lt;/P&gt;
&lt;P&gt;If we take a look at a service implementation in OR, the operations in a handler receive or return a resource, but they never specify the final representation of that resource. Resource representation is a pure responsibility of the encoders configured for service implementation (a handler in OR).&lt;/P&gt;
&lt;P&gt;In that way, we have a service implementation completely reusable for different resource representations. &lt;/P&gt;
&lt;DIV style="FONT-FAMILY: courier new; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;CustomerHandler&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;{&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; OperationResult Get(&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; customerId) &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; OperationResult.OK &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ResponseResource = &lt;SPAN style="COLOR: #a31515"&gt;"Customer with id "&lt;/SPAN&gt; + customerId&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;}&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Once we have the service implementation, we only need to configure the encoders for that service, which could be encoders for Xml, Json, Atom or any other representation. You are free to configure all the encoders you want for the same handler.&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: courier new; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;ConfigureServer(() =&amp;gt; ResourceSpace.Has.ResourcesOfType&amp;lt;Customer&amp;gt;()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .AtUri(&lt;SPAN style="COLOR: #a31515"&gt;"/customer/{customerId}"&lt;/SPAN&gt;)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .HandledBy&amp;lt;CustomerHandler&amp;gt;()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .AndTranscodedBy&amp;lt;OpenRasta.Codecs.JsonDataContractCodec&amp;gt;(&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;));&lt;/P&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;P&gt;This is a different story in WCF. First of all, the content type (Xml or Json) has to be specified as part of the operation definition. If we want to support different content types, we need to replicate the same operation only to change the content type. Although this point has been improved considerably in WCF 4.0, some service implementations are still absolutely tied to the resource representation. For example, an operation that returns syndications feeds. In WCF, we have to return a concrete implementation of System.ServiceModel.Syndication.SyndicationFeedFormatter. It is not a simple as return a collection of entities or resources and specify somewhere that we want to represent them as entries in a feed. &lt;/P&gt;
&lt;P&gt;This works much better in ADO.NET data services, where you can just return a resource or a collection of resources, and the framework itself will chose the best representation according to what the client initially sent in the “Accept” header. That representation could be Json or Atom, nothing changes in the service implementation (which is also automatically implemented). However, ADO.NET data services provide few extensibility points today for injecting custom code, and that is probably a good reason to move to OpenRasta. &lt;/P&gt;
&lt;P&gt;2. URI resolution &lt;/P&gt;
&lt;P&gt;In OpenRasta, the URI resolution to a handler is also part of the service configuration. This gives a great flexibility to have many URIs that resolve to the same resource instance. &lt;/P&gt;
&lt;P&gt;A typical example is a parent-child relationship, for instance, a customer/orders relationship. &lt;/P&gt;
&lt;P&gt;You might want to have different URIs to get access to the orders, &lt;/P&gt;
&lt;P&gt;Customer/1/Orders/1 =&amp;gt; Give me the order number 1 for the customer with ID 1&lt;/P&gt;
&lt;P&gt;Or you might want to access to the order directly&lt;/P&gt;
&lt;P&gt;Orders/1 =&amp;gt; Give me the order number 1&lt;/P&gt;
&lt;P&gt;In OR, you have a single handler implementation for orders (order is the resource in this case), and multiple URIs that resolve to an operation in that particular handler.&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: courier new; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;ConfigureServer(() =&amp;gt; &lt;SPAN style="COLOR: #2b91af"&gt;ResourceSpace&lt;/SPAN&gt;.Has.ResourcesOfType&amp;lt;Order&amp;gt;()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .AtUri(&lt;SPAN style="COLOR: #a31515"&gt;"/customer/{customerId}/Orders/{orderId}"&lt;/SPAN&gt;)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .AndAt(&lt;SPAN style="COLOR: #a31515"&gt;"/orders/{orderId}"&lt;/SPAN&gt;)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .HandledBy&amp;lt;OrderHandler&amp;gt;()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .AndTranscodedBy&amp;lt;OpenRasta.Codecs.&lt;SPAN style="COLOR: #2b91af"&gt;JsonDataContractCodec&lt;/SPAN&gt;&amp;gt;(&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;));&lt;/P&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;P&gt;This is a problem in WCF because the URI template is tied to the operation definition, if you want to have different URIs for the same resource, you basically have to copy/paste the same operation just to change the URIs.&lt;/P&gt;
&lt;DIV style="FONT-FAMILY: courier new; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;P style="MARGIN: 0px"&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;WebGet&lt;/SPAN&gt;(UriTemplate=&lt;SPAN style="COLOR: #a31515"&gt;"/Orders/{orderId}"&lt;/SPAN&gt;)]&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; Order GetOrderById(&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; orderId)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;{&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; //implementation&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;}&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;WebGet&lt;/SPAN&gt;(UriTemplate = &lt;SPAN style="COLOR: #a31515"&gt;"/Customers/{customerId}/Orders/{orderId}"&lt;/SPAN&gt;)]&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; Order GetCustomerOrder(&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; customerId, &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; orderId)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;{&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; //implementation&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;}&lt;/P&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;P&gt;So, you will have as many operations as URI and content types you want to support in the service.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7102069" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/cibrax/~4/MepLBqCaaao" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/cibrax/archive/tags/WCF/default.aspx">WCF</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/REST/default.aspx">REST</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/OpenRasta/default.aspx">OpenRasta</category><feedburner:origLink>http://weblogs.asp.net/cibrax/archive/2009/05/29/what-i-like-about-openrasta.aspx</feedburner:origLink></item><item><title>Webcast "OpenID, OAuth y Live ID. Cual es la diferencia ?</title><link>http://feedproxy.google.com/~r/cibrax/~3/KQg7So6BVlI/webcast-quot-openid-oauth-y-live-id-cual-es-la-diferencia.aspx</link><pubDate>Mon, 18 May 2009 19:52:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7092245</guid><dc:creator>cibrax</dc:creator><slash:comments>1</slash:comments><comments>http://weblogs.asp.net/cibrax/archive/2009/05/18/webcast-quot-openid-oauth-y-live-id-cual-es-la-diferencia.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;El proximo miercoles 20 de mayo a las&amp;nbsp;3 PM&amp;nbsp;(GMT-05:00 Colombia, Panama), voy a estar presentando un MSDN webcast acerca&amp;nbsp;de OpenID, OAuth y&amp;nbsp;Windows Live ID.&amp;nbsp;El evento va a ser transmitido en castellano para la comunidad de latinoamerica, y&amp;nbsp;se va a enfocar en las caracteristicas principales de estas soluciones/protocolos, como funcionan, y algunos escenarios en donde se pueden aplicar con exito.&lt;/P&gt;
&lt;P mce_keep="true"&gt;El link al evento es el siguiente, &lt;A href="http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032403625&amp;amp;Culture=es-AR" mce_href="http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032403625&amp;amp;Culture=es-AR"&gt;http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032403625&amp;amp;Culture=es-AR&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Los espero.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7092245" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/cibrax/~4/KQg7So6BVlI" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/cibrax/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/OAuth/default.aspx">OAuth</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/Webcast/default.aspx">Webcast</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/OpenID/default.aspx">OpenID</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/Live+ID/default.aspx">Live ID</category><feedburner:origLink>http://weblogs.asp.net/cibrax/archive/2009/05/18/webcast-quot-openid-oauth-y-live-id-cual-es-la-diferencia.aspx</feedburner:origLink></item><item><title>I am joining Tellago</title><link>http://feedproxy.google.com/~r/cibrax/~3/G61iA2Nc4mA/i-am-joining-tellago.aspx</link><pubDate>Thu, 14 May 2009 18:45:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7087247</guid><dc:creator>cibrax</dc:creator><slash:comments>1</slash:comments><comments>http://weblogs.asp.net/cibrax/archive/2009/05/14/i-am-joining-tellago.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;On May 18th, I will officially become part of &lt;A href="http://tellago.com/" mce_href="http://tellago.com/"&gt;Tellago&lt;/A&gt;&lt;U&gt;&lt;FONT color=#0066cc&gt;&lt;/FONT&gt;&lt;/U&gt;.&amp;nbsp; I will be joining a great team with people that I respect immensely like &lt;A href="http://weblogs.asp.net/gsusx" mce_href="http://weblogs.asp.net/gsusx"&gt;Jesus Rodriguez&lt;/A&gt;, &lt;A href="http://weblogs.asp.net/controlpanel/blogs/www.donxml.com" mce_href="www.donxml.com"&gt;DonXml&lt;/A&gt;, or &lt;A href="http://geekswithblogs.net/jklug/Default.aspx" mce_href="http://geekswithblogs.net/jklug/Default.aspx"&gt;Joe Klug&lt;/A&gt; to name a few. Thanks guys for give me this opportunity!!.&lt;/P&gt;
&lt;P mce_keep="true"&gt;I am leaving Clarius after almost two years of service. I got involved in a lot of interesting projects there, and what is more important, I had a chance to work with an excellent team of “all-stars” developers. I would like to thank Clarius and wish them the best in the future!&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7087247" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/cibrax/~4/G61iA2Nc4mA" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/cibrax/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/Personal/default.aspx">Personal</category><feedburner:origLink>http://weblogs.asp.net/cibrax/archive/2009/05/14/i-am-joining-tellago.aspx</feedburner:origLink></item><item><title>OpenRasta, an open source alternative for developing Restful services</title><link>http://feedproxy.google.com/~r/cibrax/~3/2Ds3Xjmr2t8/openrasta-an-open-source-alternative-for-developing-restful-services.aspx</link><pubDate>Wed, 22 Apr 2009 15:09:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7056476</guid><dc:creator>cibrax</dc:creator><slash:comments>1</slash:comments><comments>http://weblogs.asp.net/cibrax/archive/2009/04/22/openrasta-an-open-source-alternative-for-developing-restful-services.aspx#comments</comments><description>&lt;P&gt;&lt;A href="http://serialseb.blogspot.com/2008/12/openrasta-is-available.html" mce_href="http://serialseb.blogspot.com/2008/12/openrasta-is-available.html"&gt;OpenRasta&lt;/A&gt; (OR) is the name of a new open source framework for developing Restful applications (Web applications or services) created by &lt;A href="http://serialseb.blogspot.com/" mce_href="http://serialseb.blogspot.com"&gt;Sebastien Lambla&lt;/A&gt;. As the ASP.NET MVC, this framework is also an implementation of the MVC pattern, which focus mainly on a good separation of concerns, and provide different extensibility points where the developer can plugging custom code at the moment of developing applications.&lt;/P&gt;
&lt;P&gt;The framework is now on Beta 2 stage, Sebastien and other guys are currently working on improving the hosting infrastructure and public API. They are, of course, very open at this point to receive feedback or suggestions for new features, or improvements to existing ones. If you have some interest in participating of this project, you can start joining the &lt;A href="http://groups.google.com/group/openrasta/" mce_href="http://groups.google.com/group/openrasta/"&gt;mailing list&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;In order to understand how OR works under the hood, I will start by describing some basic concepts that a developer should know to implement an application from scratch with this framework.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Handlers&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;A “handler” is one of the main building blocks in OR. It represents the implementation of the service itself, and it is generally mapped to single resource through an URI. Therefore, any access to an URI will get resolved by OR to an specific handler. &lt;/P&gt;
&lt;P&gt;From an implementation point of view, a handler is simple class that expose methods for handling different http verbs. By convention, a method should be called as the Http verb that supports, for example, Get or Post. However, nothing prevent you from giving more friendly names to the methods (or handler operations), there is an special custom attribute “HttpOperationAttribute” that you can use to associate the method with an http verb.&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: courier new"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;CustomerHandler&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;{&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;Customer&lt;/SPAN&gt; Get(&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; customerId) &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;Customer&lt;/SPAN&gt; { FirstName = &lt;SPAN style="COLOR: #a31515"&gt;"foo"&lt;/SPAN&gt;, LastName = &lt;SPAN style="COLOR: #a31515"&gt;"bar"&lt;/SPAN&gt; }; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;OperationResult&lt;/SPAN&gt; Put(&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; id, &lt;SPAN style="COLOR: #2b91af"&gt;Customer&lt;/SPAN&gt; customer) &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;OperationResult&lt;/SPAN&gt;.&lt;SPAN style="COLOR: #2b91af"&gt;Modified&lt;/SPAN&gt; { ResponseResource = customer }; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;SPAN style="COLOR: #2b91af"&gt;HttpOperation&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;HttpMethod&lt;/SPAN&gt;.POST)]&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;OperationResult&lt;/SPAN&gt; MyFriendlyMethod(&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; id, &lt;SPAN style="COLOR: #2b91af"&gt;Customer&lt;/SPAN&gt; customer)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;OperationResult&lt;/SPAN&gt;.&lt;SPAN style="COLOR: #2b91af"&gt;Modified&lt;/SPAN&gt; { ResponseResource = customer }; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;}&lt;/P&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;P&gt;If you want to have a better control of the Http status code, as it is shown in the code above, you can also return an instance of OperationResult.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Codecs&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;As you can see, the handlers have not been wired to any content type at this point. Serializing/Deserializing a resource instance into an specific representation is responsibility of the codecs. Some codecs are provided out of the box in OR, for example, Json, Xml, Html or Form-Url-Encoded data.&lt;/P&gt;
&lt;P&gt;A codec generally implement two interfaces, IMediaTypeReader (for deserializing content) and IMediaTypeWriter(for serializing). The following code shows the implementation of the Json codec,&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: courier new"&gt;
&lt;P style="MARGIN: 0px"&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;MediaType&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"application/json;q=0.5"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"json"&lt;/SPAN&gt;)]&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;JsonDataContractCodec&lt;/SPAN&gt; : &lt;SPAN style="COLOR: #2b91af"&gt;IMediaTypeReader&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #2b91af"&gt;IMediaTypeWriter&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;{&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; Configuration { &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;; &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt;; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; ReadFrom(&lt;SPAN style="COLOR: #2b91af"&gt;IHttpEntity&lt;/SPAN&gt; request, System.&lt;SPAN style="COLOR: #2b91af"&gt;Type&lt;/SPAN&gt; destinationType, &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; paramName)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;DataContractJsonSerializer&lt;/SPAN&gt; serializer = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;DataContractJsonSerializer&lt;/SPAN&gt;(destinationType);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; serializer.ReadObject(request.Stream);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; WriteTo(&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; entity, &lt;SPAN style="COLOR: #2b91af"&gt;IHttpEntity&lt;/SPAN&gt; response, &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;[] paramneters)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (entity == &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;DataContractJsonSerializer&lt;/SPAN&gt; serializer = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;DataContractJsonSerializer&lt;/SPAN&gt;(entity.GetType());&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; serializer.WriteObject(response.Stream, entity);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;}&lt;/P&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;P&gt;&lt;STRONG&gt;Putting Handlers and Codecs together&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;By means of a fluent configuration, we can later wire up an URI with the corresponding handler and one or more codecs according to the content-types that the service should support.&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: courier new"&gt;
&lt;P style="MARGIN: 0px"&gt;ConfigureServer(() =&amp;gt; &lt;SPAN style="COLOR: #2b91af"&gt;ResourceSpace&lt;/SPAN&gt;.Has.ResourcesOfType&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;Customer&lt;/SPAN&gt;&amp;gt;()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .AtUri(&lt;SPAN style="COLOR: #a31515"&gt;"/customer/{id}"&lt;/SPAN&gt;)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .HandledBy&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;CustomerHandler&lt;/SPAN&gt;&amp;gt;()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .AndTranscodedBy&amp;lt;OpenRasta.Codecs.&lt;SPAN style="COLOR: #2b91af"&gt;JsonDataContractCodec&lt;/SPAN&gt;&amp;gt;()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .AndBy&amp;lt;OpenRasta.Codecs.&lt;SPAN style="COLOR: #2b91af"&gt;XmlSerializerCodec&lt;/SPAN&gt;&amp;gt;());&lt;/P&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;P&gt;This is one of the big differences with the ASP.NET MVC or the Web Programming Model in WCF.&lt;/P&gt;
&lt;P&gt;In the MVC, the supported content types are inherently tied to the ActionResult returned by the controller action. Therefore, the action implementation must be modified in order to support new content types.&amp;nbsp; Or a more specialized implementation of an ActionResult is required, which has to be smart enough to accommodate these changes. &lt;/P&gt;
&lt;P&gt;Same thing happens with WCF, you have to either decorate the service operation with the supported content-type (Only Json or Pox supported today) or return a Message/Stream instance from the operation and write the resource representation yourself in the operation implementation. As I said, only Json/Pox are supported today, and adding new content types is something complicated to do. You basically need to write a custom IDispatchMessageFormatter extension, and a custom WebServiceHost to replace the formatter provided out of the box. (This is the approach taken in the WCF REST Starter kit for supporting form-url-encoded data).&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Pipeline Contributors&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Let’s go back to OpenRasta for a moment, “Handlers” and “Codecs” are not the only supported extensibility points in this framework. All the processing of incoming/outgoing messages is performed in a pipeline that contains contributors or filters. A pipeline contributor perform simple tasks such as initializing the security context, routing the messages or processing exceptions to name a few. You can write your own contributors, or customize the pipeline to support different configurations or scenarios&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;More information about OpenRasta&lt;/STRONG&gt;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;You can find more information about this framework in the &lt;A href="http://serialseb.blogspot.com/" mce_href="http://serialseb.blogspot.com"&gt;Sebastien’s blog&lt;/A&gt;. The current project status is also available &lt;A href="http://serialseb.blogspot.com/2008/10/openrasta-status-update.html" mce_href="http://serialseb.blogspot.com/2008/10/openrasta-status-update.html"&gt;here&lt;/A&gt;. &lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7056476" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/cibrax/~4/2Ds3Xjmr2t8" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/cibrax/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/REST/default.aspx">REST</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/OpenRasta/default.aspx">OpenRasta</category><feedburner:origLink>http://weblogs.asp.net/cibrax/archive/2009/04/22/openrasta-an-open-source-alternative-for-developing-restful-services.aspx</feedburner:origLink></item><item><title>Developing RESTful services with JSON and POX support in the ASP.NET MVC</title><link>http://feedproxy.google.com/~r/cibrax/~3/HHIQmPLKxlM/developing-restful-services-with-json-and-pox-support-in-the-asp-net-mvc.aspx</link><pubDate>Fri, 17 Apr 2009 21:20:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7049125</guid><dc:creator>cibrax</dc:creator><slash:comments>2</slash:comments><comments>http://weblogs.asp.net/cibrax/archive/2009/04/17/developing-restful-services-with-json-and-pox-support-in-the-asp-net-mvc.aspx#comments</comments><description>&lt;P&gt;Many of the features available out of the box today in the ASP.NET MVC framework are only intended to develop web applications using REST principles. There is not support for accepting incoming messages encoded as JSON or plain old XML (POX), or even support for returning POX from a controller action. Only form-urlencoded data is accepted by default for incoming messages, and JSON/HTML (with support of the view engines) for outgoing messages in controller actions. &lt;/P&gt;
&lt;P&gt;However, thanks to the different extensibility points that the MVC provides for hooking up custom code, supporting different scenarios for RESTful services tend to be something really easy to implement.&lt;/P&gt;
&lt;P&gt;In this framework, we basically have two extensibility points that deserve some attention, Action Filters and Action Results. &lt;/P&gt;
&lt;P&gt;Action filters intercept messages before they are dispatched to the controller action (or operation), and just after the operation returns a result. They are basically equivalent to the Dispatch Message Interceptors in WCF, or the new Message Interceptors in the WCF REST Starter kit (although they work more at a deeper level in the WCF processing pipeline).&lt;/P&gt;
&lt;P&gt;Action results know how to serialize and write an object (the controller action result) into the response stream. Since they also have access to the Response object, additional work can be done there to manipulate some response settings or add output headers.&lt;/P&gt;
&lt;P&gt;The framework also support Model Binders, which basically knows how to create an object representing the model expected by the controller action from some scalar values. Those scalar values are parsed from the incoming message (encoded as form-urlencoded), and then passed to the binder. However, they do not seem to add any value for implementing RESTful services with support for JSON or XML.&lt;/P&gt;
&lt;P&gt;Omar Al Zabir has already written &lt;A href="http://weblogs.asp.net/omarzabir/archive/2008/10/03/create-rest-api-using-asp-net-mvc-that-speaks-both-json-and-plain-xml.aspx" mce_href="http://weblogs.asp.net/omarzabir/archive/2008/10/03/create-rest-api-using-asp-net-mvc-that-speaks-both-json-and-plain-xml.aspx"&gt;an nice post&lt;/A&gt; on how to implement RESTful services with the ASP.NET MVC that speak JSON and XML using action filters and action results.&lt;/P&gt;
&lt;P&gt;ATOM and other syndication formats can also be handled as XML. For this, the Web Programming Model in WCF comes with a couple of classes, Rss20FeedFormatter and Atom10FeedFormator, which are Data Contracts and also IXmlSerializable classes. Therefore, if your operation returns an instance of any of these classes, the filters created by Omar would address this scenario as well. Regarding Conditional get support, you will have to implement it in the action itself or a custom filter. (You will have to do the same thing if you decide to go with the WCF Web Programming Model). &lt;/P&gt;
&lt;P&gt;Caching is another feature that you might want to use at the moment of developing RESTful services. Fortunately, the MVC also comes with an special action filter “OutputCache” that was built on top the ASP.NET cache, so it provides the same caching capabilities that you may use for normal ASP.NET pages.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7049125" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/cibrax/~4/HHIQmPLKxlM" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/cibrax/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/MVC/default.aspx">MVC</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/REST/default.aspx">REST</category><feedburner:origLink>http://weblogs.asp.net/cibrax/archive/2009/04/17/developing-restful-services-with-json-and-pox-support-in-the-asp-net-mvc.aspx</feedburner:origLink></item><item><title>Webcast para el programa Microsoft Student Partner “Building Web Services”</title><link>http://feedproxy.google.com/~r/cibrax/~3/6AiP6cZQZY0/webcast-para-el-programa-microsoft-student-partner-building-web-services.aspx</link><pubDate>Fri, 17 Apr 2009 20:33:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7049106</guid><dc:creator>cibrax</dc:creator><slash:comments>5</slash:comments><comments>http://weblogs.asp.net/cibrax/archive/2009/04/17/webcast-para-el-programa-microsoft-student-partner-building-web-services.aspx#comments</comments><description>&lt;P&gt;&lt;A href="http://www.kioskotobys.com.ar/WebServices.ppt" mce_href="http://www.kioskotobys.com.ar/WebServices.ppt"&gt;Aqui&lt;/A&gt; pueden encontrar el material de la prestacion que di en el dia de hoy acerca de construccion de web services con ASP.NET y WCF en Visual Studio 2008.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7049106" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/cibrax/~4/6AiP6cZQZY0" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/cibrax/archive/tags/Web+Services/default.aspx">Web Services</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/.NET/default.aspx">.NET</category><feedburner:origLink>http://weblogs.asp.net/cibrax/archive/2009/04/17/webcast-para-el-programa-microsoft-student-partner-building-web-services.aspx</feedburner:origLink></item><item><title>Mutual Certificate Authentication for WCF REST services</title><link>http://feedproxy.google.com/~r/cibrax/~3/NWkZ4wUST8Q/mutual-certificate-authentication-for-wcf-rest-services.aspx</link><pubDate>Thu, 16 Apr 2009 16:28:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7048235</guid><dc:creator>cibrax</dc:creator><slash:comments>7</slash:comments><comments>http://weblogs.asp.net/cibrax/archive/2009/04/16/mutual-certificate-authentication-for-wcf-rest-services.aspx#comments</comments><description>&lt;P&gt;When Mutual Certificate Authentication is configured for REST services, both, the client and the service perform identity verification or authentication through X509 certificates. &lt;/P&gt;
&lt;P&gt;The client authenticates the service during the initial SSL handshake, when the server sends the client a certificate to authenticate itself. More information about this process can be &lt;A href="http://support.microsoft.com/default.aspx/kb/257587" mce_href="http://support.microsoft.com/default.aspx/kb/257587"&gt;found here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;The service on the other hand, performs similar validations on the certificate attached by the client consumer to the request message.&lt;/P&gt;
&lt;P&gt;Some specific configuration settings are required in WCF to use this authentication scenario with REST services. The service must be configured with transport security (SSL), “certificate” as client credential type. &lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;webHttpBinding&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&amp;nbsp; &amp;lt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;binding&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#ff0000 size=2&gt;name&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;mutual&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;security&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#ff0000 size=2&gt;mode&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Transport&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;transport&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#ff0000 size=2&gt;clientCredentialType&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Certificate&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;/&amp;gt;&lt;/FONT&gt; &lt;/P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;security&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp; &amp;lt;/&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;binding&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&amp;lt;/&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;webHttpBinding&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;/P&gt;
&lt;P&gt;For example, the complete configuration for a REST service that provides ATOM feeds would be the following,&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;system.serviceModel&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&amp;nbsp; &amp;lt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;serviceHostingEnvironment&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#ff0000 size=2&gt;aspNetCompatibilityEnabled&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;true&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;/&amp;gt;&lt;/FONT&gt; &lt;/P&gt;&amp;nbsp; &amp;lt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;services&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;service&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#ff0000 size=2&gt;name&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;MutualAuthenticationRest.FeedService&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;endpoint&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#ff0000 size=2&gt;address&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;""&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#ff0000 size=2&gt;contract&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;MutualAuthenticationRest.IFeedService&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#ff0000 size=2&gt;binding&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;webHttpBinding&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#ff0000 size=2&gt;bindingConfiguration&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;mutual&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#ff0000 size=2&gt;behaviorConfiguration&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;mutual&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&amp;lt;/&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;endpoint&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;service&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/P&gt;&amp;nbsp; &amp;lt;/&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;services&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&amp;nbsp; &amp;lt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;bindings&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;webHttpBinding&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;binding&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#ff0000 size=2&gt;name&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;mutual&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;security&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#ff0000 size=2&gt;mode&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Transport&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;transport&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#ff0000 size=2&gt;clientCredentialType&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Certificate&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;/&amp;gt;&lt;/FONT&gt; &lt;/P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;security&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;binding&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;webHttpBinding&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;bindings&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;behaviors&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;endpointBehaviors&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;behavior&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#ff0000 size=2&gt;name&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;mutual&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;webHttp&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;/&amp;gt;&lt;/FONT&gt; &lt;/P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;behavior&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;endpointBehaviors&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/P&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;behaviors&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&amp;lt;/&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;system.serviceModel&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;/P&gt;
&lt;P&gt;The virtual directory used for hosting the service in IIS must also be configured with the same security settings.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.kioskotobys.com.ar/MutualCertificateAuthenticationforWCFRES_B433/MutualCertificate.jpg" mce_href="http://www.kioskotobys.com.ar/MutualCertificateAuthenticationforWCFRES_B433/MutualCertificate.jpg"&gt;&lt;IMG title=MutualCertificate style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; DISPLAY: inline; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=96 alt=MutualCertificate src="http://www.kioskotobys.com.ar/MutualCertificateAuthenticationforWCFRES_B433/MutualCertificate_thumb.jpg" width=244 border=0 mce_src="http://www.kioskotobys.com.ar/MutualCertificateAuthenticationforWCFRES_B433/MutualCertificate_thumb.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;The client application only need to attach the certificate at the moment of consuming the service. This can be easily done with the new HttpClient class shipped as part of the WCF REST Starter kit,&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: courier new"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;Program&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;{&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; Main(&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;[] args)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;X509Certificate2&lt;/SPAN&gt; certificate = &lt;SPAN style="COLOR: #2b91af"&gt;CertificateUtil&lt;/SPAN&gt;.GetCertificate(&lt;SPAN style="COLOR: #2b91af"&gt;StoreName&lt;/SPAN&gt;.My, &lt;SPAN style="COLOR: #2b91af"&gt;StoreLocation&lt;/SPAN&gt;.LocalMachine, &lt;SPAN style="COLOR: #a31515"&gt;"CN=clientCert"&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;HttpClient&lt;/SPAN&gt; client = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;HttpClient&lt;/SPAN&gt;();&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; client.TransportSettings.ClientCertificates.Add(certificate); //Cert attached to the request&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; content = client.Get(&lt;SPAN style="COLOR: #a31515"&gt;"https://localhost/MutualAuthentication/Service.svc?numItems=10"&lt;/SPAN&gt;).Content.ReadAsString();&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(content);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;}&lt;/P&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;P&gt;CertificateUtil is an helper class that looks for an specific X509 certificate in the windows certificate store. In addition, if you are using test certificates, you might want to disable the service authentication on the client side, that can be done with a callback attached to the static class “ServicePointManager”. &lt;/P&gt;
&lt;P&gt;For instance,&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: courier new"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;PermissiveCertificatePolicy&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;{&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; Enable()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;ServicePointManager&lt;/SPAN&gt;.ServerCertificateValidationCallback +=&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;RemoteCertificateValidationCallback&lt;/SPAN&gt;(RemoteCertValidate);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; RemoteCertValidate(&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; sender, &lt;SPAN style="COLOR: #2b91af"&gt;X509Certificate&lt;/SPAN&gt; cert, &lt;SPAN style="COLOR: #2b91af"&gt;X509Chain&lt;/SPAN&gt; chain, System.Net.Security.&lt;SPAN style="COLOR: #2b91af"&gt;SslPolicyErrors&lt;/SPAN&gt; error)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;true&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;}&lt;/P&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;P&gt;The method PermissiveCertificatePolicy.Enable should be called before consuming the service.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7048235" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/cibrax/~4/NWkZ4wUST8Q" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/cibrax/archive/tags/WCF/default.aspx">WCF</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/REST/default.aspx">REST</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/REST+Starter+Kit/default.aspx">REST Starter Kit</category><feedburner:origLink>http://weblogs.asp.net/cibrax/archive/2009/04/16/mutual-certificate-authentication-for-wcf-rest-services.aspx</feedburner:origLink></item><item><title>Sharing the security context between ASP.NET and WCF REST Services</title><link>http://feedproxy.google.com/~r/cibrax/~3/EfTuCZjGy3A/sharing-the-security-context-between-asp-net-and-wcf-rest-services.aspx</link><pubDate>Wed, 08 Apr 2009 14:24:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7035750</guid><dc:creator>cibrax</dc:creator><slash:comments>0</slash:comments><comments>http://weblogs.asp.net/cibrax/archive/2009/04/08/sharing-the-security-context-between-asp-net-and-wcf-rest-services.aspx#comments</comments><description>&lt;P&gt;It is very common for WCF services that work as Ajax callbacks and ASP.NET pages that live in the same web application to share a common security context for the authenticated user. However, in order to make this happens, the &lt;A href="http://blogs.msdn.com/wenlong/archive/2006/01/23/516041.aspx" mce_href="http://blogs.msdn.com/wenlong/archive/2006/01/23/516041.aspx"&gt;ASP.NET compatibility mode&lt;/A&gt; must be enabled for the WCF service. When that setting is enabled, WCF basically includes the service call within the ASP.NET pipeline, all the ASP.NET modules configured for the application are executed, and as result, the HttpContext get initialized for that service as it was a normal page.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Optionally, an IAuthorizationPolicy can be used to inject the HttpContext.User into the WCF security context, and completely decouple in that way, the service implementation from the Http security context. &lt;/P&gt;
&lt;P&gt;For example, we can have a web application configured with Forms Authentication or the new FederationModule in geneva framework for authenticating users with passive federation, and share that security context with the services or ajax callbacks that the web pages consume.&lt;/P&gt;
&lt;P&gt;For this scenario, the WCF REST Starter kit already includes an IAuthorizationPolicy implementation for initialization the WCF security context with the authenticated user in the web application. That authorization policy is automatically injected in the service execution pipeline by the WebServiceHost2 host shipped also within the kit. If you are using that WCF host, you do not have to do anything extra other than enabling the ASP.NET compatibility mode for the services.&lt;/P&gt;
&lt;P&gt;Configuring the ASP.NET compatibility mode requires two steps.&lt;/P&gt;
&lt;P&gt;1. Add a configuration settings in the configuration file,&lt;/P&gt;&lt;FONT size=2&gt;&lt;FONT size=2&gt;&lt;FONT color=#0000ff&gt;&amp;lt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#0000ff size=2&gt;system.serviceModel&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#0000ff&gt;&lt;FONT size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;FONT color=#0000ff&gt;&amp;lt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT size=2&gt;&lt;FONT size=2&gt;serviceHostingEnvironment&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT size=2&gt;aspNetCompatibilityEnabled&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT size=2&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT size=2&gt;true&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#0000ff&gt;&lt;FONT size=2&gt; /&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/P&gt;&lt;FONT color=#0000ff&gt;&amp;lt;/&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#0000ff size=2&gt;system.serviceModel&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#0000ff&gt;&lt;FONT size=2&gt;&amp;gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P mce_keep="true"&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;2. Add support for this mode in the service implementation. This is done through an special attribute “AspNetCompatibilityRequirements” added to the class definition&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: courier new"&gt;
&lt;P style="MARGIN: 0px"&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;AspNetCompatibilityRequirements&lt;/SPAN&gt;(RequirementsMode = &lt;SPAN style="COLOR: #2b91af"&gt;AspNetCompatibilityRequirementsMode&lt;/SPAN&gt;.Required)]&amp;nbsp; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;ServiceContract&lt;/SPAN&gt;]&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ClaimsService&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;!--EndFragment--&gt;Once you have done that, the user principal will become available to the service through the WCF security context or the Thread.CurrentPrincipal property.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7035750" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/cibrax/~4/EfTuCZjGy3A" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/cibrax/archive/tags/WCF/default.aspx">WCF</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/REST/default.aspx">REST</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/REST+Starter+Kit/default.aspx">REST Starter Kit</category><feedburner:origLink>http://weblogs.asp.net/cibrax/archive/2009/04/08/sharing-the-security-context-between-asp-net-and-wcf-rest-services.aspx</feedburner:origLink></item><item><title>MVP again 2009!!</title><link>http://feedproxy.google.com/~r/cibrax/~3/ra_vAZBsgtg/mvp-again-2009.aspx</link><pubDate>Wed, 01 Apr 2009 14:33:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7020346</guid><dc:creator>cibrax</dc:creator><slash:comments>3</slash:comments><comments>http://weblogs.asp.net/cibrax/archive/2009/04/01/mvp-again-2009.aspx#comments</comments><description>&lt;P&gt;I just got great news!&amp;nbsp; MVP in Connected Systems for another year. &lt;/P&gt;
&lt;P&gt;I want to thank Ed Hickey, my MVP lead &lt;A href="http://blogs.msdn.com/mvplead" mce_href="http://blogs.msdn.com/mvplead"&gt;&lt;FONT color=#0066cc&gt;Fernando Garcia Loera&lt;/FONT&gt;&lt;/A&gt;, and the rest of people involved in the evaluation process for once again considering my efforts in the community worthy of recognition. &lt;/P&gt;
&lt;P&gt;Thanks again Microsoft!!! &lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7020346" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/cibrax/~4/ra_vAZBsgtg" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/cibrax/archive/tags/Personal/default.aspx">Personal</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/MVP/default.aspx">MVP</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/NET/default.aspx">NET</category><feedburner:origLink>http://weblogs.asp.net/cibrax/archive/2009/04/01/mvp-again-2009.aspx</feedburner:origLink></item><item><title>Support for Form-UrlEncoded data in WCF Rest services</title><link>http://feedproxy.google.com/~r/cibrax/~3/U1WdEAL7TcE/support-for-form-urlencoded-data-in-wcf-rest-services.aspx</link><pubDate>Wed, 01 Apr 2009 14:16:13 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7020302</guid><dc:creator>cibrax</dc:creator><slash:comments>1</slash:comments><comments>http://weblogs.asp.net/cibrax/archive/2009/04/01/support-for-form-urlencoded-data-in-wcf-rest-services.aspx#comments</comments><description>&lt;p&gt;Some people have been asking around in the MSDN forums or &lt;a href="http://stackoverflow.com/questions/604463/best-way-to-support-application-x-www-form-urlencoded-post-data-with-wcf"&gt;stackoverflow&lt;/a&gt; about a possible way to pass form-urlencoded data to an existing WCF REST service. Although this is not a core feature in WCF from my point view, there is still some support for addressing this scenario in the REST Starter kit. &lt;/p&gt;  &lt;p&gt;This feature takes the form of a new message formatter, FormsPostDispatchMessageFormatter, which is automatically injected to any existing service hosted within the new WebServiceHost2 host (shipped as part of the kit)&lt;/p&gt;  &lt;p&gt;This formatter basically intercepts all messages, and handle those that contains “application/x-www-form-urlencoded” as content type in the request header. The rest of the messages are handled by the existing formatters as usual.&lt;/p&gt;  &lt;p&gt;The service operation must expose a NameValueCollection argument in the method signature in order to receive the data. This collection will contain the key/value pairs that were parsed from request body.&lt;/p&gt;  &lt;p&gt;For example,&lt;/p&gt;  &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt;&lt;span style="color: blue"&gt;     &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt;       &lt;p style="margin: 0px"&gt;[&lt;span style="color: #2b91af"&gt;WebInvoke&lt;/span&gt;(UriTemplate = &lt;span style="color: #a31515"&gt;&amp;quot;SetData&amp;quot;&lt;/span&gt;)]&lt;/p&gt;        &lt;p style="margin: 0px"&gt;[&lt;span style="color: #2b91af"&gt;OperationContract&lt;/span&gt;]&lt;/p&gt;     &lt;/div&gt; &lt;!--EndFragment--&gt;&lt;/span&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; SetData(&lt;span style="color: #2b91af"&gt;NameValueCollection&lt;/span&gt; formsData)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;this&lt;/span&gt;.value = &lt;span style="color: #2b91af"&gt;Int32&lt;/span&gt;.Parse(formsData[&lt;span style="color: #a31515"&gt;&amp;quot;counter&amp;quot;&lt;/span&gt;]);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;&lt;!--EndFragment--&gt;“Counter”&amp;#160; in this case represents a field in the form that was posted to the service.&lt;/p&gt; &lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;     &lt;p&gt;&amp;lt;&lt;/p&gt;   &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;FORM&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;&lt;font color="#ff0000" size="2"&gt;action&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;=&amp;quot;service.svc/SetData&amp;quot;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;&lt;font color="#ff0000" size="2"&gt;method&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;=&amp;quot;post&amp;quot;&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;   &lt;p&gt;Input Counter value and hit enter:&lt;/p&gt;    &lt;p&gt;&lt;/p&gt;   &lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;INPUT&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;&lt;font color="#ff0000" size="2"&gt;type&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;=&amp;quot;text&amp;quot;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;&lt;font color="#ff0000" size="2"&gt;name&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;=&amp;quot;Counter&amp;quot;&amp;gt;&lt;/font&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;FORM&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7020302" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/cibrax/~4/U1WdEAL7TcE" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/cibrax/archive/tags/WCF/default.aspx">WCF</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/REST/default.aspx">REST</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/REST+Starter+Kit/default.aspx">REST Starter Kit</category><feedburner:origLink>http://weblogs.asp.net/cibrax/archive/2009/04/01/support-for-form-urlencoded-data-in-wcf-rest-services.aspx</feedburner:origLink></item><item><title>Streaming large content from a WCF RESTFul service</title><link>http://feedproxy.google.com/~r/cibrax/~3/yiiZEJP9LLA/streaming-large-content-from-a-wcf-restful-service.aspx</link><pubDate>Fri, 27 Mar 2009 17:23:23 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7007919</guid><dc:creator>cibrax</dc:creator><slash:comments>3</slash:comments><comments>http://weblogs.asp.net/cibrax/archive/2009/03/27/streaming-large-content-from-a-wcf-restful-service.aspx#comments</comments><description>&lt;p&gt;Streaming large content such as media content, images or files is a common scenario for RESTful services. If a scenario like this is not well addressed or implemented on the service side, there is a high risk of consuming server resources like memory or CPU in a matter of seconds. This usually happens when the complete content is loaded in memory before it is transferred to the service consumer.&lt;/p&gt;  &lt;p&gt;The WCF REST Starter kit introduced a new mechanism for addressing this scenario, an “AdapterStream” utility class, which basically pushes small pieces of content (and thus, only small memory buffers are used) to the client application as it becomes necessary.&lt;/p&gt;  &lt;p&gt;The kit also comes with an example “PushStyleStreaming” that shows this class in action&lt;/p&gt;  &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;Stream&lt;/span&gt; GetImage(&lt;span style="color: blue"&gt;string&lt;/span&gt; text)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: blue"&gt;string&lt;/span&gt;.IsNullOrEmpty(text))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;throw&lt;/span&gt; &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;WebProtocolException&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;HttpStatusCode&lt;/span&gt;.BadRequest, &lt;span style="color: #a31515"&gt;&amp;quot;text must be specified&amp;quot;&lt;/span&gt;, &lt;span style="color: blue"&gt;null&lt;/span&gt;);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;Bitmap&lt;/span&gt; theBitmap = GenerateImage(text);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;WebOperationContext&lt;/span&gt;.Current.OutgoingResponse.ContentType = &lt;span style="color: #a31515"&gt;&amp;quot;image/jpeg&amp;quot;&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;AdapterStream&lt;/span&gt;((stream) =&amp;gt; theBitmap.Save(stream, &lt;span style="color: #2b91af"&gt;ImageFormat&lt;/span&gt;.Jpeg));&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt; &lt;!--EndFragment--&gt;  &lt;p&gt;In the code above, the AdapterStream is used to transfer an image to a service consumer. As you can also notice in that code, that class receives a lambda&amp;#160; expression or Action&amp;lt;T&amp;gt; delegate in the constructor. That provides some flexibility at the moment of generating the final stream that will be sent to the client application.&lt;/p&gt;  &lt;p&gt;Another example that uses an TextWriter for generating text content,&lt;/p&gt;  &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160; new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;AdapterStream&lt;/span&gt;((writer) =&amp;gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; writer.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;You said: &amp;quot;&lt;/span&gt;);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; writer.WriteLine(text);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; writer.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;Didn't you?&amp;quot;&lt;/span&gt;);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; writer.Flush();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; }, &lt;span style="color: #2b91af"&gt;Encoding&lt;/span&gt;.UTF8);&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;&lt;!--EndFragment--&gt;In addition to this feature, you might also want to have a better control of service usage by restricting the &lt;a href="http://kennyw.com/indigo/150"&gt;throttling settings&lt;/a&gt;. This is a good thing about REST services implemented with the WCF stack. Other implementations such as the ASP.NET MVC rely on the ASP.NET for handling this aspect, where these settings are applied only at application domain level (For all services running in the same app).&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7007919" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/cibrax/~4/yiiZEJP9LLA" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/cibrax/archive/tags/WCF/default.aspx">WCF</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/REST/default.aspx">REST</category><category domain="http://weblogs.asp.net/cibrax/archive/tags/REST+Starter+Kit/default.aspx">REST Starter Kit</category><feedburner:origLink>http://weblogs.asp.net/cibrax/archive/2009/03/27/streaming-large-content-from-a-wcf-restful-service.aspx</feedburner:origLink></item></channel></rss>
