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.

  1. [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]

Related Posts

  1. Using WCF for REST, Part 2
  2. Calling a Static Method from an Object Instance in C#
  3. Using WCF for REST, Part 1

2 Responses to “WCF Instance Context”

  1. Vish says:

    This seems like a bug in the product. Thanks for bringing it tou our notice

  2. Dean says:

    No worries, Vish. I’m glad I could help. It makes me feel a bit better to know that it’s not just me. :-)

Leave a Reply