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 8536141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:35:38+00:00 2026-06-11T10:35:38+00:00

I have a custrom soapheader that looks like this : [DataContract()] public class IntegrationHeader

  • 0

I have a custrom soapheader that looks like this :

[DataContract()]
    public class IntegrationHeader
    {
        [DataMember]
        public string UserName;
        [DataMember]
        public string Password;
    }

Then I have the following code in a messageInspector :

if (request.Headers.Action == null || request.Headers.Action.ToString().Length < 1)
                return null;

            foreach (var header in request.Headers)
            {
                if (header.Namespace == "ns" && header.Name == "SecurityToken")
                {
                    loginHandler = new LoginHandler();

                    integrationHeader = request.Headers.GetHeader<IntegrationHeader>(header.Name, header.Namespace);
                    if ((userContext = loginHandler.LoginUser(integrationHeader.UserName, PassWordManager.DESEncrypt(integrationHeader.Password), Business.Entity.LoginType.Regular)) == null)
                        throw new SecurityTokenException("Unknown username or invalid password");

                    Thread.CurrentPrincipal = userContext;

                    return null;
                }
            }

            throw new SecurityTokenException("Unknown username or invalid password");

When sending the following soap header with soapui it works fine :

   <soapenv:Header>
     <SecurityToken xmlns="ns" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
       <Password xmlns="MyApp.ServiceImplementation">X</Password>
       <UserName xmlns="MyApp.ServiceImplementation">X</UserName>
     </SecurityToken>
   </soapenv:Header>

Then I try to do this from within a proxy generated WCF client :

using (client = new MyProxy())
{

                IntegrationHeader ih = new IntegrationHeader { UserName = "X", Password = "X" };

                MessageHeader untyped = MessageHeader.CreateHeader("SecurityToken", "ns", ih);
                using (new System.ServiceModel.OperationContextScope(client.InnerChannel))
                {
                    OperationContext.Current.OutgoingMessageHeaders.Add(untyped);
                }

                client.GetData(request);
            }

The problem is that there will be only 2 headers in the messageInspector when running this code and none of them will be the security header?

What am I doing wrong?

  • 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-06-11T10:35:39+00:00Added an answer on June 11, 2026 at 10:35 am

    This is the correct solution :

                IntegrationHeader ih = new IntegrationHeader { UserName = "X", Password = "X" };
    
                MessageHeader untyped = MessageHeader.CreateHeader("SecurityToken", "ns", ih);
                using (new System.ServiceModel.OperationContextScope(client.InnerChannel))
                {
                    OperationContext.Current.OutgoingMessageHeaders.Add(untyped);
                    client.GetData(request);
                }
    

    The service call most be done within the using else the security header will be removed from the outgoing context.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have custom exceptions in my django project that look like this: class CustomFooError(Exception):
I have Custom List to display image with it's name like below... public class
I have custom plugin with the next structure. models.py looks like class ProductDescription(models.Model): name
I have custom validation rule: public function customRule($check) { } Inside this rule I
I have custom assembly that is loaded on runtime. at this point i have
I have custom button, with an image that I'd like to shift down within
I have custom class that implement IEnumerable<int[]> interface and save current Enumerator . When
I have custom SPlist with some fields that I'd like to bind to a
I have custom binary tree class that holds values of template type T (it
I have custom ImageView: public class ShadowedImageView extends ImageView { private Paint mPaint; public

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.