Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Best practice is to implement IErrorHandler. This is because:</p> <ol> <li><strong>Your code isn’t the only potential source of exceptions.</strong> The methods you call (or a bug) might result in a .NET Exception. If you don’t handle that exception somewhere and aren’t using <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.includeexceptiondetailinfaults.aspx" rel="nofollow">IncludeExceptionDetailInFaults</a> (which you shouldn't in production) this will look like a service crash. </li> <li><strong>Separation of Concerns</strong>: Any business layer called by the service code should not reference WCF (<code>System.ServiceModel</code>) and therefore should be throwing standard .NET exceptions. Keeping the business layer unaware of how its hosted makes it more portable and more testable.</li> <li>[<code>FaultContract</code>] types need to be specified on the [<code>OperationContract</code>]. In larger applications you want the Fault generation to be centralized… In other words know that a particular IErrorHandler returns a particular set of Faults so that you can validate the Contracts Faults types are right. Throwing a Fault type that the contract’s method does not explicitly support is a nasty runtime error.</li> </ol> <p>You could copy and paste a try/catch block in all your service methods to throw a FaultException, but it’s a horrible code smell and is the exact functionality that IErrorHandler is giving you as a behavior. So use IErrorHandler instead.</p> <p>Combining the two models is possible. For example have IErrorHandler process FaultExceptions as needed, but this is not a common practice. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload