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 -
- Anybody knows what is the rationale behind this decision?
- 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?)
- 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; }
}