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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:47:22+00:00 2026-05-26T11:47:22+00:00

We have custom XML serialization for our protocol here: [XmlRoot(axf, Namespace = Axf10Namespace)] public

  • 0

We have custom XML serialization for our “protocol” here:

[XmlRoot("axf", Namespace = Axf10Namespace)]
public class AxfDocument : IXmlSerializable
{
  public const string Axf10Namespace = "http://schemas.***.ru/axf/axf-1.0.0";
  // ...
}

and all’s fine when using standard .NET XmlSerializer:

<?xml version="1.0" encoding="utf-16"?>
<axf version="1.0.0" createdAt="2011-10-20T13:11:40" xmlns="http://schemas.***.ru/axf/axf-1.0.0">
  <itineraries>
    <!-- -->
   </itineraries>
</axf>

Now that we try to use this class in a bare-bones WCF service:

[OperationContract]
AxfDocument GetItineraries(ItinerariesQuery query);

actual XML document that gets sent to client side is this:

<GetItinerariesResult version="1.0.0" createdAt="2011-10-20T13:17:50" xmlns="http://tempuri.org/">
  <itineraries xmlns="http://schemas.***.ru/axf/axf-1.0.0">
    <!-- rest is fine, serialization code does work -->

How do I bend WCF to send root element as-is and not to replace it with its own?

  • 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-26T11:47:22+00:00Added an answer on May 26, 2026 at 11:47 am

    By default, the operation responses are wrapped in the operation name. You can, however, use a MessageContract in the operation definition to use an “unwrapped” response, as shown below. If you look at the response body of the request in Fiddler, you’ll see that it’s exactly as the one from the serialization.

    public class StackOverflow_7836645
    {
        [XmlRoot("axf", Namespace = Axf10Namespace)]
        public class AxfDocument : IXmlSerializable
        {
            public const string Axf10Namespace = "http://schemas.something.ru/axf/axf-1.0.0";
    
            public XmlSchema GetSchema()
            {
                return null;
            }
    
            public void ReadXml(XmlReader reader)
            {
            }
    
            public void WriteXml(XmlWriter writer)
            {
                writer.WriteStartElement("intineraries", Axf10Namespace);
                writer.WriteElementString("item", Axf10Namespace, "one value");
                writer.WriteElementString("item", Axf10Namespace, "another value");
                writer.WriteEndElement();
            }
        }
    
        [MessageContract(IsWrapped = false)]
        public class OperationResponse
        {
            [MessageBodyMember(Name = "axf", Namespace = AxfDocument.Axf10Namespace)]
            public AxfDocument axf;
        }
    
        [ServiceContract]
        public interface ITest
        {
            [OperationContract]
            OperationResponse GetAxf();
        }
    
        public class Service : ITest
        {
            public OperationResponse GetAxf()
            {
                return new OperationResponse { axf = new AxfDocument() };
            }
        }
    
        public static void Test()
        {
            Console.WriteLine("Serialization");
            MemoryStream ms = new MemoryStream();
            XmlSerializer xs = new XmlSerializer(typeof(AxfDocument));
            xs.Serialize(ms, new AxfDocument());
            Console.WriteLine(Encoding.UTF8.GetString(ms.ToArray()));
    
            Console.WriteLine();
            Console.WriteLine("Service");
    
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
            host.AddServiceEndpoint(typeof(ITest), new BasicHttpBinding(), "");
            host.Open();
            Console.WriteLine("Host opened");
    
            ChannelFactory<ITest> factory = new ChannelFactory<ITest>(new BasicHttpBinding(), new EndpointAddress(baseAddress));
            ITest proxy = factory.CreateChannel();
            Console.WriteLine(proxy.GetAxf());
    
            ((IClientChannel)proxy).Close();
            factory.Close();
    
            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We use custom serialization schemas for xml serialization of our objects. I have a
I have a class that I need to do some custom XML output from,
I have a custom XML schema defined for page display that puts elements on
I have a custom XML file format which can contain blocks of code within
I am currently watching an XML file from log4j output. I have a custom
friends, i have created custom title bar using following titlebar.xml file with code <?xml
I have a listView with custom objects defined by the xml-layout below. I want
I have the following XML Parsing code in my application: public static XElement Parse(string
I have made custom .xml layout for ListView. Now it looks: But it isn't
I have my custom attr.xml document in which I specified declare-styleable : <?xml version=1.0

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.