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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:16:26+00:00 2026-05-27T09:16:26+00:00

I have a need to pass an HTTP header for each an every RIA

  • 0

I have a need to pass an HTTP header for each an every RIA Service request being made from a Silverlight app. The value of the header needs to come from the app instance, and not from a cookie. I know this can be accomplished by putting it in the DTOs, but it’s not an option because a lot of our service calls use Entities and change sets, so there’s no base class to tie into for all requests. So I’m looking for a centralized and safe means to pass something back with each request so the developers do not have to worry with it. A custom HTTP header would work fine, but I don’t know how to intercept the outbound request to set it.

Anyone have any ideas I can try?

  • 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-27T09:16:26+00:00Added an answer on May 27, 2026 at 9:16 am

    On the lower level you can add HTTP headers with the help of an IClientMessageInspector. Try starting from this post on SL forum.

    The next step depends on your use cases.

    If the value of the header must be the same for any method called by the DomainContext, then you may just extend the context using partial class, add a property for the header value and use that property in the inspector.

    If you need to pass a different value for each method call, you’d probably need to wrap your DomainContext into another class and add an argument to each method of the context that will accept the header value and pass it to the inspector somehow. Needless to say, without a code-generator this would be hard.

    Here’s an adapted sample from the SL forum for the first case:

    public sealed partial class MyDomainContext
    {
      public string HeaderValue { get; set; }
    
      partial void OnCreated()
      {
        WebDomainClient<IMyDomainServiceContract> webDomainClient = (WebDomainClient<IMyDomainServiceContract>)DomainClient;
        CustomHeaderEndpointBehavior customHeaderEndpointBehavior = new CustomHeaderEndpointBehavior(this);
        webDomainClient.ChannelFactory.Endpoint.Behaviors.Add(customHeaderEndpointBehavior);
      }
    }
    
    public class CustomHeaderEndpointBehavior : IEndpointBehavior
    {
      MyDomainContext _Ctx;
    
      public CustomHeaderEndpointBehavior(MyDomainContext ctx)
      {
        this._Ctx = ctx;
      }      
    
      public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) { }
      public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
      {
        clientRuntime.MessageInspectors.Add(new CustomHeaderMessageInspector(this._Ctx));
      }
      public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher) { }
      public void Validate(ServiceEndpoint endpoint) { }
    }
    
    public class CustomHeaderMessageInspector : IClientMessageInspector
    {
      MyDomainContext _Ctx;
    
      public CustomHeaderMessageInspector(MyDomainContext ctx)
      {
        this._Ctx = ctx;
      }
    
      public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState) {}
      public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel)
      {
        string myHeaderName = "X-Foo-Bar";
        string myheaderValue = this._Ctx.HeaderValue;
    
        HttpRequestMessageProperty property = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];
        property.Headers[myHeaderName] = myheaderValue;
        return null;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a server script that I need to pass data to from the
I have an application in which I need to pass an array from C#
I have a lot of JSON data I need to pass to a request:
I have DataGrid that connects to REST service. I need to pass some custom
I have a custom sharepoint app whose security model depends on an HTTP header.
I have a java application I need to pass some info to a C++
So I have a flashobject which I need to pass a formatted DateTime string
I have a user control in a repeater that I need to pass data
I have a .NET program and a Borland Win32 program that need to pass
I have an ASP control custom built and I need to pass a value

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.