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

  • Home
  • SEARCH
  • 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 554613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:43:43+00:00 2026-05-13T11:43:43+00:00

We’ve observed that when we expose a WCF service which uses classes decorated with

  • 0

We’ve observed that when we expose a WCF service which uses classes decorated with various xml serialisation attributes, despite the fact that we use the XmlSerializerFormat attribute on the interface any XmlRoot attribute on any of the operation’s parameters gets completely ignored.
The namespace of the parameters is always that of the service and not what we specify.

This is causing us problems as it does not seem to be backwards compatible with ASMX and also because we’re using BizTalk, and need to have tighter control over the shape of the XML’s exchanged.

A few questions then –

  1. Anybody knows what is the rationale
    behind this decision?
  2. Anybody knows
    how this is happening? I was under
    the impressions that WCF, with the
    XmlSerializerFormat attribute, uses
    the XmlSerialiser to serialise the
    types, which would suggest XmlRoot
    should be taken into account, how
    come this is not the case? (is it
    only due to the fact that, taking
    the SOAP envelope into account, the
    parameter is not root?)
  3. Most
    importantly – anybody knows if
    there’s a way to ‘force the issue’ –
    i.e. get the parameters to be of the
    namespace of our choosing?

I’ve seen this post, but I don’t believe it is relevant to my question –

As per Wagner Silveira’s request – the contracts I used to test this are –

[ServiceContract(Namespace = "http://servicecontract"),
 XmlSerializerFormat(Style = OperationFormatStyle.Document)]
public interface ITestService
{
    [OperationContract]
    MyOtherType MyTestMethod(MyType obj);
}

// Composite class for DCS and XMLS
[Serializable, XmlType, XmlRoot(Namespace = "http://datacontract")] 
public class MyType
{
    [XmlAttribute]
    public string StringValue { get; set; }
}

// Composite class for DCS and XMLS
[Serializable, XmlType, XmlRoot(Namespace = "http://datacontract")]
public class MyOtherType
{
    [XmlAttribute]
    public string OtherStringValue { get; set; }
}
  • 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-13T11:43:43+00:00Added an answer on May 13, 2026 at 11:43 am

    I assume you’re using SOAP as the message format. In this case, the object you’re serializing is not the root of the XML, the soap envelope is. So it makes sense that the XmlRoot would be ignored. By default WCF will create a message contract for you and name the response and it has the namespace of the service. What you can do is create your own message contract to have full control over SOAP.

    Create the following two classes:

    [MessageContract]
    public class MyTestMethodRequest
    {
        [MessageBodyMember( Namespace = "http://datacontract" )]
        public MyType MyType;
    }
    
    [MessageContract]
    public class MyTestMethodResponse
    {
        [MessageBodyMember( Namespace = "http://datacontract" )]
        public MyOtherType MyOtherType;
    }
    

    Then change the signature of your service operation to the following.

    [OperationContract]
    public MyTestMethodResponse MyTestMethod( MyTestMethodRequest request )
    {
        return new MyTestMethodResponse {
            MyOtherType = new MyOtherType {
                OtherStringValue = "bar"
            }
        };
    }
    

    Now if you example the SOAP messages you should see the following:

    Request

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
      <s:Header>
        <Action xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none"
                s:mustUnderstand="1">http://servicecontract/TestService/MyTestMethod</Action>
      </s:Header>
      <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <MyTestMethodRequest xmlns="http://servicecontract">
          <MyType StringValue="foo" xmlns="http://datacontract" />
        </MyTestMethodRequest>
      </s:Body>
    </s:Envelope>
    

    Response

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
      <s:Header />
      <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <MyTestMethodResponse xmlns="http://servicecontract">
          <MyOtherType OtherStringValue="bar" xmlns="http://datacontract" />
        </MyTestMethodResponse>
      </s:Body>
    </s:Envelope>
    
    • 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.