Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should constructors for WCF Services use faults for error handling?

I have a wcf service. The service itself (class that inherits the ServiceContract) has a constructor that sometimes throws exceptions. I want to present the user a message if the service fails. Should I use faults like I would for a service method?

like image 405
Justin Dearing Avatar asked Nov 05 '22 19:11

Justin Dearing


1 Answers

A fault is generally meant to provide error information across service boundaries, and in most cases, a fault is sent as a response to a malformed or invalid request message. Given that, I would say a fault doesn't make sense here.

I agree with the above commenter that a constructor for a service class should avoid throwing exceptions. If your service is sessionful, you may want to consider a design where you do this type of initialization as the result of a specific service operation. This can be done in WCF by marking such a service operation with "IsInitiating = true" in the [OperationContract] attribute. At that point, you would be able to generate a fault and have some hope of it reaching the intended client.

like image 190
bobbymcr Avatar answered Nov 14 '22 21:11

bobbymcr