WCF REST Message Inspector

An IDispatchMessageInspector implementation which shows how to get the actual message body for non-XML messages (i.e., JSON, binary) in a WCF REST service.

C# (43.9 KB)
 
 
 
 
 
4.5 Star
(10)
5,293 times
Add to favorites
4/13/2011
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Calling this service through Jquery Ajax
    1 Posts | Last post February 08, 2013
    • When i am trying to call this service through jquery ajax, then IncomingMessageLogger is not getting hit, i mean then Incoming message logger is not working...
      
      Please reply as soon as possible..
      
      Regards Vikash
  • Great Article and code example
    1 Posts | Last post January 24, 2013
    • Great Article and code example
  • xml Document declaration
    3 Posts | Last post January 24, 2013
    • Hi Carlos, Great article !
      
      In the forums this question has come up time and time again (Actually twice). How do I include <?xml version="1.0" encoding="utf-8" ?> in a response message to the client when BodyStyle:=WebMessageBodyStyle.Bare is set on the WebGetAttribute.
      
      I followed your article to the letter and when regenerating the message (which is awesome that you showed us how) the xml declaration disappears. I know it's possible cos when BodyStyle:=WebMessageBodyStyle.Wrapped the xml declaration is returned to the client.
      
      I thought it was the difference between XMLDictionaryReader and XMLReader which was the root cause but after many hours of trying different variations I'm still stumped.
      
      I hope you have time to answer my question
      
      rupex
    • I figured it out !!!
      
          Public Sub BeforeSendReply(ByRef reply As System.ServiceModel.Channels.Message, correlationState As Object) Implements System.ServiceModel.Dispatcher.IDispatchMessageInspector.BeforeSendReply
      
              WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml"
              reply = WebOperationContext.Current.CreateTextResponse("<?xml version=""1.0"" encoding=""utf-8"" ?><myField>Hello, I'm formatted xml</myField>")
      
          End Sub
    • Great Article