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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:51:23+00:00 2026-05-18T01:51:23+00:00

I’m attempting to test a [MessageContract] class against an existing sample message, and I’m

  • 0

I’m attempting to test a [MessageContract] class against an existing sample message, and I’m looking for a way to simplify development by reading the sample message file into an instance of my [MessageContract] class and seeing how it worked out (I’m dealing with a particularly complex contract here, of non-WCF origin).

My [MessageContract] class looks something like this:

[MessageContract(IsWrapped = true, WrapperName = "wrapper", WrapperNamespace = "somens")]
public class RequestMessage
{
    [MessageHeader(Name = "HeaderElem", Namespace = "otherns")]
    public XElement CorrelationTimeToLive { get; set; }

    [MessageBodyMember(Name = "id", Namespace = "somens")]
    public XElement id { get; set; }
}

I can read the file into an instance of the Message class, using code such as the following:

var xr = XmlReader.Create("sample_message.xml");
var msg = Message.CreateMessage(xr, int.MaxValue, MessageVersion.Soap12);

That’s not particulary helpful, however, because it doesn’t allow me to test my [MessageContract] class at all.

Somewhere in the guts of WCF is a system for turning this Message instance into an instance of a particular [MessageContract] class, but what is it?

  • 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-18T01:51:24+00:00Added an answer on May 18, 2026 at 1:51 am

    I just learned how to do this the other day following a talk with a collegue. I think this is what you were asking to do.

    namespace MessageContractTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                string action = null;
                XmlReader bodyReader = XmlReader.Create(new StringReader("<Example xmlns=\"http://tempuri.org/\"><Gold>109</Gold><Message>StackOverflow</Message></Example>"));
                Message msg = Message.CreateMessage(MessageVersion.Default, action, bodyReader);
                TypedMessageConverter converter = TypedMessageConverter.Create(typeof(Example), "http://tempuri.org/IFoo/BarOperation");
                Example example = (Example)converter.FromMessage(msg);
            }
        }
    
    
        [MessageContract]
        public class Example
        {
            [MessageHeader]
            public string Hello;
    
            [MessageHeader]
            public double Value;
    
            [MessageBodyMember]
            public int Gold;
    
            [MessageBodyMember]
            public string Message;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.