Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does the XmlRoot attribute gets ignored in WCF and how to overcome this
    primarykey
    data
    text
    <p>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. </p> <p>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.</p> <p>A few questions then - </p> <ol> <li>Anybody knows what is the rationale behind this decision?</li> <li>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?)</li> <li>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?</li> </ol> <p>I've seen <a href="https://stackoverflow.com/questions/159373/xmlroot-attribute-not-included-in-the-generated-proxy-class">this</a> post, but I don't believe it is relevant to my question - </p> <p>As per Wagner Silveira's request - the contracts I used to test this are - </p> <pre><code>[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; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload