<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5789460235976325967</id><updated>2011-11-27T15:21:37.904-08:00</updated><title type='text'>Architecture</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://architecturebyashwani.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://architecturebyashwani.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Ashwani</name><uri>http://www.blogger.com/profile/11607166212315288799</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>10</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5789460235976325967.post-1846611982353518843</id><published>2010-02-04T22:27:00.001-08:00</published><updated>2011-07-03T01:39:03.322-07:00</updated><title type='text'>foreground GC and background GC together in .Net 4.0</title><content type='html'>&lt;span xmlns=""&gt;&lt;h2&gt;What's new in Garbage Collector in .Net 4.0&lt;br /&gt;&lt;/h2&gt;&lt;p&gt;With the introduction of background GC (applicable only for Generation 2 and improvement over concurrent GC), you can do ephemeral GCs (Generation 0 and 1) as the foreground GCs. &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;How it works&lt;br /&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;When the background GC is in progress, the background GC thread will check frequent safe points and see if there is any requirement for foreground GCs and if yes, then it blocks the background GC and user threads to perform foreground GCs. Once foreground GCs is done, the background and user thread is resumed. The background GC is currently available for workstation GC only.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;This means that now only unusual circumstances should lead to long latency times.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;h2&gt;Various Garbage Collectors&lt;br /&gt;&lt;/h2&gt;&lt;p&gt;CLR provides two garbage collectors&lt;br /&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Workstation GC: designed for use by desktop applications&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Server GC: designed for use by server applications. ASP.Net loads Server GC on multiprocessor machines. On single processor machines it loads workstation GC with concurrent GC on.&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;We can use Garbage collection in our applications with the following options:&lt;br /&gt;&lt;/p&gt;&lt;h4&gt;Workstation GC with concurrent GC off&lt;br /&gt;&lt;/h4&gt;&lt;p&gt;This is designed for high throughput on single processor machines.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;    &lt;/span&gt;&lt;strong&gt;How it works&lt;br /&gt;&lt;/strong&gt;&lt;/p&gt;&lt;ol style="margin-left: 72pt"&gt;&lt;li&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;A managed thread is doing allocations;&lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;     &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Times New Roman; font-size:7pt"&gt;&lt;br /&gt;     &lt;/span&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;It runs out of allocations&lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;     &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Times New Roman; font-size:7pt"&gt;&lt;br /&gt;     &lt;/span&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;It triggers a GC which will be running on this very thread;&lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;     &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;GC calls SuspendEE to suspend managed threads;&lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;     &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;GC does its work;&lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;     &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;GC calls RestartEE to restart the managed threads;&lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;     &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;Managed threads start running again.&lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;     &lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;Configuration: This mode can be configured by setting the following values in the web.config&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;&amp;lt;configuration&amp;gt; &lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;    &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;    &amp;lt;runtime&amp;gt; &lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;    &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;        &amp;lt;gcConcurrent enabled="false"/&amp;gt; &lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;    &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;    &amp;lt;/runtime&amp;gt; &lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;    &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;&amp;lt;/configuration&amp;gt; &lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;    &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 54pt"&gt;&lt;br /&gt; &lt;/p&gt;&lt;h4&gt;Workstation GC with concurrent GC on&lt;br /&gt;&lt;/h4&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;This is designed for interactive applications where the response time is critical. Concurrent GC allows for shorter pause time.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;&lt;strong&gt;How it works:&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;The concurrent GC pauses the main thread of the application for the short interval of time during the entire GC time frame. This helps the applications to be more responsive. Since Gen0 and Gen1 collections are very fast so concurrent GC doesnot work for these generations. It makes sense to make concurrent GC for generation 2&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;br /&gt; &lt;/p&gt;&lt;h4&gt;Server GC&lt;br /&gt;&lt;/h4&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;In this case separate GC thread and a separated heap for each CPU is created. GC happens on these threads instead of on the allocating thread. The flow looks like this:&lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;    &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;br /&gt; &lt;/p&gt;&lt;ul style="margin-left: 54pt"&gt;&lt;li&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;A managed thread is doing allocations;&lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;     &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;It runs out of allocations on the heap its allocating on;&lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;     &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;It signals an event to wake the GC threads to do a GC and waits for it to finish;&lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;     &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;GC threads run, finish with the GC and signal an event that says GC is complete (When GC is in progress, all managed threads are suspended just like in Workstation GC);&lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;     &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;div&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;Managed threads start running again.&lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;      &lt;/span&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;Configuration: This mode can be configured by setting the following values in the web.config&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;&amp;lt;configuration&amp;gt; &lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;      &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;    &amp;lt;runtime&amp;gt; &lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;      &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;        &amp;lt;gcServer enabled="true"/&amp;gt; &lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;      &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;    &amp;lt;/runtime&amp;gt; &lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;      &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana; font-size:10pt"&gt;&amp;lt;/configuration&amp;gt;&lt;/span&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;&lt;br /&gt;      &lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;Important Points:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Concurrent GC is available only for Workstation GC. That means Server GC is always blocking GC.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Concurrent GC is only for the full garbage collection. Generation 0 and Generation 1 GCs are always blocking GCs.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;h2&gt;Garbage Collection Overview&lt;br /&gt;&lt;/h2&gt;&lt;p&gt;Garbage collector in .Net reclaims the memory of unused resources.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;It is performed in three different generations. All the new objects that we create fall under the category of Generation 0. Garbage collector collects the unused objects from Generation 0 first before it goes to Generation 1 and then 2. Everytime GC runs it advances the generation of the object (which survived from Garbage collection) to next level till the Generation 2.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;.Net &lt;strong&gt;System.GC class implements several methods that can be used by programmers. Here is the brief about each of the methods:&lt;/strong&gt;&lt;br /&gt;   &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;strong&gt;System.GC.Collect: This method forces garbage collection. This method should not be called explicitly to start garbage collection as it adversely effects the performance of the application.&lt;/strong&gt;&lt;br /&gt;    &lt;/li&gt;&lt;li&gt;&lt;strong&gt;System.GC.WaitForPendingFinalizers: This method suspends the execution of the current thread until the finalization thread has emptied the finalization queue. As with GC.Collect this method should be not be called.&lt;/strong&gt;&lt;br /&gt;    &lt;/li&gt;&lt;li&gt;&lt;strong&gt;System.GC.KeepAlive: This method is used to prevent an object to be garbage collected prematurely. This could happen if your managed code is not using the object however unmanaged code is using the object.&lt;/strong&gt;&lt;br /&gt;    &lt;/li&gt;&lt;li&gt;&lt;strong&gt;System.GC.SuppressFinalize: &lt;/strong&gt;This prevents the finalizer being called for a specified object. Use this method when you implement the dispose pattern.&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2&gt;A short note on Finalization&lt;br /&gt;&lt;/h2&gt;&lt;p&gt;.Net garbage collection mechanism keeps track of the objects life time using the strong and weak references. However when it comes to unmanaged resources like file, network connections it doesnot maintain their life time. You need to write the code to free the unmanaged resources. Net provides Object.Finalize method that can be used to free unmanaged resources.  Whenever a new object, having a Finalize method, is allocated on the heap a pointer to the object is placed in an internal data structure called Finalization queue. When the object is not reachable (means ready for garbage collection), GC removes the object from Finalization Queue and put that in another internal data structure called Freachable Queue. A special runtime thread empties the Freachable queue by executing the Finalize method.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;The next time garbage collector runs it sees that the finalized objects are truly garbage (means their finalize method has been executed) and then the memory of those object is freed.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;It is recommended to avoid using Finalize method unless required as it delays the garbage collection of those objects to the next time when GC runs.&lt;br /&gt;&lt;/p&gt;&lt;h4&gt;Use Dispose Pattern&lt;br /&gt;&lt;/h4&gt;&lt;p&gt;The Dispose pattern defines the way we should implement finalizer functionality on all managed classes that maintain resources that the caller must be allowed to explicitly release. To implement the Dispose pattern, do the following:&lt;br /&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Create a class that derives from &lt;strong&gt;IDisposable&lt;/strong&gt;.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Add a private member variable to track whether &lt;strong&gt;IDisposable.Dispose&lt;/strong&gt; has already been called. Clients should be allowed to call the method multiple times without generating an exception. If another method on the class is called after a call to &lt;strong&gt;Dispose&lt;/strong&gt;, you should throw an &lt;strong&gt;ObjectDisposedException&lt;/strong&gt;.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Implement a &lt;strong&gt;protected&lt;/strong&gt;&lt;br /&gt;     &lt;strong&gt;virtual&lt;/strong&gt;&lt;br /&gt;     &lt;strong&gt;void&lt;/strong&gt; override of the &lt;strong&gt;Dispose&lt;/strong&gt; method that accepts a single &lt;strong&gt;bool&lt;/strong&gt; parameter. This method contains common cleanup code that is called either when the client explicitly calls &lt;strong&gt;IDisposable.Dispose&lt;/strong&gt; or when the finalizer runs. The &lt;strong&gt;bool&lt;/strong&gt; parameter is used to indicate whether the cleanup is being performed as a result of a client call to &lt;strong&gt;IDisposable.Dispose&lt;/strong&gt; or as a result of finalization.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Implement the &lt;strong&gt;IDisposable.Dispose&lt;/strong&gt; method that accepts no parameters. This method is called by clients to explicitly force the release of resources. Check whether &lt;strong&gt;Dispose&lt;/strong&gt; has been called before; if it has not been called, call &lt;strong&gt;Dispose(true)&lt;/strong&gt; and then prevent finalization by calling &lt;strong&gt;GC.SuppressFinalize(this)&lt;/strong&gt;. Finalization is no longer needed because the client has explicitly forced a release of resources.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;div&gt;Create a finalizer, by using destructor syntax. In the finalizer, call &lt;strong&gt;Dispose(false)&lt;/strong&gt;.&lt;br /&gt;&lt;/div&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman; font-size:12pt"&gt;Code&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;public sealed class MyClass: IDisposable&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;  // Variable to track if Dispose has been called&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;  private bool disposed = false;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;  // Implement the IDisposable.Dispose() method&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;  public void Dispose(){&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;    // Check if Dispose has already been called&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;    if (!disposed)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;    {&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;      // Call the overridden Dispose method that contains common cleanup code&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;      // Pass true to indicate that it is called from Dispose&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;      Dispose(true);&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;     // Prevent subsequent finalization of this object. This is not needed&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;     // because managed and unmanaged resources have been explicitly released&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;      GC.SuppressFinalize(this);&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;    }&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;  }&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;  // Implement a finalizer by using destructor style syntax&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;  ~MyClass() {&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;    // Call the overridden Dispose method that contains common cleanup code&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;    // Pass false to indicate the it is not called from Dispose&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;    Dispose(false);&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;  }&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;  // Implement the override Dispose method that will contain common&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;  // cleanup functionality&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;  protected virtual void Dispose(bool disposing){&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;   if(disposing){&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;     // Dispose time code&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;     . . .&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;   }&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;   // Finalize time code&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;    . . .&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;  }&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;  …}&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Passing &lt;strong&gt;true&lt;/strong&gt; to the protected &lt;strong&gt;Dispose&lt;/strong&gt; method ensures that dispose specific code is called. Passing &lt;strong&gt;false&lt;/strong&gt; skips the &lt;strong&gt;Dispose&lt;/strong&gt; specific code. The &lt;strong&gt;Dispose(bool)&lt;/strong&gt; method can be called directly by your class or indirectly by the client.&lt;br /&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If you reference any static variables or methods in your finalize-time &lt;strong&gt;Dispose&lt;/strong&gt; code, make sure you check the &lt;strong&gt;Environment.HasShutdownStarted&lt;/strong&gt; property. If your object is thread safe, be sure to take whatever locks are necessary for cleanup.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Use the &lt;strong&gt;HasShutdownStarted&lt;/strong&gt; property in an object's &lt;strong&gt;Dispose&lt;/strong&gt; method to determine whether the CLR is shutting down or the application domain is unloading. If that is the case, you cannot reliably access any object that has a finalization method and is referenced by a static field.&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;References:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.msdn.com/maoni/archive/2004/09/25/234273.aspx"&gt;http://blogs.msdn.com/maoni/archive/2004/09/25/234273.aspx&lt;/a&gt;&lt;br /&gt;   &lt;/p&gt;&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms998549.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms998549.aspx#scalenetchapt06_topic5&lt;/a&gt;&lt;br /&gt;   &lt;/p&gt;&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/cc713687%28VS.100%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/cc713687%28VS.100%29.aspx&lt;/a&gt;&lt;br /&gt;   &lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.msdn.com/maoni/archive/2008/11/19/so-what-s-new-in-the-clr-4-0-gc.aspx"&gt;http://blogs.msdn.com/maoni/archive/2008/11/19/so-what-s-new-in-the-clr-4-0-gc.aspx&lt;/a&gt;&lt;br /&gt;   &lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/sasha/archive/2008/08/25/garbage-collection-notifications-in-net-3-5-sp1.aspx"&gt;http://blogs.microsoft.co.il/blogs/sasha/archive/2008/08/25/garbage-collection-notifications-in-net-3-5-sp1.aspx&lt;/a&gt;&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5789460235976325967-1846611982353518843?l=architecturebyashwani.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://architecturebyashwani.blogspot.com/feeds/1846611982353518843/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://architecturebyashwani.blogspot.com/2010/02/foreground-gc-and-background-gc.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default/1846611982353518843'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default/1846611982353518843'/><link rel='alternate' type='text/html' href='http://architecturebyashwani.blogspot.com/2010/02/foreground-gc-and-background-gc.html' title='foreground GC and background GC together in .Net 4.0'/><author><name>Ashwani</name><uri>http://www.blogger.com/profile/11607166212315288799</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5789460235976325967.post-6897225151372621440</id><published>2010-01-17T20:40:00.001-08:00</published><updated>2010-01-18T22:23:20.427-08:00</updated><title type='text'>Separating Code Concerns using AOP</title><content type='html'>&lt;span xmlns=''&gt;&lt;p&gt;One of the new assignments I took is designing guidelines for separating the code concerns in .net applications.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Let's look at the example to understand what problem needs to be solved.&lt;br/&gt;The following method retrieve products from the  database.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;&lt;span style='color:blue'&gt;public&lt;/span&gt;&lt;br /&gt;     &lt;span style='color:#2b91af'&gt;List&lt;/span&gt;&amp;lt;&lt;span style='color:#2b91af'&gt;Product&lt;/span&gt;&amp;gt; GetProducts()&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;Step1: Create Connection with the database&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;Step2: Call Stored Procedure to fetch the records.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;Step3: Return list of products.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;As we go on improving our code, we need to perform other activities like:&lt;br /&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Authorization: whether the current user has rights to fetch the complete product list&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Activity Capture: to log the activity performed by the user&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Caching&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;In order to implement this, we start incorporating the code in the above method as shown below (Example for Caching, Authorization, and Activity Capture):&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;&lt;span style='color:blue'&gt;public&lt;/span&gt;&lt;br /&gt;     &lt;span style='color:#2b91af'&gt;List&lt;/span&gt;&amp;lt;&lt;span style='color:#2b91af'&gt;Product&lt;/span&gt;&amp;gt; GetProducts()&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;Perform Activity Capture: &lt;span style='color:red'&gt;&lt;strong&gt;Concern(Activity Capture)&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;    &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;    if( User is Authorized)&lt;span style='color:red'&gt;&lt;strong&gt; Concern(Authorization)&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;    &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;    {&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;        if(Data is in Cache)&lt;span style='color:red'&gt;&lt;strong&gt; Concern(Caching)&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;    &lt;/span&gt;&lt;/p&gt;&lt;p style='margin-left: 36pt'&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style='margin-left: 36pt'&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;    Return data from cache&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style='margin-left: 36pt'&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style='margin-left: 36pt'&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;else&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style='margin-left: 36pt'&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style='margin-left: 72pt'&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;Create Connection with the database &lt;span style='color:#0070c0'&gt;&lt;strong&gt;    &lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;            Call Stored Procedure to fetch the records.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;            Store the result in Cache.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;            return the list of products&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style='margin-left: 36pt'&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;We created "GetProducts" method to retrieve Products but now start adding more concerns to it (marked in red). These concerns should be removed from the body of this method. This type of programming is called Aspect Oriented Programming (AOP).&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Unfortunately .Net doesnot have inbuilt support for AOP.  You need to use reflection a lot in order to perform this separation, however that would have negative impact on run-time performance of the applications. There are some very good frameworks that support AOP. In this blog, I will be discussing two approaches to do AOP in .Net&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;PostSharp:&lt;/strong&gt; This framework uses Attribute Programming to separate concerns. Let's look how our above method will be written using PostSharp&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;[&lt;span style='color:#2b91af'&gt;Authorization&lt;/span&gt;]&lt;br/&gt;[&lt;span style='color:#2b91af'&gt;Caching&lt;/span&gt;]&lt;br/&gt;[&lt;span style='color:#2b91af'&gt;ActivityCapture&lt;/span&gt;]&lt;br/&gt;&lt;span style='color:blue'&gt;public&lt;/span&gt;&lt;br /&gt;     &lt;span style='color:#2b91af'&gt;List&lt;/span&gt;&amp;lt;&lt;span style='color:#2b91af'&gt;Product&lt;/span&gt;&amp;gt; GetProducts()&lt;br/&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;Create Connection with the database&lt;span style='color:#0070c0'&gt;&lt;strong&gt;&lt;br /&gt;      &lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;    Call Stored Procedure to fetch the records.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;    return the list of products&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Courier New; font-size:10pt'&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;The body of the above method contains code only related to fetching the products and all other concerns are placed as attributes on top of the Method. PostSharp allows you to write your own attributes. You can specify the code that needs to be performed before or after the execution of the method body. Postsharp then does the compile time weaving to place the code at appropriate location.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_FJo4XM0HhGE/S1VLHzxhZPI/AAAAAAAAAEM/AncMD2TFBZY/s1600-h/PostSharp.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 106px;" src="http://4.bp.blogspot.com/_FJo4XM0HhGE/S1VLHzxhZPI/AAAAAAAAAEM/AncMD2TFBZY/s320/PostSharp.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5428327523394086130" /&gt;&lt;/a&gt;&lt;br /&gt;   &lt;/p&gt;&lt;p&gt;You can download &lt;a href='http://ashwanicodesamples.googlecode.com/files/PostSharpWeb.zip'&gt;sample code&lt;/a&gt; that contains Authorization performed using PostSharp.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;For more details on PostSharp visit: &lt;a href='http://www.postsharp.org/'&gt;http://www.postsharp.org/&lt;/a&gt;&lt;br /&gt;   &lt;/p&gt;&lt;p&gt;Keep looking into this blog for update on this topic.&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5789460235976325967-6897225151372621440?l=architecturebyashwani.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://architecturebyashwani.blogspot.com/feeds/6897225151372621440/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://architecturebyashwani.blogspot.com/2010/01/separating-code-concerns-using-aop.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default/6897225151372621440'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default/6897225151372621440'/><link rel='alternate' type='text/html' href='http://architecturebyashwani.blogspot.com/2010/01/separating-code-concerns-using-aop.html' title='Separating Code Concerns using AOP'/><author><name>Ashwani</name><uri>http://www.blogger.com/profile/11607166212315288799</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_FJo4XM0HhGE/S1VLHzxhZPI/AAAAAAAAAEM/AncMD2TFBZY/s72-c/PostSharp.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5789460235976325967.post-5284700049580633114</id><published>2010-01-03T23:26:00.001-08:00</published><updated>2010-01-03T23:26:52.147-08:00</updated><title type='text'>Cryptography Library in .Net</title><content type='html'>&lt;span xmlns=''&gt;&lt;p&gt;During the development of Application framework, I created a library that would help to perform cryptography functions in the application. Here I am providing brief overview of cryptography and code that performs cryptography functions.&lt;br/&gt;&lt;br/&gt;Encryption is a technique by which plain text information is converted in data stream (cipher text) which looks like meaningless.&lt;br/&gt;Decryption is the process of converting the cipher text (encrypted data stream) to readable plain text.&lt;br/&gt;&lt;br/&gt;.Net Cryptography supports symmetric encryption, asymmetric encryption and hashing to convert plain text into cipher text.&lt;br/&gt;&lt;br/&gt;&lt;br /&gt;   &lt;/p&gt;&lt;p&gt;&lt;span style='color:#3333ff; font-size:14pt'&gt;&lt;strong&gt;Symmetric Encryption&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;   &lt;/p&gt;&lt;p&gt;These cryptography algorithms use the same key for encryption and decryption. Algorithms that operate on 1 bit or 1 byte of plaintext at a time are called &lt;strong&gt;stream ciphers &lt;/strong&gt;whereas&lt;strong&gt;&lt;br /&gt;    &lt;/strong&gt;algorithms that operate on blocks of bits at a time are called &lt;strong&gt;block ciphers.&lt;/strong&gt;&lt;br /&gt;   &lt;/p&gt;&lt;p&gt;&lt;strong&gt;Where to use Symmetric Encryption&lt;br/&gt;&lt;/strong&gt;These algorithms should be used to encrypt the messages within one application because same key is used for encryption and decryption. Using symmetric encryption with third party applications is not recommended as you need to share the encryption key.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Important Symmetric Encryption Algorithms&lt;/strong&gt;&lt;br /&gt;   &lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Data Encryption Standard: &lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;   &lt;/p&gt;&lt;p&gt;DES is a block cipher which uses 56-bit fixed length key to generate cipher text. Any 56 bit value can be a key.&lt;br/&gt;Due to short length of the key this algorithm is vulnerable to brute-force attack.&lt;br/&gt;&lt;br/&gt;&lt;strong&gt;&lt;em&gt;TripleDES:&lt;/em&gt;&lt;h3&gt;&lt;br/&gt;&lt;/h3&gt;&lt;/strong&gt;Triple DES improves the DES algorithm by applying DES three times using three different keys by which effective key length becomes 168 bits.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Advanced Encryption Standard (AES) aka Rijndael:&lt;/em&gt;&lt;/strong&gt;&lt;h3&gt;&lt;br/&gt;&lt;/h3&gt;This is block cipher and supports key lengths of 128, 192 and 256 bits. It is recommended to uses 256 bits key.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;What is Initialization Vector&lt;br/&gt;&lt;/strong&gt;To ensure that encryption of the same string and with the same key is different everytime we perform the encryption, the output (cipher block) of previous block is appended to the next block to perform the encryption. But for the first block initialization vector is used. It is important to use the random IV everytime we perform the encryption operation.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;span style='color:#3333ff; font-size:14pt'&gt;&lt;strong&gt;Hashing&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;   &lt;/p&gt;&lt;p&gt;This is one way hash function which takes the variable length string and converts that to the fixed length binary sequence. Using the hash value you can't retrieve the original value. This is only one way conversion; however you can always compare the two hash values to check whether those are same or not.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Where to use Hashing&lt;/strong&gt;&lt;br/&gt;Hashing should be used where you need to protect the information and doesnot want the original text. For example: User's Passowrd.&lt;br/&gt;User's Password can be hashed and stored in the database and during the login calculate the hash of the password entered by the user. We compare the hash value just calculated with the value stored in the database, if both matches that means user has entered the valid password.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Hashing Algorithms&lt;/strong&gt;&lt;br /&gt;   &lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;MD5:&lt;/em&gt;&lt;br/&gt;&lt;/strong&gt;This algorithm produces 128 bit hash value.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;SHA1:&lt;/em&gt;&lt;br/&gt;&lt;/strong&gt;This algorithm produces 160 bit hash value. Always use SHA because it produces larger hash value as compared to MD5.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Salt Value&lt;br/&gt;&lt;/strong&gt;One problem with hashing is that if two user's selected the same password then the hash value will also be same. One way to ensure that the hash of two same strings will never be same is to add the salt value (unique value) to the original text before hashing. The salt value can be generated using &lt;strong&gt;RNGCryptoServiceProvider. Y&lt;/strong&gt;ou require this salt value during comparison. You have two options either to store the salt as the part of the hash value so that later it can be extracted from the hash value or store the salt value as separate. The attached code appends the salt value as part of the hash itself.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;span style='color:#3333ff; font-size:14pt'&gt;&lt;strong&gt;Difference between Hashing and HMAC&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;   &lt;/p&gt;&lt;p&gt;During development of Security Framework of Rest Services, I figured out that why hashing alone is not sufficient and we need to perform the HMAC. Here is the difference between two.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Hashing: It produces standard 20 byte fixed length hash (using SHA1). Now if we send the request to the service along with the hash value of the Request Parameters for tamper proofing, the service will also compute the hash value of all the request parameters to check whether the information has been tampered or not. Things look fine but actually here is one problem. Some Attacker changes the request parameters, recalculates the hash of the changed request parameters and then sends the request using the new request parameters and new hash value. Now service recalculates the hash value from the request parameters and found the hash value to be correct (because the hash value is itself replaced with the new one.). So hashing in this scenario will not work for tamper proofing.&lt;br/&gt;Hashing should be used only within one layer of the application or between layers where communication between the layers is encrypted and highly secured like storing password because the hash is calculated in the business layer and stored in the database. The communication between the business layer and database is generally behind the firewall and secured.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;So in the above scenario, we have to use HMAC in which a secret key is shared between the two parties and using that secret key the HMAC is calculated. What HMAC does is, it takes the hash of the shared key + message, prepends the key to that hash, and then re-hashes the result. This makes it cryptographically sound and thus used for digital signing.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;HMAC = hash (sharedkey + hash (sharedkey + message))&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Forms Authentication Ticket, Roles Cookie uses HMac for tamper proofing.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;span style='color:#3333ff; font-size:14pt'&gt;&lt;strong&gt;Performing Encryption/Digital Signing in ASP.Net&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Arial; font-size:10pt'&gt;.Net has machine key settings in the machine.config file by which forms authentication ticket, roles cookie are encrypted and signed.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Arial; font-size:10pt'&gt;The default values for the machinekey are&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style='background: #dddddd'&gt;&lt;span style='color:black; font-family:Courier New; font-size:10pt'&gt;&amp;lt;pages enableViewStateMac="true" viewStateEncryptionMode="Auto" ... /&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style='background: #dddddd'&gt;&lt;br /&gt; &lt;/p&gt;&lt;p style='background: #dddddd'&gt;&lt;span style='color:black; font-family:Courier New; font-size:10pt'&gt;&amp;lt;machineKey validationKey="AutoGenerate,IsolateApps"  &lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style='background: #dddddd'&gt;&lt;span style='color:black; font-family:Courier New; font-size:10pt'&gt;            decryptionKey="AutoGenerate,IsolateApps" &lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style='background: #dddddd'&gt;&lt;span style='color:black; font-family:Courier New; font-size:10pt'&gt;            validation="SHA1" decryption="Auto" /&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Arial; font-size:10pt'&gt;When you configure ViewState, the &amp;lt;&lt;strong&gt;pages&lt;/strong&gt;&amp;gt; element is used in conjunction with the &amp;lt;&lt;strong&gt;machineKey&lt;/strong&gt;&amp;gt; element.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Arial; font-size:10pt'&gt;The &amp;lt;machineKey&amp;gt; attributes are&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span style='font-family:Arial; font-size:10pt'&gt;validationKey: This key specifies the HMAC key which is used for making viewstate tamper proof, signing the forms authentication ticket, signing Roles cookie.&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style='font-family:Arial; font-size:10pt'&gt;decryptionKey: This specifies the key that will be used to encrypt or decrypt the data. This key is used to encrypt data of forms authentication ticket, roles cookie. &lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style='font-family:Arial; font-size:10pt'&gt;decryption: This specifies the symmetric algorithm that will be used for encryption and decryption. The values can be AES, 3DES, DES&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style='font-family:Arial; font-size:10pt'&gt;validation: This specifies the algorithm used to generate HMAC for making viewstate tamper proof, signing forms authentication ticket. The various values can be SHA1, MD5, AES and 3DES. The values AES and 3DES are used in ASP.Net 1.1 because the decryption was only introduced in 2.0&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style='font-family:Arial; font-size:10pt'&gt;Always use SHA1 because this produces larger hash as compared to MD5.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Arial; font-size:10pt'&gt;Forms authentication defaults to SHA1 for tamper proofing (if &amp;lt;&lt;strong&gt;forms protection="validation"&lt;/strong&gt; or "&lt;strong&gt;All&lt;/strong&gt;"). &lt;br/&gt;When &amp;lt;&lt;strong&gt;forms protection="All"&lt;/strong&gt;&amp;gt; or &amp;lt;&lt;strong&gt;forms protection = "Encryption"&lt;/strong&gt;&amp;gt;, then forms authentication hashes the forms authentication ticket by using either MD5 or HMACSHA1&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style='margin-left: 36pt'&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;span style='color:black; font-family:Arial; font-size:10pt'&gt;&lt;strong&gt;Performing Cryptography Operations:&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='color:black; font-family:Arial; font-size:10pt'&gt;In every application there are scenarios where we need to encrypt/ decrypt, hash or digital sign the information. The attached code provides the library for performing these operations. Brief overview of the library is explained below:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='color:black; font-family:Arial; font-size:10pt'&gt;As mentioned Microsoft uses machineKey to encrypt/ decrypt, digitally sign the authentication cookie, roles cookie so it is better to use same keys for crypto operation which we perform in the application.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='color:black; font-family:Arial; font-size:10pt'&gt;The first step would be to generate the decryption and validation keys. We should keep in mind that our applications will be deployed in web farm environment or not. It is always better to specify the specific values of decryption and validation keys so that in future web farm deployment will be easier. Attached code contains the Console Project which describes the way to generate decryption and validation keys.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='color:black; font-family:Arial; font-size:10pt'&gt;&lt;strong&gt;&lt;em&gt;MachineKey Wrapper&lt;/em&gt;&lt;/strong&gt;: Code contains machine Key wrapper that reads machineKey settings from the config file.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='color:black; font-family:Arial; font-size:10pt'&gt;&lt;strong&gt;&lt;em&gt;Encryption/ Decryption&lt;/em&gt;&lt;/strong&gt;: The code contains various operations for performing encryption and decryption including encryption and decryption of XML documents/ elements. These methods use decryption and decryptionKey element of the machineKey settings.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='color:black; font-family:Arial; font-size:10pt'&gt;&lt;strong&gt;&lt;em&gt;Hashing&lt;/em&gt;&lt;/strong&gt;: Code contains methods for creating the hash and then comparing the hash value. Salt is randomly generated and stored as part of hash value. These methods use only the validation attribute of machineKey settings.&lt;/span&gt;&lt;br /&gt;    &lt;br/&gt;Note: The validationKey attribute is used is not used for hashing, this value is used for HMAC which is different from hashing as explained above.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Digital Signing (HMAC): Code contains various methods for creating and comparing the signature. The validation Key mentioned in the machineKey settings of web.config file is the secret key which HMAC uses for generating signature.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href='http://cryptographylibrary.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=37421'&gt;&lt;strong&gt;Cryptography Library in .Net&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;br /&gt;    &lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;References:&lt;br /&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;a href='http://msdn.microsoft.com/en-us/library/ms998288.aspx'&gt;&lt;span style='font-size:10pt'&gt;http://msdn.microsoft.com/en-us/library/ms998288.aspx&lt;/span&gt;&lt;/a&gt;&lt;span style='font-size:10pt'&gt;&lt;br /&gt;    &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;a href='http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate2.aspx'&gt;&lt;span style='font-size:10pt'&gt;http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate2.aspx&lt;/span&gt;&lt;/a&gt;&lt;span style='font-size:10pt'&gt;&lt;br /&gt;    &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;a href='http://www.4guysfromrolla.com/webtech/LearnMore/Security.asp'&gt;&lt;span style='font-size:10pt'&gt;http://www.4guysfromrolla.com/webtech/LearnMore/Security.asp&lt;/span&gt;&lt;/a&gt;&lt;span style='font-size:10pt'&gt;&lt;br /&gt;    &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;a href='http://msdn.microsoft.com/en-us/library/5e9ft273%28VS.100%29.aspx'&gt;&lt;span style='font-size:10pt'&gt;http://msdn.microsoft.com/en-us/library/5e9ft273%28VS.100%29.aspx&lt;/span&gt;&lt;/a&gt;&lt;span style='font-size:10pt'&gt;&lt;br /&gt;    &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;a href='http://dev.ionous.net/2009/03/hmac-vs-raw-sha-1.html'&gt;&lt;span style='font-size:10pt'&gt;http://dev.ionous.net/2009/03/hmac-vs-raw-sha-1.html&lt;/span&gt;&lt;/a&gt;&lt;span style='font-size:10pt'&gt;&lt;br /&gt;    &lt;/span&gt;&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5789460235976325967-5284700049580633114?l=architecturebyashwani.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://architecturebyashwani.blogspot.com/feeds/5284700049580633114/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://architecturebyashwani.blogspot.com/2010/01/cryptography-library-in-net.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default/5284700049580633114'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default/5284700049580633114'/><link rel='alternate' type='text/html' href='http://architecturebyashwani.blogspot.com/2010/01/cryptography-library-in-net.html' title='Cryptography Library in .Net'/><author><name>Ashwani</name><uri>http://www.blogger.com/profile/11607166212315288799</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5789460235976325967.post-2675806877740674828</id><published>2010-01-03T23:25:00.001-08:00</published><updated>2010-01-03T23:25:20.784-08:00</updated><title type='text'>WCF Generic Error Handling using IErrorHandler</title><content type='html'>&lt;p style="font-family: trebuchet ms;font-family:trebuchet ms;"  class="MsoNormal"&gt;&lt;span style="font-size:100%;"&gt;This is one of the series of WCF Blogs I have written. Click &lt;a href="http://ashwani-wcf.blogspot.com/"&gt;here &lt;/a&gt;to visit all my WCF Blogs.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: trebuchet ms;font-family:trebuchet ms;"  class="MsoNormal"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: trebuchet ms;font-family:trebuchet ms;"  class="MsoNormal"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style=""&gt;Error Handling in WCF using IErrorHandler Interface&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;Source Code: &lt;a href="http://ashwanicodesamples.googlecode.com/files/WCFErrorHandling.zip"&gt;Download&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;Exceptions are a critical component of a robust system and can be indicators of a variety of situations. For example, a caller may not have provided correct or complete information to a service, a service may have encountered an issue attempting to complete an operation, or a message may be formatted according to an unsupported version.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;In this blog, I will talk about the effect exceptions have in WCF and the features WCF provides for communicating and processing exceptions. I will also describe the difference between exceptions and faults, the ways to create faults to send to a caller, and ways to process exceptions on both the service and caller. Finally, I will describe ways to centralize exception processing, catching unexpected exceptions or performing additional processing on exceptions and faults, such as logging.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;A WCF service typically wraps calls to underlying business logic libraries, and as would be expected in any managed code, these libraries may raise standard .NET exceptions to their callers. Exceptions are raised up the call stack until either they are handled by a layer or reach the root application’s context, at which point they are typically fatal to the calling application, process, or thread (depending on what type of application is running).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;Although unhandled exceptions are not fatal to WCF itself, WCF makes the assumption that they indicate a serious issue in the service’s capability to continue communications with the client. In those cases, WCF will fault the service channel, which means any existing sessions (for example, for security, reliable messaging, or state sharing) will be destroyed. If a session is part of the service call, the client channel will no longer be useful, and the client-side proxy will need to be re-created for the client to continue calling the service.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;By default, exceptions that reach the service host that are not derived from FaultException are considered indications of a potentially fatal condition. The exception is replaced by FaultException and the original exception’s details are omitted unless the IncludeExceptionDetailInFaults option is enabled. The FaultException is then serialized as a SOAP fault for communication back to the caller.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;The fatal condition created by unhandled exceptions can be prevented by catching exceptions before they reach the service host and throwing a &lt;/span&gt;&lt;span style="font-size:100%;"&gt;FaultException &lt;/span&gt;&lt;span style="font-size:100%;"&gt;manually.&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;Most services which require error handling also require additional information to be passed with the error notification. This information can be transferred to the client as a standard WCF data contract, in the disguise of a fault. The contractual specification that a particular service operation can result in the specified fault is called a &lt;em&gt;&lt;span style=""&gt;fault contract&lt;/span&gt;&lt;/em&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;The WCF service can produce a fault that is part of its fault contract, by throwing an exception. Throwing an exception is the most natural thing to do to indicate failure, for a .NET developer. The service is expected to throw the &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;code&gt;&lt;span style=""&gt;FaultException&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;span class="code-keyword"  style="font-size:100%;"&gt;&lt;span style=""&gt;&lt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;code&gt;&lt;span style=""&gt;TDetail&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;span class="code-keyword"  style="font-size:100%;"&gt;&lt;span style=""&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; generic exception, with &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;code&gt;&lt;span style=""&gt;TDetail&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; being the actual fault type that is being conveyed to the client. For example, the following service code conveys the &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;code&gt;&lt;span style=""&gt;ServiceFault&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; fault to the client:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: trebuchet ms;font-family:trebuchet ms;" class="MsoNormal" &gt;&lt;span  lang="CS" style="font-size:100%;"&gt;class Service : IService {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: trebuchet ms;font-family:trebuchet ms;" class="MsoNormal" &gt;&lt;span  lang="CS" style="font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;public void MyMethod() {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: trebuchet ms;font-family:trebuchet ms;" class="MsoNormal" &gt;&lt;span  lang="CS" style="font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;ServiceFault fault = new ServiceFault(...);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: trebuchet ms;font-family:trebuchet ms;" class="MsoNormal" &gt;&lt;span  lang="CS" style="font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;throw new FaultException&lt;servicefault&gt;(fault);&lt;o:p&gt;&lt;/o:p&gt;&lt;/servicefault&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: trebuchet ms;font-family:trebuchet ms;" class="MsoNormal" &gt;&lt;span  lang="CS" style="font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: trebuchet ms;font-family:trebuchet ms;" class="MsoNormal" &gt;&lt;span  lang="CS" style="font-size:100%;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;WCF has an excellent built-in extensibility mechanism for converting exceptions to faults. This extensibility point can be consumed through the &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;code&gt;&lt;span style=""&gt;IErrorHandler&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; interface, which provides two methods: &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;code&gt;&lt;span style=""&gt;HandleError&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; and &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;code&gt;&lt;span style=""&gt;ProvideFault&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;. The &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;code&gt;&lt;span style=""&gt;HandleError&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; method is called on a separate thread after the call has already completed, to possibly log the error and perform other book-keeping operations. The &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;code&gt;&lt;span style=""&gt;ProvideFault&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; method, on the other hand, is called on the worker thread that is invoking the service call, and accepts the exception that was thrown by the service. It is expected to provide a fault message that will be sent to the client, and thus fits exactly what we are trying to accomplish. At runtime, an implementation of these methods can be hooked up to the &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;code&gt;&lt;span style=""&gt;ChannelDispatcher&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; on the service side, and automatically get called whenever an unhandled exception escapes the service code.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;We will begin with the core of the error handler. Our first attempt could be converting any exception to a &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;code&gt;&lt;span style=""&gt;FaultException&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;span class="code-keyword"  style="font-size:100%;"&gt;&lt;span style=""&gt;&lt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;code&gt;&lt;span style=""&gt;TDetail&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;span class="code-keyword"  style="font-size:100%;"&gt;&lt;span style=""&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; with &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;code&gt;&lt;span style=""&gt;TDetail&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; as the exception type. For example, if an &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;code&gt;&lt;span style=""&gt;ArgumentException&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; could be thrown from downstream code, then we convert that to the specific fault. We need a mapping mechanism between .NET exceptions and faults. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;In the code attached, I have created class library project that you can use in any of the Service. This Library contains the following classes&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style=""&gt;IExceptionToFaultConverter&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; is having a method ConvertExceptionToFaultDetail. This method will be responsible for converting any type of Exception to the Fault. You can implement this interface in your service and write any your own logic to convert the exceptions to faults.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style=""&gt;ErrorHandler&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; is implementing the IErrorHandler interface and thus implementing HandleError and ProvideFault methods.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: trebuchet ms;font-family:trebuchet ms;" &gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style=""&gt;ErrorHandlerBehaviourAttribute&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; is used to apply the behavior to your service so that whenever exception is raised, that will be handled in the Channel Dispatcher.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: trebuchet ms;font-family:trebuchet ms;" &gt;&lt;span style="font-size:100%;"&gt;In the Service, we have to implement the &lt;b style=""&gt;IExceptionToFaultConverter &lt;/b&gt;method and also specify the behavior to the service.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: trebuchet ms;font-family:trebuchet ms;" &gt;&lt;span style="font-size:100%;"&gt;The behavior can be specified in the following way at the service Level.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: trebuchet ms;font-family:trebuchet ms;" class="MsoNormal" &gt;&lt;span style="font-size:100%;"&gt;[&lt;span style="color: rgb(43, 145, 175);"&gt;ErrorHandlerBehaviour&lt;/span&gt;(&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: trebuchet ms;font-family:trebuchet ms;" class="MsoNormal" &gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;ExceptionToFaultConverter = &lt;span style="color:blue;"&gt;typeof&lt;/span&gt;(&lt;span style="color: rgb(43, 145, 175);"&gt;ServiceFaultConverter&lt;/span&gt;))]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: trebuchet ms;font-family:trebuchet ms;" class="MsoNormal" &gt;&lt;span style=";font-size:100%;color:blue;"  &gt;public&lt;/span&gt;&lt;span style="font-size:100%;"&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Service&lt;/span&gt; : &lt;span style="color: rgb(43, 145, 175);"&gt;IService&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: trebuchet ms;font-family:trebuchet ms;" class="MsoNormal" &gt;&lt;span style="font-size:100%;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: trebuchet ms;font-family:trebuchet ms;" &gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;            &lt;/span&gt;………….&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: trebuchet ms;font-family:trebuchet ms;" &gt;&lt;span style="font-size:100%;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;We are here adding the Service behavior and specifying the Converter which we have implemented above.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="text-align: justify; font-family: trebuchet ms;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style=""&gt;Summary&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;span style="font-family: trebuchet ms;font-family:&amp;quot;;font-size:100%;"  &gt;The approach outlined in this article allows service developers to focus on their business logic and call downstream facilities directly. It absolves service developers from the need to worry about letting only permitted faults escape the service boundary, and provides a convenient mechanism for mapping .NET exceptions to well-defined WCF faults.&lt;br /&gt;Click &lt;a href="http://ashwanicodesamples.googlecode.com/files/WCFErrorHandling.zip"&gt;here&lt;/a&gt; to download source code&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5789460235976325967-2675806877740674828?l=architecturebyashwani.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://architecturebyashwani.blogspot.com/feeds/2675806877740674828/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://architecturebyashwani.blogspot.com/2010/01/wcf-generic-error-handling-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default/2675806877740674828'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default/2675806877740674828'/><link rel='alternate' type='text/html' href='http://architecturebyashwani.blogspot.com/2010/01/wcf-generic-error-handling-using.html' title='WCF Generic Error Handling using IErrorHandler'/><author><name>Ashwani</name><uri>http://www.blogger.com/profile/11607166212315288799</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5789460235976325967.post-6423706680443058314</id><published>2010-01-03T23:24:00.001-08:00</published><updated>2010-01-03T23:24:35.598-08:00</updated><title type='text'>Speed up your Development using Ado.Net Entity Framework</title><content type='html'>&lt;span style=";font-family:trebuchet ms;font-size:100%;color:black;"   &gt;&lt;br /&gt;This is one of my posts on the ADO.Net Entity Framework. Click &lt;a href="http://ashwani1111.blogspot.com/"&gt;here&lt;/a&gt; to see all my posts on Entity Framework.&lt;br /&gt;&lt;br /&gt;Relational database systems are really considered the lifeline of every enterprise application and, in many cases, of the enterprise itself. These remarkable systems store information in logical tables containing rows and columns, allowing data access and manipulation through Structured Query Language (SQL) calls and data manipulation languages (DMLs). Relational databases are unique in the enterprise because they form the foundation from which all applications are born. In addition, unlike other software applications, databases are often shared across many function&lt;/span&gt;&lt;span style=";font-family:trebuchet ms;font-size:100%;color:black;"   &gt;al areas of a business. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoNormal"  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style=";font-size:100%;color:black;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;span style="color:black;"&gt;What Is ORM?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;i&gt;&lt;span style="color:black;"&gt;ORM &lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;span style=";font-size:100%;color:black;"  &gt;is an automated way of connecting an object model, sometimes referred to as a &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;i&gt;&lt;span style="color:black;"&gt;domain model&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;span style=";font-size:100%;color:black;"  &gt;, to a relational database by using metadata as the descriptor of the object and data.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style=";font-size:100%;color:black;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;span style="color:black;"&gt;Entity Framework&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;The Entity Framework looks like an interesting technology which is more powerful and advanced than LINQ to SQL. Both technologies have a different kind of philosophy but several features have similar implementations. The EF is more than just an ORM (Object Relational Mapping) tool. It allows developers to query and manipulate data using a conceptual model instead of a physical storage model. It will also become the foundation of new application blocks like &lt;a href="http://astoria.mslivelabs.com/" target="_blank"&gt;Astoria&lt;/a&gt; (ADO.NET Data Services) which will enable you to expose any data store as web services and &lt;a href="http://msdn2.microsoft.com/en-us/data/bb419139.aspx" target="_blank"&gt;Jasper&lt;/a&gt; (Data Access Incubation Projects) which &lt;span id="article_content3"&gt;can be used to build dynamic data layers&lt;/span&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style=";font-size:100%;color:black;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;It is important to understand that there are many benefits to using EF rather than other data access techniques. These benefits will become more evident as you work with them, but the following are the few of them. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;ul  style="font-family:trebuchet ms;"&gt;&lt;li&gt;&lt;!--[if !supportLists]--&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;&lt;span style="font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style="font-size:100%;"&gt;EF automates the object-to table and table-to-object conversion, which simplifies development. This simplified development leads to quicker time to market and reduced development and maintenance costs.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;!--[if !supportLists]--&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;&lt;span style="font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style="font-size:100%;"&gt;Applications are freed from hard-coded dependencies on a particular data engine or storage schema.&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;!--[if !supportLists]--&gt;&lt;!--[endif]--&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;Mappings between the conceptual model and the storage-specific schema can change without changing the application code.&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;!--[if !supportLists]--&gt;&lt;!--[endif]--&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;Multiple conceptual models can be mapped to a single storage schema.&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;!--[if !supportLists]--&gt;&lt;!--[endif]--&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;Language-integrated query support provides compile-time syntax validation for queries against a conceptual model.&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;!--[if !supportLists]--&gt;&lt;!--[endif]--&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;EF requires less code as compared to embedded SQL, handwritten stored procedures, or any other interface calls with relational databases.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;!--[endif]--&gt;&lt;span style="font-size:100%;"&gt;EF provides transparent caching of objects on the client (that is, the application tier), thereby improving system performance. A good ORM is a highly optimized solution that will make your application faster and easier to support.&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;              &lt;p class="MsoNormal"  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;span style="color:black;"&gt;EF Architecture&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_FJo4XM0HhGE/SbItpyV_rwI/AAAAAAAAABY/1WseT6GMmy0/s1600-h/Image.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 320px; height: 295px;" src="http://3.bp.blogspot.com/_FJo4XM0HhGE/SbItpyV_rwI/AAAAAAAAABY/1WseT6GMmy0/s320/Image.JPG" alt="" id="BLOGGER_PHOTO_ID_5310357106535149314" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;The ADO.NET Entity Framework is a layered framework which abstracts the relational schema of a database and presents a conceptual model.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;br /&gt;&lt;span style=";font-size:100%;color:red;"  &gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;strong&gt;Data Source&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;: The bottom layer is the data which can be stored in one or many databases. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;strong&gt;Data Providers&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;: The data will be accessed by an ADO.NET data provider. At this moment only SQL Server is supported but in the near future there will be data providers for Oracle, MySQL, DB2, etc.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;strong&gt;Entity Data Model (EDM)&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;: An EDM is defined by the following three model and mapping files that have corresponding file name extensions: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="margin-left: 0.5in; text-align: justify; text-indent: -0.25in;font-family:trebuchet ms;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;·&lt;span style="font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style="font-size:100%;"&gt;Conceptual schema definition language file (.csdl) - defines the conceptual model.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="margin-left: 0.5in; text-align: justify; text-indent: -0.25in;font-family:trebuchet ms;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;·&lt;span style="font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style="font-size:100%;"&gt;Store schema definition language file (.ssdl) - defines the storage model, which is also called the logical model.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="margin-left: 0.5in; text-align: justify; text-indent: -0.25in;font-family:trebuchet ms;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;·&lt;span style="font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style="font-size:100%;"&gt;Mapping specification language file (.msl) - defines the mapping between the storage and conceptual models.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;The Entity Framework uses these XML-based models and mapping files to transform create, read, update, and delete operations against entities and relationships in the conceptual model to equivalent operations in the data source. The EDM even supports mapping entities in the conceptual model to stored procedures in the data source.&lt;strong&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;strong&gt;Entity Client&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;: EntityClient is an ADO.NET managed provider that supports accessing data described in an Entity Data Model. The mission of EntityClient is to provide a gateway for &lt;i&gt;entity-level queries&lt;/i&gt;. Through EntityClient one queries against a conceptual model, not against a specific store implementation of that model. EntityClient does not directly communicate with the data store but it requires a separate, store-specific, provider. EntityClient employs its own language, &lt;i&gt;Entity SQL&lt;/i&gt;. An Entity SQL query needs no change in order to work over different store implementations of the same model. That is achieved through EntityClient’s pluggable architecture. Its &lt;i&gt;query pipeline&lt;/i&gt; compiles the Entity SQL text to a &lt;i&gt;command tree&lt;/i&gt; that is passed to the store provider for native SQL generation.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;strong&gt;Entity SQL&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt; &lt;strong&gt;(ESQL)&lt;/strong&gt;: Entity SQL is a derivative of Transact-SQL, designed to query and manipulate entities defined in the Entity Data Model. It supports inheritance and associations. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;strong&gt;LINQ to Entities&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;: This is a strong-typed query language for querying against entities defined in the Entity Data Model.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="text-align: justify;font-family:trebuchet ms;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;Summary&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;span style=";font-family:trebuchet ms;font-size:100%;"  &gt;ORM is the act of connecting object code, whether it is in C#, Java, or any other object-oriented language, to a relational database. This act of mapping is an efficient way to overcome the mismatch that exists between object-oriented development languages and relational databases. Such a mismatch can be classified as an inequality between the native object oriented language operations and functions and those of a relational database. For example, it is impossible to take an object model and save it directly into a database without some manipulation. This occurs because the database doesn’t have the ability to handle inheritance or polymorphism, two basic tenets of object-oriented development. An ORM tool is an excellent solution to overcome the inherent difference between object code and relational databases.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5789460235976325967-6423706680443058314?l=architecturebyashwani.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://architecturebyashwani.blogspot.com/feeds/6423706680443058314/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://architecturebyashwani.blogspot.com/2010/01/speed-up-your-development-using-adonet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default/6423706680443058314'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default/6423706680443058314'/><link rel='alternate' type='text/html' href='http://architecturebyashwani.blogspot.com/2010/01/speed-up-your-development-using-adonet.html' title='Speed up your Development using Ado.Net Entity Framework'/><author><name>Ashwani</name><uri>http://www.blogger.com/profile/11607166212315288799</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_FJo4XM0HhGE/SbItpyV_rwI/AAAAAAAAABY/1WseT6GMmy0/s72-c/Image.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5789460235976325967.post-6648976747870411036</id><published>2010-01-03T23:23:00.001-08:00</published><updated>2010-01-03T23:23:48.171-08:00</updated><title type='text'>Microsoft Identity Model in Web Farm</title><content type='html'>&lt;span xmlns=''&gt;&lt;p&gt;Microsoft Identity Model for claims based authentication uses SessionSecurityTokenHandler to create cookie. This cookie is encrypted using DPAPI. This will not work if you are going to deploy your applications in Webfarm or in general Microsoft Azure platform. To support Web Farm deployment we need to remove the default Cookie Transform used by the Session Security Handler and then add our own customized cookie transform.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;We need to provide two cookie transforms&lt;br /&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;For  encryption based upon the machine key settings&lt;br /&gt;&lt;/li&gt;&lt;li&gt;HMAC-SHA1 cookie transform for tamper proofing of the cookie.&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;In next few days, my team will be providing both the cookie transforms and sample code to demonstrate this.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Thanks,&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Ashwani&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5789460235976325967-6648976747870411036?l=architecturebyashwani.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://architecturebyashwani.blogspot.com/feeds/6648976747870411036/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://architecturebyashwani.blogspot.com/2010/01/microsoft-identity-model-in-web-farm.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default/6648976747870411036'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default/6648976747870411036'/><link rel='alternate' type='text/html' href='http://architecturebyashwani.blogspot.com/2010/01/microsoft-identity-model-in-web-farm.html' title='Microsoft Identity Model in Web Farm'/><author><name>Ashwani</name><uri>http://www.blogger.com/profile/11607166212315288799</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5789460235976325967.post-7754614372231871050</id><published>2010-01-03T23:22:00.000-08:00</published><updated>2010-01-03T23:23:15.406-08:00</updated><title type='text'>Custom Code for SAML 1.1 digital verification</title><content type='html'>Attached is the custom code for Digital verification of SAML 1.1 Token&lt;br /&gt;&lt;br /&gt;&lt;a href="http://ashwanicodesamples.googlecode.com/files/IGroupCustomFormsAuth.zip"&gt;Source Code&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.blogger.com/%20%27http://ashwanicodesamples.googlecode.com/files/IGroupCustomFormsAuth.zip%27"&gt;&lt;br /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5789460235976325967-7754614372231871050?l=architecturebyashwani.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://architecturebyashwani.blogspot.com/feeds/7754614372231871050/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://architecturebyashwani.blogspot.com/2010/01/custom-code-for-saml-11-digital.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default/7754614372231871050'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default/7754614372231871050'/><link rel='alternate' type='text/html' href='http://architecturebyashwani.blogspot.com/2010/01/custom-code-for-saml-11-digital.html' title='Custom Code for SAML 1.1 digital verification'/><author><name>Ashwani</name><uri>http://www.blogger.com/profile/11607166212315288799</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5789460235976325967.post-6330106883663955370</id><published>2010-01-03T23:21:00.000-08:00</published><updated>2010-01-03T23:22:10.732-08:00</updated><title type='text'>WCF Client Authentication using X509 certificates on SSL</title><content type='html'>&lt;p style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;In one of my project; there is a requirement &lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 0.5in; text-align: justify; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;!--[endif]--&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;a. Web Services (WCF) Clients should be authenticated by X509 certificates. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 0.5in; text-align: justify; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;b. Clients should validate the web services using X509 certificate (using &lt;/span&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;SSL). &lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 0.5in; text-align: justify; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=";font-family:Symbol;font-size:100%;"&gt;&lt;span style=""&gt;&lt;span style=";font-family:&amp;quot;;"&gt;c. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;All these services should be built using basicHttpBinding and to be consumed by .Net 2.0 clients.&lt;/span&gt;&lt;/p&gt;  &lt;p style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;I am describing here the complete solution to achieve this and &lt;/span&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;the settings to be done in IIS.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;span style="font-family:Arial;"&gt;SSL Layer: &lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;In order to run web services on SSL; you need to get certificate from the certificate authority like VeriSign; however in development environment someti&lt;/span&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;mes you donot have certificate from valid Authority and need to generate self signed certificate. Microsoft provides a utility to gener&lt;/span&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;ate self signed certificates.&lt;/span&gt;&lt;/p&gt;  &lt;p style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;makecert.exe -r -pe -a sha1 -n CN=”Ent.com” -sr LocalMachine -ss My -sky exchange &lt;/span&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;-b 01/01/2000 -e 01/01/2036 Ent.cer&lt;/span&gt;&lt;/p&gt;  &lt;p style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;The above command creates the self signed certificates and places this certificate in the Local Computer Account under personal store.&lt;/span&gt;&lt;/p&gt;  &lt;p style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;The configuration in IIS is simple as shown below:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 0.5in; text-align: justify; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;span style=""&gt;a.&lt;span style=";font-family:&amp;quot;;"&gt;       &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;Right Click WebSite (say Ent.com, where your &lt;/span&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;WCF services are hosted). Go to properties and then go to Directory Security tab.&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 0.5in; text-align: justify; text-indent: -0.25in;"&gt;&lt;span style="font-size:100%;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_FJo4XM0HhGE/Sk4TaQyHOOI/AAAAAAAAACo/0INYkOF9AsU/s1600-h/image1.PNG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 314px; height: 320px;" src="http://1.bp.blogspot.com/_FJo4XM0HhGE/Sk4TaQyHOOI/AAAAAAAAACo/0INYkOF9AsU/s320/image1.PNG" alt="" id="BLOGGER_PHOTO_ID_5354238348892780770" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 0.25in; text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;span style="font-family:Arial;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shapetype id="_x0000_t75" coordsize="21600,21600" spt="75" preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"&gt;  &lt;v:stroke joinstyle="miter"&gt;  &lt;v:formulas&gt;   &lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;   &lt;v:f eqn="sum @0 1 0"&gt;   &lt;v:f eqn="sum 0 0 @1"&gt;   &lt;v:f eqn="prod @2 1 2"&gt;   &lt;v:f eqn="prod @3 21600 pixelWidth"&gt;   &lt;v:f eqn="prod @3 21600 pixelHeight"&gt;   &lt;v:f eqn="sum @0 0 1"&gt;   &lt;v:f eqn="prod @6 1 2"&gt;   &lt;v:f eqn="prod @7 21600 pixelWidth"&gt;   &lt;v:f eqn="sum @8 21600 0"&gt;   &lt;v:f eqn="prod @7 21600 pixelHeight"&gt;   &lt;v:f eqn="sum @10 21600 0"&gt;  &lt;/v:formulas&gt;  &lt;v:path extrusionok="f" gradientshapeok="t" connecttype="rect"&gt;  &lt;o:lock ext="edit" aspectratio="t"&gt; &lt;/v:shapetype&gt;&lt;v:shape id="_x0000_i1025" type="#_x0000_t75" style="'width:247.5pt;"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\ASHWAN~1.KUM\LOCALS~1\Temp\msohtml1\01\clip_image001.png" title=""&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;br /&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 0.25in; text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;span style="font-family:Arial;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 0.25in; text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;span style="font-family:Arial;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 0.5in; text-align: justify; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;span style=""&gt;b.&lt;span style=";font-family:&amp;quot;;"&gt;       &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;Click Server Certificate button. This will open the wizard to install certificate. Click “Next” and you will see the following screen. Select option “Assign an existing certificate” and click “Next”.&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 0.25in; text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_FJo4XM0HhGE/Sk4TrG7_fnI/AAAAAAAAACw/Yefu51HwQno/s1600-h/image2.PNG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="http://4.bp.blogspot.com/_FJo4XM0HhGE/Sk4TrG7_fnI/AAAAAAAAACw/Yefu51HwQno/s320/image2.PNG" alt="" id="BLOGGER_PHOTO_ID_5354238638307638898" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 0.5in; text-align: justify; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;span style=""&gt;c.&lt;span style=";font-family:&amp;quot;;"&gt;       &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;Now select the certificate you created “Ent.com” and click “Next”.&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_FJo4XM0HhGE/Sk4T-FVFsQI/AAAAAAAAAC4/yEf4d3GVkHg/s1600-h/image3.PNG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 242px;" src="http://2.bp.blogspot.com/_FJo4XM0HhGE/Sk4T-FVFsQI/AAAAAAAAAC4/yEf4d3GVkHg/s320/image3.PNG" alt="" id="BLOGGER_PHOTO_ID_5354238964293546242" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 0.25in; text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1027" type="#_x0000_t75" style="'width:279pt;height:211.5pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\ASHWAN~1.KUM\LOCALS~1\Temp\msohtml1\01\clip_image005.png" title=""&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;br /&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;ol style="margin-top: 0in;" start="4" type="a"&gt;&lt;li class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;Select      the port number (for SSL default is 443) and click finish.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;Now      if you want to enable 128 bit encryption you can edit the certificate      details by clicking “Edit” button on the Directory Security tab and click      the checkbox “Require 128-bit encryption”.&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;span style="font-style: italic;"&gt;Some configuration changes need to be done in web.config file (WCF hosting configuration file). These configuration settings are described at the end of article.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;That’ it you are done with installing SSL. &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;Now you can Add Web Reference in your .Net 2.0 project. However when you try to access the Web Service from your client application you will get the following error:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style="font-family:Arial;"&gt;&lt;br /&gt;“The underlying connection was closed: Could not establish trust relationship for the&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style="font-family:Arial;"&gt; SSL/TLS secure channel.”&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;br /&gt;This exception is raised by client during SSL handshake because Server certificate is not issued b&lt;/span&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;y valid Authority.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;In order to fix this problem, you need to tell client that it allows your certificate. The following code needs to be written and called before calling the service method.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;protected&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; button1_Click(&lt;span style="color:blue;"&gt;object&lt;/span&gt; sender, &lt;span style="color: rgb(43, 145, 175);"&gt;EventArgs&lt;/span&gt; e)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Testing.&lt;span style="color: rgb(43, 145, 175);"&gt;Service&lt;/span&gt; service1 = &lt;span style="color:blue;"&gt;new&lt;/span&gt; Testing.&lt;span style="color: rgb(43, 145, 175);"&gt;Service&lt;/span&gt;();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;ServicePointManager&lt;/span&gt;.ServerCertificateValidationCallback += &lt;span style="color:blue;"&gt;new&lt;/span&gt; System.Net.Security.&lt;span style="color: rgb(43, 145, 175);"&gt;RemoteCertificateValidationCallback&lt;/span&gt;(customCertificateValidation);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;string&lt;/span&gt; data = service1.GetData(5, &lt;span style="color:blue;"&gt;true&lt;/span&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;label1.Text = data;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;b style=""&gt;&lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;bool&lt;/span&gt; customCertificateValidation(&lt;span style="color:blue;"&gt;object&lt;/span&gt; sender, &lt;span style="color: rgb(43, 145, 175);"&gt;X509Certificate&lt;/span&gt; cert, &lt;span style="color: rgb(43, 145, 175);"&gt;X509Chain&lt;/span&gt; chain, System.Net.Security.&lt;span style="color: rgb(43, 145, 175);"&gt;SslPolicyErrors&lt;/span&gt; error)&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;"&gt;&lt;span style=""&gt;    &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:green;"&gt;//analyze the certificate and then return true.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; &lt;span style="color:blue;"&gt;true&lt;/span&gt;;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;"&gt;&lt;span style=""&gt;    &lt;/span&gt;}&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style="font-family:Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;The custom certificate validation method allows clients applications to decide which server certificates they can trust. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;Note: Allowing self signed certificates is not recommended in Production environment.&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;span style=""&gt; &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style="font-family:Arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style="font-family:Arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style="font-family:Arial;"&gt;X509 Client Certificate Authentication:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;The next thing to do is client authentication using X509 certificates. In order to do this you need to change configuration in IIS and also in web.config file.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;i style=""&gt;&lt;span style="font-family:Arial;"&gt;IIS settings&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 0.5in; text-align: justify; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;span style=""&gt;a.&lt;span style=";font-family:&amp;quot;;"&gt;       &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;Right Click web site (say Ent.com). Go to properties and then go to Directory Security tab.&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_FJo4XM0HhGE/Sk4UV6TOveI/AAAAAAAAADA/KTTk5dafit8/s1600-h/image4.PNG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 315px; height: 320px;" src="http://2.bp.blogspot.com/_FJo4XM0HhGE/Sk4UV6TOveI/AAAAAAAAADA/KTTk5dafit8/s320/image4.PNG" alt="" id="BLOGGER_PHOTO_ID_5354239373649821154" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;span style="font-family:Arial;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1028" type="#_x0000_t75" style="'width:240pt;height:243pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\ASHWAN~1.KUM\LOCALS~1\Temp\msohtml1\01\clip_image007.png" title=""&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;br /&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;span style="font-family:Arial;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 0.5in; text-align: justify; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;span style=""&gt;b.&lt;span style=";font-family:&amp;quot;;"&gt;       &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;Click Edit button and then on “Client Certificate” Section select the option “Require client certificates”&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_FJo4XM0HhGE/Sk4Uq1I1fMI/AAAAAAAAADI/QYYgks4digs/s1600-h/image5.PNG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 318px; height: 320px;" src="http://1.bp.blogspot.com/_FJo4XM0HhGE/Sk4Uq1I1fMI/AAAAAAAAADI/QYYgks4digs/s320/image5.PNG" alt="" id="BLOGGER_PHOTO_ID_5354239733041298626" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 0.25in; text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;span style="font-family:Arial;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1029" type="#_x0000_t75" style="'width:228.75pt;height:229.5pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\ASHWAN~1.KUM\LOCALS~1\Temp\msohtml1\01\clip_image009.png" title=""&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;br /&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;i style=""&gt;&lt;span style="font-family:Arial;"&gt;Client Side Changes&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;Now when you call the web service you need to provide client Certificate. Here is the code:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;i style=""&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;protected&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; button1_Click(&lt;span style="color:blue;"&gt;object&lt;/span&gt; sender, &lt;span style="color: rgb(43, 145, 175);"&gt;EventArgs&lt;/span&gt; e)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Testing.&lt;span style="color: rgb(43, 145, 175);"&gt;Service&lt;/span&gt; service1 = &lt;span style="color:blue;"&gt;new&lt;/span&gt; Testing.&lt;span style="color: rgb(43, 145, 175);"&gt;Service&lt;/span&gt;();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;b style=""&gt;&lt;span style="color:green;"&gt;//As an example loading certificate from file system.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;X509Certificate&lt;/span&gt; cert = &lt;span style="color: rgb(43, 145, 175);"&gt;X509Certificate2&lt;/span&gt;.CreateFromCertFile(&lt;span style="color: rgb(163, 21, 21);"&gt;@"C:\Test1.cer"&lt;/span&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;"&gt;&lt;span style=""&gt;        &lt;/span&gt;service1.ClientCertificates.Add(cert); &lt;span style="color:green;"&gt;//adding cleint certificate.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;ServicePointManager&lt;/span&gt;.ServerCertificateValidationCallback += &lt;span style="color:blue;"&gt;new&lt;/span&gt; System.Net.Security.&lt;span style="color: rgb(43, 145, 175);"&gt;RemoteCertificateValidationCallback&lt;/span&gt;(customXertificateValidation);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;string&lt;/span&gt; data = service1.GetData(5, &lt;span style="color:blue;"&gt;true&lt;/span&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;label1.Text = data;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;bool&lt;/span&gt; customXertificateValidation(&lt;span style="color:blue;"&gt;object&lt;/span&gt; sender, &lt;span style="color: rgb(43, 145, 175);"&gt;X509Certificate&lt;/span&gt; cert, &lt;span style="color: rgb(43, 145, 175);"&gt;X509Chain&lt;/span&gt; chain, System.Net.Security.&lt;span style="color: rgb(43, 145, 175);"&gt;SslPolicyErrors&lt;/span&gt; error)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:green;"&gt;//analyze the certificate and then return true.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; &lt;span style="color:blue;"&gt;true&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.25in; text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;}&lt;/span&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.25in; text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;The “Test1” certificate used here is self signed certificate. In production environment this certificate should be issued by valid authority. However to fix the problem in development environment you need to add the certificate in the “Trusted Root Certification Authorities” on you WCF hosting machine.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.25in; text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;i style=""&gt;&lt;span style="font-family:Arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;i style=""&gt;&lt;span style="font-family:Arial;"&gt;Web.config changes:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;The complete config file is:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.25in; text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;system.serviceModel&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;services&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                  &lt;/span&gt;&lt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;service&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt; &lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:red;"&gt;name&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;=&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;"&lt;span style="color:blue;"&gt;Service&lt;/span&gt;"&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;behaviorConfiguration&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;"&lt;span style="color:blue;"&gt;ServiceBehavior&lt;/span&gt;"&lt;span style="color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                        &lt;/span&gt;&lt;!--&lt;/span&gt;&lt;span style=" Courier New&amp;quot;; font-family:&amp;quot;font-size:10pt;color:green;"&gt; Service Endpoints &lt;/span&gt;&lt;span style=" Courier New&amp;quot;; font-family:&amp;quot;font-size:10pt;color:blue;"&gt;--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                        &lt;/span&gt;&lt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;endpoint&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt; &lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:red;"&gt;address&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;=&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;"&lt;span style="color:blue;"&gt;https://Ent.com/Services/Service.svc&lt;/span&gt;"&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;binding&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;"&lt;span style="color:blue;"&gt;basicHttpBinding&lt;/span&gt;"&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;contract&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;"&lt;span style="color:blue;"&gt;IService&lt;/span&gt;"&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;bindingConfiguration&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;"&lt;span style="color:blue;"&gt;Binding&lt;/span&gt;"&lt;span style="color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                              &lt;/span&gt;&lt;!--&lt;/span&gt;&lt;span style=" Courier New&amp;quot;; font-family:&amp;quot;font-size:10pt;color:green;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=" Courier New&amp;quot;; font-family:&amp;quot;font-size:10pt;color:green;"&gt;&lt;span style=""&gt;              &lt;/span&gt;Upon deployment, the following identity element should be removed or replaced to reflect the &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=" Courier New&amp;quot;; font-family:&amp;quot;font-size:10pt;color:green;"&gt;&lt;span style=""&gt;              &lt;/span&gt;identity under which the deployed service runs.&lt;span style=""&gt;  &lt;/span&gt;If removed, WCF will infer an appropriate identity &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=" Courier New&amp;quot;; font-family:&amp;quot;font-size:10pt;color:green;"&gt;&lt;span style=""&gt;              &lt;/span&gt;automatically.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=" Courier New&amp;quot;; font-family:&amp;quot;font-size:10pt;color:green;"&gt;&lt;span style=""&gt;          &lt;/span&gt;&lt;/span&gt;&lt;span style=" Courier New&amp;quot;; font-family:&amp;quot;font-size:10pt;color:blue;"&gt;--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                              &lt;/span&gt;&lt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;identity&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                                    &lt;/span&gt;&lt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;dns&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt; &lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:red;"&gt;value&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;=&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;"&lt;span style="color:blue;"&gt;localhost&lt;/span&gt;"&lt;span style="color:blue;"&gt;/&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                              &lt;/span&gt;&lt;!--&lt;/span--&gt;&lt;span style=";font-family:&amp;quot;;"&gt;identity&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                        &lt;/span&gt;&lt;!--&lt;/span--&gt;&lt;span style=";font-family:&amp;quot;;"&gt;endpoint&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                        &lt;/span&gt;&lt;b style=""&gt;&lt;!--&lt;/b&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style=" Courier New&amp;quot;; font-family:&amp;quot;font-size:10pt;color:green;"&gt;&lt;endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"&gt;&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style=" Courier New&amp;quot;; font-family:&amp;quot;font-size:10pt;color:blue;"&gt;--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                  &lt;/span&gt;&lt;!--&lt;/span--&gt;&lt;span style=";font-family:&amp;quot;;"&gt;service&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;!--&lt;/span--&gt;&lt;span style=";font-family:&amp;quot;;"&gt;services&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;behaviors&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                  &lt;/span&gt;&lt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;serviceBehaviors&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                        &lt;/span&gt;&lt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;behavior&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt; &lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:red;"&gt;name&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;=&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;"&lt;span style="color:blue;"&gt;ServiceBehavior&lt;/span&gt;"&lt;span style="color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                              &lt;/span&gt;&lt;!--&lt;/span&gt;&lt;span style=" Courier New&amp;quot;; font-family:&amp;quot;font-size:10pt;color:green;"&gt; To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment &lt;/span&gt;&lt;span style=" Courier New&amp;quot;; font-family:&amp;quot;font-size:10pt;color:blue;"&gt;--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                              &lt;/span&gt;&lt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;serviceMetadata&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt; &lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:red;"&gt;httpsGetEnabled&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;=&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;"&lt;span style="color:blue;"&gt;true&lt;/span&gt;"&lt;span style="color:blue;"&gt;/&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                              &lt;/span&gt;&lt;!--&lt;/span&gt;&lt;span style=" Courier New&amp;quot;; font-family:&amp;quot;font-size:10pt;color:green;"&gt; To receive exception details in faults for debugging purposes, set the value below to true.&lt;span style=""&gt;  &lt;/span&gt;Set to false before deployment to avoid disclosing exception information &lt;/span&gt;&lt;span style=" Courier New&amp;quot;; font-family:&amp;quot;font-size:10pt;color:blue;"&gt;--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                              &lt;/span&gt;&lt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;serviceDebug&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt; &lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:red;"&gt;includeExceptionDetailInFaults&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;=&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;"&lt;span style="color:blue;"&gt;true&lt;/span&gt;"&lt;span style="color:blue;"&gt;/&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                        &lt;/span&gt;&lt;!--&lt;/span--&gt;&lt;span style=";font-family:&amp;quot;;"&gt;behavior&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                  &lt;/span&gt;&lt;!--&lt;/span--&gt;&lt;span style=";font-family:&amp;quot;;"&gt;serviceBehaviors&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;!--&lt;/span--&gt;&lt;span style=";font-family:&amp;quot;;"&gt;behaviors&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;bindings&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                  &lt;/span&gt;&lt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;basicHttpBinding&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                        &lt;/span&gt;&lt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;binding&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt; &lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:red;"&gt;name&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;=&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;"&gt;"&lt;span style="color:blue;"&gt;Binding&lt;/span&gt;"&lt;span style="color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                              &lt;/span&gt;&lt;b style=""&gt;&lt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;"&gt;security&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt; &lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;color:red;"&gt;mode&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;=&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;"&gt;"&lt;span style="color:blue;"&gt;Transport&lt;/span&gt;"&lt;span style="color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;&lt;span style=""&gt;                                    &lt;/span&gt;&lt;&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;"&gt;transport&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt; &lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;color:red;"&gt;clientCredentialType&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;=&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;"&gt;"&lt;span style="color:blue;"&gt;Certificate&lt;/span&gt;"&lt;span style="color:blue;"&gt;/&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;&lt;span style=""&gt;                              &lt;/span&gt;&lt;!--&lt;/span--&gt;&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;"&gt;security&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                        &lt;/span&gt;&lt;!--&lt;/span--&gt;&lt;span style=";font-family:&amp;quot;;"&gt;binding&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;                  &lt;/span&gt;&lt;!--&lt;/span--&gt;&lt;span style=";font-family:&amp;quot;;"&gt;basicHttpBinding&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;!--&lt;/span--&gt;&lt;span style=";font-family:&amp;quot;;"&gt;bindings&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.25in; text-align: justify;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;span style=""&gt;   &lt;/span&gt;&lt;!--&lt;/span--&gt;&lt;span style=";font-family:&amp;quot;;"&gt;system.serviceModel&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;&gt;&lt;/span&gt;&lt;span style="font-family:Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.25in; text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;Description:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;ul style="margin-top: 0in;" type="disc"&gt;&lt;li class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;In      order to use SSL you need to tell that you are using transport layer      security using the tag.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify; text-indent: 0.5in;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;          &lt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;"&gt;security&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt; &lt;/span&gt;&lt;span style=";font-family:&amp;quot;;color:red;"&gt;mode&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;=&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;"&gt;"&lt;span style="color:blue;"&gt;Transport&lt;/span&gt;"&lt;span style="color:blue;"&gt;&gt;&lt;!--&lt;/span--&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;security&lt;/span&gt;&lt;span style="color:blue;"&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;"&gt;&lt;span style="color:blue;"&gt;&lt;span style="color:blue;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify; text-indent: 0.5in;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;ul style="margin-top: 0in;" type="disc"&gt;&lt;li class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;In order to use client      certificates for authentication you need to specify ClientCertificateType      as Certificate&lt;/span&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify; text-indent: 0.5in;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;          &lt;/span&gt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;"&gt;security&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt; &lt;/span&gt;&lt;span style=";font-family:&amp;quot;;color:red;"&gt;mode&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;=&lt;/span&gt;"&lt;span style="color:blue;"&gt;Transport&lt;/span&gt;"&lt;span style="font-size:100%;"&gt;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;              &lt;span style=";font-family:&amp;quot;;color:blue;"&gt;&lt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;"&gt;transport&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt; &lt;/span&gt;&lt;span style=";font-family:&amp;quot;;color:red;"&gt;clientCredentialType&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;=&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;"&gt;"&lt;span style="color:blue;"&gt;Certificate&lt;/span&gt;"&lt;span style="color:blue;"&gt;/&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;         &lt;span style=";font-family:&amp;quot;;font-size:100%;color:blue;"&gt;&lt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=";font-family:&amp;quot;;"&gt;security&lt;/span&gt;&lt;/span&gt;/&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=";font-family:&amp;quot;;"&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;          &lt;p class="MsoNormal" style="margin-left: 0.5in; text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-left: 0.5in; text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;However after changes these settings when you try to run the application you will get strange error saying:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.5in; text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;“&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;i&gt;Client found response content type of '', but expected 'text/xml'.&lt;br /&gt;The request failed with an empty response.&lt;/i&gt;&lt;/span&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;”&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify; text-indent: 0.5in;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;In order to fix this error you need to comment the following line in web.config file&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.5in; text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;color:blue;"&gt;&lt;!--&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style=" Courier New&amp;quot;; font-family:&amp;quot;font-size:10pt;color:green;"&gt;&lt;endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"&gt;&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style=" Courier New&amp;quot;; font-family:&amp;quot;font-size:10pt;color:blue;"&gt;--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-left: 0.5in; text-align: justify;"&gt;&lt;b style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;color:blue;"&gt;&lt;!--&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style=" Courier New&amp;quot;; font-family:&amp;quot;font-size:10pt;color:green;"&gt;&lt;endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"&gt;&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style=" Courier New&amp;quot;; font-family:&amp;quot;font-size:10pt;color:blue;"&gt;--&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt; ! - - &lt; address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"&gt;- - &gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;That’s all. Now you can use WCF services from .Net 2.0 clients on SSL and using client certificate authentication.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;The complete Code can be downloaded from &lt;a href="http://ashwanicodesamples.googlecode.com/files/WCFSSL_CertClientAuth.zip"&gt;here&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;You can generate the certificate using Microsoft tool as described above.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;Ashwani Kumar&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;Solutions Architect&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style=";font-family:Arial;font-size:100%;"&gt;Globallogic Inc.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5789460235976325967-6330106883663955370?l=architecturebyashwani.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://architecturebyashwani.blogspot.com/feeds/6330106883663955370/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://architecturebyashwani.blogspot.com/2010/01/wcf-client-authentication-using-x509.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default/6330106883663955370'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default/6330106883663955370'/><link rel='alternate' type='text/html' href='http://architecturebyashwani.blogspot.com/2010/01/wcf-client-authentication-using-x509.html' title='WCF Client Authentication using X509 certificates on SSL'/><author><name>Ashwani</name><uri>http://www.blogger.com/profile/11607166212315288799</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_FJo4XM0HhGE/Sk4TaQyHOOI/AAAAAAAAACo/0INYkOF9AsU/s72-c/image1.PNG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5789460235976325967.post-2463758762816716177</id><published>2009-07-04T19:38:00.000-07:00</published><updated>2009-11-20T16:53:14.980-08:00</updated><title type='text'>Who should use Cloud?</title><content type='html'>&lt;span style="font-size:100%;"&gt;This question comes to everyone these days when big companies like Microsoft, Amazon, Google and others are spending a lot on cloud infrastructure. So the thoughts start coming in our mind: should we use cloud computing? Will it benefit our company over traditional way of developing and hosting??&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;p&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;Let’s start dissecting the cloud:-&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;What is cloud?&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;b&gt;&lt;span style="color:black;"&gt;Cloud computing&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span class="apple-converted-space"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;is a style of computing in which dynamically&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;scalable&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;and often virtualized&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;resources are provided&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;as a service&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;over the&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;Internet.&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-converted-space"  style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;Cloud services can be classified into three categories: Infrastructure-as-a-Service (IaaS), Platform-as-a-Service (PaaS) and Software-as-a-Service (SaaS). In this article we will talk about Infrastructure services.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;Though many companies are jumping into cloud service provider bandwagon but Amazon has been one of the oldest in the business and provides services which support innumerable functionalities and are easy to use.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;Infrastructure Services by Amazon provides virtual server instances with unique&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;IP addresses and blocks of storage on demand. Customers use application program interface (API) to start, stop, access and configure their virtual servers and storage.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;b&gt;&lt;i&gt;&lt;span style="color:black;"&gt;Overview of Amazon Infrastructure Services&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;b&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;It provides the following services:-&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;b&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;b&gt;&lt;span style="color:black;"&gt;Simple Storage Service (S3):&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt; This service provides secure online storage space for any kind of data. There is no limit how much data you can store in S3. You can also control the bandwidth to use for transfer of data. The important point is that you do not need to pay upfront for large storage space. As your data grows you pay more.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;S3 is scalable and distributed and stores your data reliably across multiple data centers of Amazon.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;b&gt;&lt;span style="color:black;"&gt;Amazon Elastic Compute Cloud (EC2):&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;This service allows you to run multiple virtual machines (Linux or Windows) on demand. The service allows you to create resizable pool of servers for handling computing tasks. You can increase or decrease the number of servers as per demand. The cost will be calculated based upon the usage of the servers on hourly basis. The APIs to start, stop and configure the virtual machines are very simple and you can easily control them.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-converted-space"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;EC2 helps startups companies and online entrepreneurs to build applications that can scale from 0 to 5 million hits in just few weeks without worrying how to manage the scalability and reliability of the application. As the load increases you can add more servers and delete when not required. Suppose you are hosting an event and that is expected large number of hits; so you can add more servers and release when event is over.&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;b&gt;&lt;span style="color:black;"&gt;Amazon Simple Queue Service (SQS):&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;SQS delivers messages between computers/ systems allowing distributed applications to communicate reliably. SQS is implemented as a distributed application in Amazon and your messages are stored redundantly across multiple servers and data centers.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;b&gt;&lt;span style="color:black;"&gt;Amazon SimpleDB&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;Amazon SimpleDB stores the small pieces of information in a database structure that is easy to manage, modify and search. It indexes every piece of information you store so all your queries run quickly.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-converted-space"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;All the services provided by Amazon are easy to use and have benefits for all categories of organizations (small, large etc.).&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"  style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-converted-space"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;b&gt;&lt;span style="color:black;"&gt;Startup&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt; companies can go to market fast by deploying their applications on the Cloud (EC2). Imagine you can have your Web Server ready in 10-15 minutes without spending time to think on which machine to buy, placing an order and then worrying about having it installed and hiring a person to look after it. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;Well, the services are cheap and are absolutely in reach of the startups.&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;For &lt;b&gt;Large&lt;/b&gt; companies whose applications are already used by millions of users and whose users are continuously growing; it provides an enormously large storage capacity. They needn’t to fall into buying and installing data server troubles. They can host the applications on the cloud and get benefits of scalability and reliability EC2 provides. EC2 lets you to host your applications in &lt;st1:place st="on"&gt;Europe&lt;/st1:place&gt; and US; so you can replicate your data in different geographical zones and deal with the risk of failure in one zone. &lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;It prevents the company from worst web challenges like power failures, cable cuts, earthquakes etc. &lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;A cloud service has three distinct characteristics that differentiate it from traditional hosting. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;ul  style="margin-top: 0in;font-family:arial;" type="disc"&gt;&lt;li class="MsoNormal"  style="text-align: justify;color:black;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;It is sold on demand, typically by the minute or the hour.&lt;/span&gt; &lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal"  style="text-align: justify;color:black;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;It is elastic; a user can have as much or as little of a service as they want at any given time. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal"  style="text-align: justify;color:black;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;Significant innovations in virtualization and distributed computing, as well as improved access to high-speed Internet and a weak economy, have accelerated interest in cloud computing.&lt;/span&gt;&lt;span class="apple-converted-space"  style="font-size:100%;"&gt; &lt;/span&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;i&gt;The "Elastic" nature of the service allows developers to instantly scale to meet spikes in traffic or demand. When computing requirements unexpectedly change (up or down), Amazon EC2 can instantly respond, meaning that developers have the ability to control how many resources are in use at any given point in time.&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;" face="arial"&gt;Ashwani Kumar&lt;br /&gt;Solutions Architect&lt;br /&gt;Globallogic Inc.&lt;br /&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="text-align: justify;font-family:arial;"&gt;&lt;br /&gt;&lt;span class="apple-style-span"  style="font-size:100%;"&gt;&lt;span style="color:black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5789460235976325967-2463758762816716177?l=architecturebyashwani.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://architecturebyashwani.blogspot.com/feeds/2463758762816716177/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://architecturebyashwani.blogspot.com/2009/07/who-should-use-cloud.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default/2463758762816716177'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default/2463758762816716177'/><link rel='alternate' type='text/html' href='http://architecturebyashwani.blogspot.com/2009/07/who-should-use-cloud.html' title='Who should use Cloud?'/><author><name>Ashwani</name><uri>http://www.blogger.com/profile/11607166212315288799</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5789460235976325967.post-7251088361410157115</id><published>2009-05-30T09:45:00.000-07:00</published><updated>2009-05-30T11:02:22.412-07:00</updated><title type='text'>SOAP VS REST Web Services</title><content type='html'>&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;b style=""&gt;SOAP or REST WebServices&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;When we start designing the Architecture of any Web Application, architects generally think what to choose? REST or SOAP&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;In this blog I am going to describe few design principles based upon which you can choose either SOAP or REST&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;b style=""&gt;History of WebServices&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;Webservices were built in the last 10-15 years in layers, where each layer resolves some of the technical issues faced by architects. It started when people think that we can use internet to transfer the data internally or globally. The process started with the use of HTTP protocol. However this protocol is restricted in some ways and thus big software companies spending their time in building a new protocol SOAP (Simple Object Access Protocol) which extends the HTTP capabilities to allow objects to be called remotely over HTTP. This protocol was a big success and lot of internet applications started using this. However as applications required more and more capabilities from the protocol one more layer was added in 2005 WS*. As the research in this subject goes on, we might see few more layers on this in coming years. If, SOAP webservices are built from the last so many years and have lot of capabilities then why some of the architects not prefer these? The answer is: to create a simple SOAP webservice we need to understand various protocols and architecture styles and this caused some of the developers to ignore the new technology/ standards and continue to use what they know.&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;The other issue is the wrong usage of Http verb in SOAP. The webservice Soap requests use the HTTP POST verb to transport request to the end points for the operations. Now if the method is just retrieving the records, then this should be GET. SOAP resolves this issue by having the standards naming conventions for the retrieval method by naming them as &lt;i style=""&gt;Get&lt;/i&gt;Customers (prefeixing the methods with Get) but this is in the hands of developers.&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;Now REST (Representational State Transfer) Services: some researchers tell that REST should be the only design applied to the HTTP based services.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;The greatest asset of REST based service is its pure elegance and its simplicity. REST is based upon the Resource Oriented Architecture. &lt;span style=""&gt;REST services do not require you to design your own service contracts, because you can rely on HTTP verbs to describe intent. This radically simplifies your service’s design. HTTP defines the verbs GET, PUT, POST, and DELETE. By using these built- in verbs, REST services provide access to resources via a Uniform Resource Indicator (URI) and an HTTP verb.&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;Now the question is which technology to choose. Well both has some advantages and some disadvantages. In most of the cases I would prefer REST because these are simple and what I believe is that “Simplicity is the key to success for big applications”. Does that mean it is end for SOAP, Not really. There are some cases where you might need to use SOAP because REST is somewhat limited, like you don’t have duplex message exchange pattern in REST. &lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;Here are few of the things not supported by REST but available in SOAP.&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;REST only supports text based encoding whereas SOAP supports other encodings binary&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;REST doesnot support duplex message exchange pattern which is available in WS*&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;Only transport security is available in REST whereas WS* supports additional like WS-Security, WS-SecureConversation etc.&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;I am concluding on the blog by saying: This is very important for architects to choose the right approach for building services but always focus to keep things simple but secure so that community can consume your services easily. In my coming blogs I will focus on Ado.Net Data Services (Astoria), one of the very good project by Microsoft which allow us to create REST services. (generally we found Microsoft introducing complexity with every new release but this time things are changed and Microsoft is looking for simplicity and understanding the needs of the industry well.)&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5789460235976325967-7251088361410157115?l=architecturebyashwani.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://architecturebyashwani.blogspot.com/feeds/7251088361410157115/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://architecturebyashwani.blogspot.com/2009/05/soap-vs-rest-web-services.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default/7251088361410157115'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5789460235976325967/posts/default/7251088361410157115'/><link rel='alternate' type='text/html' href='http://architecturebyashwani.blogspot.com/2009/05/soap-vs-rest-web-services.html' title='SOAP VS REST Web Services'/><author><name>Ashwani</name><uri>http://www.blogger.com/profile/11607166212315288799</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>
