in Education by

What is Exception Handling in WCF? What are the ways for WCF Exception Handling?

1 Answer

0 votes
by

Exception handling is critical to all applications for troubleshooting the unexpected problems in applications. The Windows Communication Framework (WCF) provides several options for handling exceptions in WCF services. This article discusses these approaches and describes the advantages and disadvantages of each. The following options are provided to handle exceptions in WCF:

  1. Using returnUnknownExceptionsAsFaults: Debugging Mode
  2. Using FaultException: Best Option.
  3. Using IErrorHandler: Only when the exception can't be handled by Fault

Exception handling in WCF

Exception handling in WCF

Exceptions inside a WCF Service

Before describing the details of exception handling in WCF, let's explore what happens if we do not handle an exception inside the service. Consider a service with the CreateUser method as shown in the following:

  1. public void CreateUser(User user)  
  2. {  
  3.     if(user.isValid())  
  4.     {  
  5.         //Create User   
  6.     }  
  7.     else  
  8.     {  
  9.         throw new ApplicationException(“User Inavalid.”);  
  10.     }  
  11. }  

Example

  1. public class DBManagerService: IDBManagerService  
  2.   
  3. void Save(Employee emp)  
  4. {  
  5.     try  
  6.     {  
  7.         //Code to store an employee object to the database  
  8.     }  
  9.     catch (Exception ex  
  10.         {  
  11.             throw new Exception(“Error occurred  
  12.                 while saving data…”);  
  13.         }  
  14.     }  
  15. }  

Related questions

0 votes
    What you understand by Fault Exception in WCF?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    What are the possible ways of hosting a WCF service?...
asked Apr 2, 2021 in Education by JackTerrance
0 votes
    What is Security Implementation in WCF? How many are there?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    What is WCF Concurrency and How many modes are of Concurrency in WCF?...
asked Apr 2, 2021 in Education by JackTerrance
0 votes
    What are the main components of WCF Service?...
asked Apr 2, 2021 in Education by JackTerrance
0 votes
    What is Binding in WCF?What are the types of binding?...
asked Apr 2, 2021 in Education by JackTerrance
0 votes
    What are Contracts in WCF? How many Contracts are in WPF?...
asked Apr 2, 2021 in Education by JackTerrance
0 votes
    What is Information cards in WCF?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    What is Instance Management in WCF?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    What is Duplex in WCF? Explain also Message Exchange Pattern?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    What is WCF Messaging Layer?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    What is Method overloading in WCF?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    What is MSMQ in WCF?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    Explain bindings in WCF with description?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    Explain briefly different Instance Modes in WCF?...
asked Apr 3, 2021 in Education by JackTerrance
...