You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
You deploy a Windows Communication Foundation (WCF) Data Service to a production server.
The application is hosted by Internet Information Services (IIS).
After deployment, applications that connect to the service receive the following error message:
“The server encountered an error processing the request. See server logs for more details.”
You need to ensure that the actual exception data is provided to client computers. What should you do?
A.
Modify the application’s Web.config file. Set the value for the customErrors element to Off.
B.
Modify the application’s Web.config file. Set the value for the customErrors element to RemoteOnly.
C.
Add the FaultContract attribute to the class that implements the data service.
D.
Add the ServiceBehavior attribute to the class that implements the data service.
Explanation:
Apply the ServiceBehaviorAttribute attribute to a service implementation to specify service-wide execution behavior.
The IncludeExceptionDetailInFaults property specifies whether unhandled exceptions in a service are returned as SOAP faults. This is for debugging purposes only.ServiceBehavior Attribute
(http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.aspx)FaultContract Attribute
(http://msdn.microsoft.com/en-us/library/ms752208.aspx)[ServiceContract(Namespace=”http://Microsoft.ServiceModel.Samples”)]
public interface ICalculator
{
[OperationContract]
int Add(int n1, int n2);
[OperationContract]
int Subtract(int n1, int n2);
[OperationContract]
int Multiply(int n1, int n2);
[OperationContract]
[FaultContract(typeof(MathFault))]
int Divide(int n1, int n2);
}
The FaultContractAttribute attribute indicates that the Divide operation may return a fault of type MathFault. A fault can be of any type that can be serialized. In this case, the MathFault is a data contract, as follows:[DataContract(Namespace=”http://Microsoft.ServiceModel.Samples”)]
public class MathFault
{
private string operation;
private string problemType;[DataMember]
public string Operation
{
get { return operation; }
set { operation = value; }
}[DataMember]
public string ProblemType
{
get { return problemType; }
set { problemType = value; }
}
}
The full answer should be to add [ServiceBehavior(IncludeExceptionDetailInFaults=true)] to the class that implements the data service.
http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.includeexceptiondetailinfaults.aspx
This behavior can also be configured administratively in the web.config file:
http://msdn.microsoft.com/en-us/library/ff649234.aspx