What should you do?

You are creating a Windows Communication Foundation (WCF) service that is implemented as follows.
(Line numbers are included for reference only.)

01 [ServiceContract]
02 [ServiceBehavior(IncludeExceptionDetailsInFaults = true)]
03 public class OrderService
04 {
05 [OperationContract]
06 public void SubmitOrder(Order anOrder)
07 {
08 try
09 {
10 …
11 }
12 catch(DivideByZeroException ex)
13 {
14 …
15 }
16 }
17 }

You need to ensure that the stack trace details of the exception are not included in the error information sent to the client.
What should you do?

You are creating a Windows Communication Foundation (WCF) service that is implemented as follows.
(Line numbers are included for reference only.)

01 [ServiceContract]
02 [ServiceBehavior(IncludeExceptionDetailsInFaults = true)]
03 public class OrderService
04 {
05 [OperationContract]
06 public void SubmitOrder(Order anOrder)
07 {
08 try
09 {
10 …
11 }
12 catch(DivideByZeroException ex)
13 {
14 …
15 }
16 }
17 }

You need to ensure that the stack trace details of the exception are not included in the error information sent to the client.
What should you do?

A.
Replace line 14 with the following line:
throw;

B.
Replace line 14 with the following line:
throw new FaultException<Order>(anOrder, ex.ToString());

C.
After line 05, add the following line:
[FaultContract(typeof(FaultException<Order>))]
Replace line 14 with the following line:
throw ex;

D.
Alter line 05, add the following line:
[FaultContract(typeof(FaultException<Order>))]
Replace line 14 with the following line:
throw new FaultException<Order>(anOrder, “Divide by zero exception”);

Explanation:
Typical deployed services use the FaultContractAttribute to formally specify all SOAP faults
that a client can expect to receive in the normal course of an operation.
Error information in a FaultContractAttribute appears as a FaultException<TDetail>
(where the typeparameter is the serializable error object specified in the operation’s FaultContractAttribute)
when it arrives at a client application.
The FaultContractAttribute can be used to specify SOAP faults for both two-way service methods and for asynchronous method pairs.

Because FaultException<TDetail> is both a FaultException and therefore a CommunicationException,
to catch specified SOAP faults make sure you catch the FaultException<TDetail> types prior to the FaultException
and CommunicationException types or handle the specified exceptions in one of those exception handlers.

FaultException<TDetail> Class
(http://msdn.microsoft.com/en-us/library/ms576199.aspx)



Leave a Reply 1

Your email address will not be published. Required fields are marked *