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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:03:42+00:00 2026-05-11T04:03:42+00:00

I have a RESTful service that I am developing in WCF . I am

  • 0

I have a RESTful service that I am developing in WCF. I am exposing a contract that does not have serializable types so I am using a DataContractSurrogate (implementation of IDataContractSurrogate) to create surrogates that can be serialized with the DataContractSerializer.

My question is, how can I access request/response headers in my DataContractSurrogate class?

In the service it’s possible by simply using WebOperationContext and in the client the same WebOperationContext is accessible within the scope of an OperationContextScope object which can be created with a reference to the current WCF Channel (IContextChannel).

I could create an OperatoinContextScope if I were able to get a reference to the WCF channel within IDataContractSurrogate.GetDeserializedObject but I’m not sure how to do that either.

Any ideas?


@casperOne:
I want to get the header value in the DataContractSurrogate implementation because to convert from the surrogate to the target type I need to reference an entry in a singleton pool of factory objects.

Something like this:

SingletonFactoryPool.Factories[factoryIdFromHeader].CreateTargetType(surrogateValues); 

I’m already passing the data I need in the headers for other reasons, it seems like it would be cleaner if I could just read the value from the header. Your point is valid though, I could easily pass the same data in the surrogate.

  • 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. 2026-05-11T04:03:42+00:00Added an answer on May 11, 2026 at 4:03 am

    If you need to access the channel in the data contract, I would say that your class is incorrectly designed. Your contract should be self contained and not be dependent on the header values used in passing the message through the channel.

    You could always create an extension (there are a number of areas you could do this) which would take the deserialized instance and then add to it the header information you need to add.

    And of course, you could always create a separate object which is an amalgam of the deserialized instance (passed through the parameters) and the header information.

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

Sidebar

Related Questions

I have a wcf restful service with a operation contract that contains two values
I have a RESTful WCF service that I am performing a PUT to using
I have a WCF restful service that I'm trying to upload an image to.
I have a restful web service that generates two types of output based on
I have a RESTful WCF service that exposes a method that takes in an
I have a restful WCF service that is returning JSON. I was wondering how
I have a simple RESTful web service that print Hello World ! I'm using
I have an old WCF 3.5 RESTful service that was at: http://www.mydomain.com/rest/Service.svc I have
I have a RESTful WCF service that can return XML, JSON, or JSONP, depending
I have a RESTful WCF service that has an upload method accepting more than

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.