FaultContractAttribute.DetailType Property
.NET Framework 3.5
Gets the type of a serializable object that contains error information.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
The following code example shows the use of FaultContractAttribute to specify that the SampleMethod operation can return a SOAP fault with the detail type of GreetingFault.
using System; using System.Collections.Generic; using System.Net.Security; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; namespace Microsoft.WCF.Documentation { [ServiceContract(Namespace="http://microsoft.wcf.documentation")] public interface ISampleService{ [OperationContract] [FaultContractAttribute( typeof(GreetingFault), Action="http://www.contoso.com/GreetingFault", ProtectionLevel=ProtectionLevel.EncryptAndSign )] string SampleMethod(string msg); } [DataContractAttribute] public class GreetingFault { private string report; public GreetingFault(string message) { this.report = message; } [DataMemberAttribute] public string Message { get { return this.report; } set { this.report = value; } } } class SampleService : ISampleService { #region ISampleService Members public string SampleMethod(string msg) { Console.WriteLine("Client said: " + msg); // Generate intermittent error behavior. Random rand = new Random(DateTime.Now.Millisecond); int test = rand.Next(5); if (test % 2 != 0) return "The service greets you: " + msg; else throw new FaultException<GreetingFault>(new GreetingFault("A Greeting error occurred. You said: " + msg)); } #endregion } }
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.