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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:18:08+00:00 2026-05-11T21:18:08+00:00

By defining an attribute that implements IContactBehavior and IWsdlExportExtension and set that attribute on

  • 0

By defining an attribute that implements IContactBehavior and IWsdlExportExtension and set that attribute on your service contract, you can easily add Soap Headers to your wsdl (see http://wcfextras.codeplex.com/ for more information)

But now I need to set a Soap Header contract in the wsdl on all Operationcontracts and this time I cannot set an attribute.

Following code (called from IWsdlExportExtension.ExportEndPoint) doesn’t work, but does work when called from the SoapHeaderAttributes (that executes an IWsdlExportExtension.ExportContract)

foreach (OperationDescription operationDescription in context.ContractConversionContext.Contract.Operations)
{
   AddSoapHeader(operationDescription, "SomeHeaderObject", typeof(SomeHeaderObject), SoapHeaderDirection.InOut);                    
}

internal static void AddSoapHeader(OperationDescription operationDescription, string name, Type type, SoapHeaderDirection direction)
{
    MessageHeaderDescription header = GetMessageHeader(name, type);
    bool input = ((direction & SoapHeaderDirection.In) == SoapHeaderDirection.In);
    bool output = ((direction & SoapHeaderDirection.Out) == SoapHeaderDirection.Out);

    foreach (MessageDescription msgDescription in operationDescription.Messages)
    {
        if ((msgDescription.Direction == MessageDirection.Input && input) ||
            (msgDescription.Direction == MessageDirection.Output && output))
            msgDescription.Headers.Add(header);
    }
}

internal static MessageHeaderDescription GetMessageHeader(string name, Type type)
{
    string headerNamespace = SoapHeaderHelper.GetNamespace(type);
    MessageHeaderDescription messageHeaderDescription = new MessageHeaderDescription(name, headerNamespace);
    messageHeaderDescription.Type = type;
    return messageHeaderDescription;
}

Anyone has an idea how to apply this code on all operations (without using attributes) and by doing this, adding the contract of the header to the wsdl ?

  • 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-11T21:18:08+00:00Added an answer on May 11, 2026 at 9:18 pm

    The IEndpointBehavior has the following interface:

    ApplyDispatchBehavior(ServiceEndpoint endPoint, EndPointDispatcher endpointDispatcher);
    

    You can add Soap Headers to the wsdl for operations by iterating over the endpoint.Contract.Operations in the ApplyDispatchBehavior.

    Here you have the complete solution that worked for me:

    void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
    {
        foreach (OperationDescription operationDescription in endpoint.Contract.Operations)
        {
            foreach (MessageDescription msgDescription in operationDescription.Messages)
            {
                AddSoapHeader(operationDescription, "SomeHeaderObject", typeof(SomeHeaderObject), SoapHeaderDirection.InOut);
            }
        }
    }
    
    internal static void AddSoapHeader(OperationDescription operationDescription, string name, Type type, SoapHeaderDirection direction)
    {
        MessageHeaderDescription header = GetMessageHeader(name, type);
        bool input = ((direction & SoapHeaderDirection.In) == SoapHeaderDirection.In);
        bool output = ((direction & SoapHeaderDirection.Out) == SoapHeaderDirection.Out);
    
        foreach (MessageDescription msgDescription in operationDescription.Messages)
        {
                if ((msgDescription.Direction == MessageDirection.Input && input) ||
                        (msgDescription.Direction == MessageDirection.Output && output))
                        msgDescription.Headers.Add(header);
        }
    }
    
    internal static MessageHeaderDescription GetMessageHeader(string name, Type type)
    {
        string headerNamespace = SoapHeaderHelper.GetNamespace(type);
        MessageHeaderDescription messageHeaderDescription = new MessageHeaderDescription(name, headerNamespace);
        messageHeaderDescription.Type = type;
        return messageHeaderDescription;
    }
    

    The SoapHeaderHelper can be found in the WcfExtras.

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

Sidebar

Related Questions

When defining a custom operator from the limited set of single-character operators that can
In Python, you can assign an arbitrary attribute from outside the defining class :
In HTML forms, buttons can be disabled by defining the disabled attribute on them,
I'm defining a class that sets a Drawable attribute in an object. The problem
After defining variables, functions, etc., can you save what you have done on the
When defining parameter type that is e.g. in System.Data you have no intellisense and
I am currently defining the src attribute of my Iframe with the URL +
I have several classes defining the DebuggerDisplay attribute. I want to know if there
I want to implement an aplication where I have various Objects that can be
I'm defining an xml schema for a file that looks something like this: <data>

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.