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?
Asked
Active
Viewed 646 times
5
-
2Why does your WCF service have a constructor that can fail? And, quite honestly...why does it have a constructor at all? WCF can create and destroy service instances at will...your just asking for problems by using a constructor, particularly if it can throw exceptions. – jrista Aug 27 '09 at 16:34
1 Answers
2
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.

bobbymcr
- 23,769
- 3
- 56
- 67