Request a ResponseInterceptor class

Last post 11-30-2009 8:46 PM by habibs. 3 replies.

Sort Posts:

  • Request a ResponseInterceptor class

    11-07-2009, 11:46 AM
    • Member
      6 point Member
    • bobbyfu
    • Member since 02-26-2009, 3:56 PM
    • Posts 7

    The REST starter kit CTP2 has an abstract class - RequestInterceptor - that we can intercept a message from the channel.  In the future release, is it possible to provide a ResponseInterceptor class?

    Thanks,

    Bobby

    Bobby Fu
    Filed under:
  • Re: Request a ResponseInterceptor class

    11-12-2009, 6:30 PM

    Hi Bobby,

    we have not heard a lot of requests for it.  We introduced RequestInterceptor for users to easily intercept the message very early in the WCF pipeline, and insert customized logic such as security check to process the request message.

    I imagine a ResponseInterceptor would do the opposite.  It would run very late in the WCF pipeline (possibly only before the transport channel), and run customized logic injected by the user.  I can't see a good use case for this.  Could you help me understand what you have in mind?

    Have you considered modifying the reply message using the requestContext?  The requestContext instance is available in the RequestInterceptor class.

    You can do the following:

     string errorHtml =
                "<html><HEAD><TITLE>Request Error</TITLE></HEAD><BODY>" +
                "<H1>Error processing request</H1><P>{0}</P></BODY></html>";
            XElement response = XElement.Load(new StringReader(
                string.Format(errorHtml, errorMessage)));
            Message reply = Message.CreateMessage(MessageVersion.None, null, response);
            HttpResponseMessageProperty responseProp = new HttpResponseMessageProperty()
            {
                StatusCode = statusCode
            };
            responseProp.Headers[HttpResponseHeader.ContentType] = "text/html";
            reply.Properties[HttpResponseMessageProperty.Name] = responseProp;
            requestContext.Reply(reply);

     

    Is there a reason why that is not sufficient?

  • Re: Request a ResponseInterceptor class

    11-12-2009, 11:27 PM
    • Member
      6 point Member
    • bobbyfu
    • Member since 02-26-2009, 3:56 PM
    • Posts 7

    Andrew, I have an old "Web Service" that was written in those ASP day.  Our business partners ping us and our service returns different kind of POX back to them.  The service has been in production for over a decade.  Because it was built more than 10 years ago and there are so many business partners and affiliates are still using them.  My new REST-style service I'm re-architecting needs to return the same old XML files back to them without breaking their code.  Hence, I need a way to hook into channel message, intercept the message, and re-format the message before sending it back. 

    I found the RequestInterceptor in the REST Starter kit but I didn't see its opposite object - ResponseInterceptor.

    Let me try the requestContext you outlined in your email.

    Also,  I wrote an Inspector class that derives from the IDispatchMessageInspector interface.  I see the outbound message.  Can I alter it?

     

    Bobby Fu
  • Re: Request a ResponseInterceptor class

    11-30-2009, 8:46 PM
    • Member
      362 point Member
    • habibs
    • Member since 01-02-2003, 4:59 AM
    • Posts 78

    I am also interested in ResponseInterceptor. Here is my need. I am developing J2ME client for my WCF Rest services but some

    phones does not support handling multiple set-cookie headers in response. In my case there are 2 cookies, auth cookie

    and aspnet_sessionId cookie. In my response i want to remove aspnet_sessionId cookie as i don't use session and it will fix my problem on those phones.

    Bytheway is there any option to disable aspnet session state when using wcf service in aspNetCompatibilityEnabled=true mode ?


Page 1 of 1 (4 items)