Showing posts with label IncludeExceptionDetailInFaults. Show all posts
Showing posts with label IncludeExceptionDetailInFaults. Show all posts

Monday, January 10, 2011

Turn on IncludeExceptionDetailInFaults while connecting to a WCF service from a client.

While using a client to connect and fetch data from a WCF service, you may encounter an error and see the following message displayed on the screen:

Error: The server was unable to process the request due to an internal error.
For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.System.Exception {System.ServiceModel.FaultException}

This happens when any type of error occurs calling a WCF endpoint from a client. The client sees this generic message, as given above, for security reason. If you want to see the full details of the error in the client, you will need to modify the config file of the WCF Host to include full exception details when sending the error to the client.
1.<configuration>
2.<system.serviceModel> 
3.  <services> 
4.    <!-- Step 1. Add a behaviorConfiguration attribute --> 
5.    <service 
6.      name="Microsoft.WCF.Documentation.SampleService" 
7.      behaviorConfiguration="metadataAndDebug"> 
8.      <host> 
9.        <baseAddresses> 
10.          <add baseAddress="http://localhost:8080/SampleService" /> 
11.        </baseAddresses> 
12.      </host> 
13.      <endpoint 
14.         address="mex" 
15.         binding="mexHttpBinding" 
16.         contract="IMetadataExchange" 
17.      /> 
18.    </service> 
19.  </services> 
20.  <behaviors> 
21.    <serviceBehaviors> 
22.      <!-- Step 2. Add a new behavior below.--> 
23.      <behavior name="metadataAndDebug"> 
24.        <serviceMetadata  httpGetEnabled="true" httpGetUrl=""/> 
25.      <!-- Step 3. Add a <serviceDebug> element --> 
26.    <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" /> 
27.      </behavior> 
28.    </serviceBehaviors> 
29.  </behaviors> 
30.</system.serviceModel> 
31.</configuration>
Please note that there is an inherent security issue if this setting is left to 'true' for your production environment. Please see the MSDN article here for more details.