DataContractSerializer
does not expose as fine grained control over the XML generation, so this sort of attribute is not inherently available. However, you could subclass the shared class (assuming you can get rid of the sealed
access modifier), with two different DataContract
attributes with different namespaces.
namespace NamespaceShared
{
using System.Runtime.Serialization;
public class SharedType
{
[DataMember(IsRequired = true)]
public int ValueOne { get; set; }
[DataMember(IsRequired = true)]
public int ValueTwo { get; set; }
}
[DataContract(Namespace = "http://namespace.one")]
public class SharedTypeOne : SharedType
{
}
[DataContract(Namespace = "http://namespace.two")]
public class SharedTypeTwo : SharedType
{
}
}
namespace NamespaceOne
{
using System.Runtime.Serialization;
using NamespaceShared;
[DataContract(Namespace = "http://namespace.one")]
public sealed class DataContractOne
{
[DataMember(IsRequired = true)]
private SharedTypeOne SharedValue { get; set; }
}
}
namespace NamespaceTwo
{
using System.Runtime.Serialization;
using NamespaceShared;
[DataContract(Namespace = "http://namespace.two")]
public sealed class DataContractTwo
{
[DataMember(IsRequired = true)]
private SharedTypeTwo SharedValue { get; set; }
}
}
If all else fails, you could edit the raw XML coming out of the service using a technique similar to that which is used to change the auto-generated prefixes. This MSDN blog post details the overall process.