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)]

2 Comments so far »

  1. Vish said,

    Wrote on May 22, 2008 @ 3:41 pm

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

  2. Dean said,

    Wrote on May 22, 2008 @ 4:11 pm

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

Comment RSS · TrackBack URI

Leave a Comment

Name: (Required)

E-mail: (Required)

Website:

Comment: