WCF Instance Context
I finally figured out the source of my HTTP 400 problem. Apparently the Windows Communication Foundation deals with exceptions differently depending on your InstanceContextMode settings. I had been using the Single setting but I should have used the PerCall setting. In PerCall mode, the try/catch block works as expected.
I think it has something to do with the way that WCF distinguishes between channel exceptions and message faults.
Anyway, if you’re building a REST web service, you’ll want to make sure your class is decorated with the following ServiceBehavior attribute.
-
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
Related Posts
- Using WCF for REST, Part 2
- Calling a Static Method from an Object Instance in C#
- Using WCF for REST, Part 1
This seems like a bug in the product. Thanks for bringing it tou our notice
No worries, Vish. I’m glad I could help. It makes me feel a bit better to know that it’s not just me.