System.ServiceModel.FaultException Error
I have a test app that emulates the data that the Client would pass to the back end that my company uses for WCF back end. But when i am writing the following fault exception on my server side it is giving me the following error.Could anyone tell me what is System.ServiceModel.FaultException ?
Re: System.ServiceModel.FaultException Error
FaultException is used in a client application to catch contractually-specified SOAP faults. Exceptions are technology specific and therefore not suitable to cross the service boundary of SOA compliant services. Another anomaly we identified is that all exceptions, with the exception of FaultException fault the communication channel, resulting in unhappy proxies as a recover and retry is not possible.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 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.The following code example shows how a service uses the FaultException type to throw a managed exception that gets converted into the SOAP fault specified by the FaultContractAttribute.
Quote:
C#
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
}
}
Re: System.ServiceModel.FaultException Error
What we need are soap faults that are an industry standard for seamless interoperability, and there is more delivers the answer to Soap Faults as FaultException, which result in a soap fault and do not fault the communication channel.The operations which may throw a FaultException, must be decorated with one or more FaultContract attributes, defining the “exact” FaultException.To test the FaultException concept we defined the following interface:
Quote:
[ServiceContract()]
public interface IFaultDemoService
{
[OperationContract]
[FaultContract(typeof(DivideByZeroException))]
void FaultDemoFaultSimple();
[OperationContract]
[FaultContract(typeof(DivideByZeroException))]
void FaultDemoFaultException();
[OperationContract]
[FaultContract(typeof(DivideByZeroException))]
void FaultDemoFaultExceptionCodeReason();
[OperationContract]
[FaultContract(typeof(DivideByZeroException))]
void FaultDemoFaultExceptionReason();
[OperationContract]
[FaultContract(typeof(DivideByZeroException))]
void FaultDemoFaultExceptionVerbose();
[OperationContract]
[FaultContract(typeof(DivideByZeroException))]
void FaultDemoException();
}
Re: System.ServiceModel.FaultException Error
When you create a new FaultException, you need to supply a reason (either using the string overload or the FaultReason type overload). When you fail to supply the reason, you can receive the following exception:
The creator of this fault did not specify a Reason.