[DataContract]
public class MyFault
{
[DataMember]
public string Message { get; set; }
public PasswordFault()
{
}
public PasswordFault(string message)
{
this.Message = message;
}
}
public class myService: IMyContract
{
public void MyMethod()
{
try
{
......
{
catch (myException exc)
{
MyFault = new MyFault(exc.Message);
throw new FaultException(MyFault, "Failed to run MyMethod");
}
}
}
[ServiceContract]
public interface IMyContract
{
[OperationContract]
[FaultContract(typeof(AuthenticationFault))]
void MyMethod();
}
Alternative Fault Handling Techniques
Recently, during the development of quite a large SOA based system I noticed that Faults that are raised by sub-services were not being raised correctly through the next service. The only way to ensure that these faults were received by the client was to recapture the fault (as a FaultException
After a bit of investigation and a very helpful reply to a post on the MSDN WCF forum I was pointed in the direction of this example of using the IErrorHandler interface to add custom error handlers to the individual channel dispatcher. I'm not going to go into any great amount of detail about this, but I strongly recommend reading the article. It gives you a much more elegant way of handling exception to fault conversions in WCF.
No comments:
Post a Comment