<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" 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/"><channel><title>WCF: 4 Tenets of Service Oriented Data Validation</title><link>http://blogs.msdn.com/b/rjacobs/archive/2011/01/15/wcf-4-tenets-of-service-oriented-data-validation.aspx</link><description>Remember the 4 tenets of SOA?&amp;#160; One of them is that Boundaries are explicit.&amp;#160; When somebody sends data to your service it is just like when you cross an international border into another country.&amp;#160; Just a couple of hours drive north of us</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: WCF: 4 Tenets of Service Oriented Data Validation</title><link>http://blogs.msdn.com/b/rjacobs/archive/2011/01/15/wcf-4-tenets-of-service-oriented-data-validation.aspx#10118348</link><pubDate>Thu, 20 Jan 2011 20:37:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10118348</guid><dc:creator>Ron Jacobs</dc:creator><description>&lt;p&gt;Document Processor - yes I&amp;#39;m quite familiar with it... I came up with it.&lt;/p&gt;
&lt;p&gt;As I said in the video, some people are not comfortable with the tight coupling that comes from sharing validation logic between client and server. &amp;nbsp;That is why I said services &amp;quot;may&amp;quot; share validation rules. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;I say this as a compromise because over the years I&amp;#39;ve become less dogmatic about SOA and more practical. &amp;nbsp;I find that many people are creating services that are consumed by other parts of their application. &amp;nbsp;And in such cases they are often already sharing code between sender and receiver so if you are comfortable with it... share the validation as well. &amp;nbsp;Just recognize that sharing the validation logic does create a tighter coupling.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10118348" width="1" height="1"&gt;</description></item><item><title>re: WCF: 4 Tenets of Service Oriented Data Validation</title><link>http://blogs.msdn.com/b/rjacobs/archive/2011/01/15/wcf-4-tenets-of-service-oriented-data-validation.aspx#10118346</link><pubDate>Thu, 20 Jan 2011 20:31:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10118346</guid><dc:creator>Martin</dc:creator><description>&lt;p&gt;Hi Ron and Rory,&lt;/p&gt;
&lt;p&gt;I really like the article and Rory&amp;#39;s additional remarks as you sum best practices regarding validation and exception handling which I use and propagate since years (DTO, Exception Shielding, Fault Contracts, Security Facades). I have the impression, that the impact of missing validation and insufficient exception handling on the maintainability of software systems is greatly underestimated.&lt;/p&gt;
&lt;p&gt;Just some short remark to Ron&amp;#39;s idea mentioned above: We have used this approach in the past to share simple validation logic between client and the server side. &lt;/p&gt;
&lt;p&gt;But how does this approach fit to the tenet &amp;quot;Services share schema and contract, not class&amp;quot; and the pattern &amp;quot;Document Processor&amp;quot; (see &lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/ms954638.aspx"&gt;msdn.microsoft.com/.../ms954638.aspx&lt;/a&gt;)? Following the &amp;quot;Document Processor&amp;quot; pattern, I would suggest to integrate the simple validation rules into the XSchema and share these rules as part of the contract.&lt;/p&gt;
&lt;p&gt;Do you agree?&lt;/p&gt;
&lt;p&gt;Best Regards,&lt;/p&gt;
&lt;p&gt;Martin&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10118346" width="1" height="1"&gt;</description></item><item><title>re: WCF: 4 Tenets of Service Oriented Data Validation</title><link>http://blogs.msdn.com/b/rjacobs/archive/2011/01/15/wcf-4-tenets-of-service-oriented-data-validation.aspx#10118344</link><pubDate>Thu, 20 Jan 2011 20:31:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10118344</guid><dc:creator>Martin</dc:creator><description>&lt;p&gt;Hi Ron and Rory,&lt;/p&gt;
&lt;p&gt;I really like the article and Rory&amp;#39;s additional remarks as you sum best practices regarding validation and exception handling which I use and propagate since years (DTO, Exception Shielding, Fault Contracts, Security Facades). I have the impression, that the impact of missing validation and insufficient exception handling on the maintainability of software systems is greatly underestimated.&lt;/p&gt;
&lt;p&gt;Just some short remark to Ron&amp;#39;s idea mentioned above: We have used this approach in the past to share simple validation logic between client and the server side. &lt;/p&gt;
&lt;p&gt;But how does this approach fit to the tenet &amp;quot;Services share schema and contract, not class&amp;quot; and the pattern &amp;quot;Document Processor&amp;quot; (see &lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/ms954638.aspx"&gt;msdn.microsoft.com/.../ms954638.aspx&lt;/a&gt;)? Following the &amp;quot;Document Processor&amp;quot; pattern, I would suggest to integrate the simple validation rules into the XSchema and share these rules as part of the contract.&lt;/p&gt;
&lt;p&gt;Do you agree?&lt;/p&gt;
&lt;p&gt;Best Regards,&lt;/p&gt;
&lt;p&gt;Martin&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10118344" width="1" height="1"&gt;</description></item><item><title>re: WCF: 4 Tenets of Service Oriented Data Validation</title><link>http://blogs.msdn.com/b/rjacobs/archive/2011/01/15/wcf-4-tenets-of-service-oriented-data-validation.aspx#10116571</link><pubDate>Mon, 17 Jan 2011 14:25:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10116571</guid><dc:creator>Ron Jacobs</dc:creator><description>&lt;p&gt;@Pablo - if you provide a Validator class from the service side that can validate the individual data items as well as the entity as a whole and share the assembly that might work. &lt;/p&gt;
&lt;p&gt;For example, a CustomerValidator might have CustomerValidator.ValidateName, ValidateAddress etc. &amp;nbsp;Then it can have a ValidateCustomer(customer) which could validate as a whole.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10116571" width="1" height="1"&gt;</description></item><item><title>re: WCF: 4 Tenets of Service Oriented Data Validation</title><link>http://blogs.msdn.com/b/rjacobs/archive/2011/01/15/wcf-4-tenets-of-service-oriented-data-validation.aspx#10116559</link><pubDate>Mon, 17 Jan 2011 14:00:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10116559</guid><dc:creator>cibrax</dc:creator><description>&lt;p&gt;Hi Ron,&lt;/p&gt;
&lt;p&gt;A common problem that many developers have to face is the distribution of the validation logic between the client and the service. Questions like, &amp;quot;Shall I run this logic on the client, service or both ?&amp;quot;, or &amp;quot;How do I do to share this validation logic between the client and the service ?&amp;quot;. The common instinct tell you that everything should be validated on the service, but then you start running in some usability issues on the client. For instance, If the service required five fields, and the client only sent two, how do I show that to the user in a friendly way ?. I can not implement the common validation method that shows the &amp;quot;red&amp;quot; boxes around the required fields without moving some validation logic to the client for that scenario. &amp;nbsp; ASP.NET MVC for example introduced the model, and you can decorate it with data validation annonations so the same model (and validation logic) is shared between the view and the controller. However, the same thing does not apply quite well to services. You can not expect that clients and services will share the same data contracts with the validation logic as you might have other legacy or service stacks consuming your services.&lt;/p&gt;
&lt;p&gt;Pablo.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10116559" width="1" height="1"&gt;</description></item><item><title>re: WCF: 4 Tenets of Service Oriented Data Validation</title><link>http://blogs.msdn.com/b/rjacobs/archive/2011/01/15/wcf-4-tenets-of-service-oriented-data-validation.aspx#10116222</link><pubDate>Sun, 16 Jan 2011 02:09:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10116222</guid><dc:creator>Ron Jacobs</dc:creator><description>&lt;p&gt;Thanks Rory - great ideas all around...&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10116222" width="1" height="1"&gt;</description></item><item><title>re: WCF: 4 Tenets of Service Oriented Data Validation</title><link>http://blogs.msdn.com/b/rjacobs/archive/2011/01/15/wcf-4-tenets-of-service-oriented-data-validation.aspx#10116213</link><pubDate>Sun, 16 Jan 2011 00:37:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10116213</guid><dc:creator>Rory_Primrose</dc:creator><description>&lt;p&gt;Hi Ron,&lt;/p&gt;
&lt;p&gt;There are some great ideas here.&lt;/p&gt;
&lt;p&gt;RE: Validation Rule violations should result in internal exceptions which may cause external faults&lt;/p&gt;
&lt;p&gt;Absolutely agree with this. You should look at leveraging an IErrorHandler for exception translation. The HandleError allows you to log exceptions on a background thread while the ProvideFault allows for exception translation. ProvideFault also plays an important role by allowing you to provide exception shielding (catch all, then return generic fault) to avoid security sensitive information being returned. I have one at &lt;a rel="nofollow" target="_new" href="http://jabiru.codeplex.com/SourceControl/changeset/view/66884#1659767"&gt;jabiru.codeplex.com/.../66884&lt;/a&gt; for example. &lt;/p&gt;
&lt;p&gt;I hit an edge case where I needed to use the IErrorHandler (in the previous link) to essentially manage business validation. It was where WF content correlation failed to find an existing workflow service instance for the data provided to the service. The IErrorHandler was the only place that the thrown exception could be translated into a business fault. See &lt;a rel="nofollow" target="_new" href="http://www.neovolve.com/post/2010/11/09/Managing-content-correlation-failures.aspx"&gt;www.neovolve.com/.../Managing-content-correlation-failures.aspx&lt;/a&gt; for the details.&lt;/p&gt;
&lt;p&gt;The IErrorHandler can be hooked up via configuration (&lt;a rel="nofollow" target="_new" href="http://www.neovolve.com/post/2008/04/07/implementing-ierrorhandler.aspx"&gt;www.neovolve.com/.../implementing-ierrorhandler.aspx&lt;/a&gt;) or as an attribute on the service implementation class (&lt;a rel="nofollow" target="_new" href="http://www.neovolve.com/post/2008/11/07/Strict-IErrorHandler-usage.aspx"&gt;www.neovolve.com/.../Strict-IErrorHandler-usage.aspx&lt;/a&gt;). I have provided support for both these scenarios in my toolkit (&lt;a rel="nofollow" target="_new" href="http://neovolve.codeplex.com/releases/view/19004"&gt;neovolve.codeplex.com/.../19004&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;RE: Validation Rules may be shared between sender and receiver&lt;/p&gt;
&lt;p&gt;I like this idea, but I prefer to keep data contracts lean and for them not to have any logic. They are essentially just DTO classes. A way to support this idea would be to provide a Validate extension method that is bundled up in the service contract assembly. If you are sharing the service contract binary with clients then they can use the same validation as the service. This could be a blessing and a curse. The validation logic will be versioned along with the service contract assembly, but the client may be using an old service contract version with a newer version of the service. Validation logic may get out of sync in this case.&lt;/p&gt;
&lt;p&gt;On a side note, a good idea is to describe business faults using combinations of code/description. Ideally, the business fault will be able to describe a collection of these code/description failures to avoid unnecessary round-trips for multiple input field failures on the client. &lt;/p&gt;
&lt;p&gt;Failure codes are great because they are human and culture independent (prefer enums for this purpose). A client application can use the code to determine an automated action (retry) or to highlight a failure in a UI with particular input fields. Codes will also allow a client to provide its own culture aware description as required. I have an example of one of these business faults at &lt;a rel="nofollow" target="_new" href="http://jabiru.codeplex.com/SourceControl/changeset/view/66884#1659655"&gt;jabiru.codeplex.com/.../66884&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;Not using codes forces the client to parse fault description strings which is very risky. The only other alternative is to create a fault contract/failure type which will be very messy on the service contracts and difficult for clients to support.&lt;/p&gt;
&lt;p&gt;I have put together an example of how to provide support for all of this with WF custom activities at &lt;a rel="nofollow" target="_new" href="http://www.neovolve.com/post/2010/10/13/Custom-Workflow-activity-for-business-failure-evaluatione28093Wrap-up.aspx"&gt;www.neovolve.com/.../Custom-Workflow-activity-for-business-failure-evaluatione28093Wrap-up.aspx&lt;/a&gt;.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10116213" width="1" height="1"&gt;</description></item></channel></rss>