Infovark Underground

  • news
    • infoblog
    • underground
  • product
  • download
  • buy
  • support
  • about
    • ← Using WCF for REST, Part 2
    • Using WCF for REST, Part 3 →

    WCF Instance Context

    21 May 2008 by Dean in REST, WCF, Web Services / 2 Comments

    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
    • Tweet

    2 Comments

    • Vish

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

      22 May 2008 03:05 pm
      Reply
      • Dean

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

        22 May 2008 04:05 pm
        Reply

        Leave a Comment

        Posting your comment...

        Subscribe to these comments via email

        • Categories

          • .NET (41)
          • AJAX (3)
          • Books (7)
          • HTML (9)
          • Infovark (8)
          • Programming (48)
          • REST (11)
          • SQL (3)
          • Testing (3)
          • Tools (13)
          • UI (3)
          • WCF (11)
          • Web Services (8)
          • WPF (4)
          • XML (4)
        • Archives

        • Get future articles


           

        • Blogroll

          • Ajaxian
          • Anne Van Kesteren
          • Brain.Save()
          • Coding Horror
          • Eric Sink
          • Joel Spolsky
          • John Resig
          • Mark Pilgrim
          • Raymond Chen
          • Scott Hansleman
          • Secret Geek
          • Steve Yegge
          • The Daily WTF
          • The Database Programmer
        • Meta

          • Log in
          • Entries RSS
          • Comments RSS
          • WordPress.org
      • Site map

        • News
        • Product
        • Download
        • Buy
        • Support
        • About
      • Recent Posts

        • Review: Brownfield Application Development in .NET
        • Using Modal Dialogs with a Splash Screen in WPF
        • Highlighting query terms in a WPF TextBlock
        • Getting XAML Hyperlink text to wrap
        • How to format the XAML Hyperlink NavigateUri
      • Twitter

        Copyright 2011 Infovark, Inc. All rights reserved.