none
How to catch duplicate request header names in WCF RRS feed

  • Question

  • Hi Team,

    We have one WCF service, in which it is to request multiple headers such as StudentId. If the application finds duplicate header names such as StudentId, studentId or StudentID, it's supposed to throw an error.

    We need to solve below scenarios.

    1. It should allow only one StudentId header, if user enter headers such as StudentId, studentId or StudentID, it's supposed to throw an error..
    2. Header names such as StudentId is read without case sensitivity.
    3. Output all http headers, dynamically, even it is duplicate.

    I can see few article that talk HttpServletRequest, but don’t for any article for WCF service.

    https://coderanch.com/t/593920/java/HttpServletRequest-catch-duplicate-request-header

    Any code, help, experience or pointers will be highly appreciated.

    Monday, June 5, 2017 9:17 PM

All replies

  • Hi Team,

    We have one WCF service, in which it is to request multiple headers such as StudentId. If the application finds duplicate header names such as StudentId, studentId or StudentID, it's supposed to throw an error.

    We need to solve below scenarios.

    1. It should allow only one StudentId header, if user enter headers such as StudentId, studentId or StudentID, it's supposed to throw an error..
    2. Header names such as StudentId is read without case sensitivity.
    3. Output all http headers, dynamically, even it is duplicate.

    I can see few article that talk HttpServletRequest, but don’t for any article for WCF service.

    https://coderanch.com/t/593920/java/HttpServletRequest-catch-duplicate-request-header

    Any code, help, experience or pointers will be highly appreciated.

    Monday, June 5, 2017 9:15 PM
  • There is a MSDN WCF forum you can post to and discuss WCF issues.
    Monday, June 5, 2017 9:45 PM
  • Is WCF Service SOAP service or Rest Service?

    Do you want to check headers in service method? If so, I suggest you try WebOperationContext.Current.IncomingRequest.

    Here is a simple code for output all headers.

                IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
                foreach (string headerName in request.Headers)
                {
                    System.Diagnostics.Debug.WriteLine(headerName +" : "+request.Headers[headerName]);
                }
    

    After getting all headers, you could check studentid header.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 6, 2017 1:52 AM
  • Hi,

    This is a WCF Service SOAP service. I tried the your shared code, it's not reading duplicate header names, actally, it's merging same header names, that I don't want.

    Please help.

    Friday, June 9, 2017 3:19 PM
  • Hi Shailendra,

    >> it's merging same header names, that I don't want.

    What do you mean by this? Could you share us a screen shot about your current result and expected result?

    Did you get two duplex headers in “request.Headers”?

    In addition, how did you add duplex headers in client side? A simple demo which could reproduce your issue would be helpful, and then we could try to reproduce your issue and provide targeted suggestion.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 12, 2017 1:59 AM
  • Hi,

    If WCF SOAP service receive duplicate header names such as StudentId, studentId or STUDENTID, actually it merge all headers and keep the value of last header one like STUDENTID in response.

    So, if we get receive duplicate header names, we should throw an error like in above case.

    Monday, June 12, 2017 8:56 PM
  • Hi Shailendra,

    I know you fall into this issue, and you know the current result for merged headers. But, we do not. I did not sit before your computer, so I could not understand what you mean by merged headers. I even do not know how to reproduce your issue since I did not add header manually, and I do not have duplex headers at my side.

    If possible, could you share us a simple demo to reproduce your issue, at least a screen shot which let us know what duplicate headers you got.

    If you mean you have got merged result in service side, I suggest you try IClientMessageInspector by checking BeforeSendRequest.

    # WCF Extensibility – Message Inspectors

    https://blogs.msdn.microsoft.com/carlosfigueira/2011/04/18/wcf-extensibility-message-inspectors/

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 13, 2017 5:23 AM