Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6475869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:45:24+00:00 2026-05-25T06:45:24+00:00

I need to put custom headers into WCF. My Code is as follows: ServiceReference1.Service2Client

  • 0

I need to put custom headers into WCF. My Code is as follows:

ServiceReference1.Service2Client ws = new Service2Client();
   using (OperationContextScope scope = new OperationContextScope((IContextChannel)ws.InnerChannel))
        {
            MessageHeaders messageHeadersElement = OperationContext.Current.OutgoingMessageHeaders;
            messageHeadersElement.Add(MessageHeader.CreateHeader("Authorization", String.Empty, "string"));
            messageHeadersElement.Add(MessageHeader.CreateHeader("username", String.Empty, "user"));
            var res = ws.GetUser("123");
        }

But when I try to read it in the service, nothing is availabe in the following

public class OAuthAuthorizationManager : ServiceAuthorizationManager
    {
        protected override bool CheckAccessCore(OperationContext operationContext)
        {
            int index = OperationContext.Current.IncomingMessageHeaders.FindHeader("username", String.Empty);

            string auth = operationContext.IncomingMessageHeaders.GetHeader<string>("username", String.Empty);

            var hereIseeIt = operationContext.RequestContext.RequestMessage;

index is -1: not found

auth: is also displaying an exception that the header is not available

hereIseeIt: .ToString() shows a xml where I can see that user is existent, but I see no way to access that information in any of the objects
enter image description here

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <username xmlns="http://Microsoft.WCF.Documentation">user</username>
  </s:Header>
  <s:Body>
    <GetUser xmlns="http://tempuri.org/">
      <UserId>123</UserId>
    </GetUser>
  </s:Body>
</s:Envelope>

But I cannot access them since I find no way to access the s:Header …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:45:24+00:00Added an answer on May 25, 2026 at 6:45 am

    try using:

    XPathNavigator XPN = operationContext.RequestContext.RequestMessage.CreateBufferedCopy ().CreateNavigator ();
    

    NOT elegant but it gives you the whole Message accessible through a XPathNavigator which should make it easy to get to any value inside the Message you want..

    some links:

    • http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.requestcontext.aspx
    • http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.aspx
    • http://msdn.microsoft.com/en-us/library/system.xml.xpath.xpathnavigator.aspx
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need create custom dialog and put JPanel into it. Is it possible?
I need to put it some custom logic into my iPhone app so that
I need to put a custom hover menu from http://www.addthis.com/help/toolbox , but Rails uses
What would i need to put in the SortIP function to make the custom
I need to put an LDAP contextSource into my Java EE container's JNDI tree
I have the need to put a custom attribute on an anchor which I
I need to put EditText box with vertical scrollbar on custom dialog.i.e when I
I need to execute a custom code function when the report first loads, and
I need to put an alpha blended gradient border around an image. My problem
I need to put a control to the right of my MenuStrip. The MenuStrip

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.