我有以下类(都在同一个命名空间 Test.NamespaceTest 中定义):
[XmlRootAttribute("rootTag")]
public class BaseClass
{
}
[XmlRootAttribute("rootTag")]
public class MyClass : BaseClass
{
}
和类似的
[XmlRootAttribute("rootTag")]
public class Class1
{
}
[XmlRootAttribute("rootTag")]
public class Class2
{
}
当 sgen 尝试为这些类创建序列化程序集时,我收到以下错误(BaseClass 和 MyClass 也一样):
The top XML element 'rootTag' from namespace " references distinct types Test.NamespaceTest.Class1 and Test.NamespaceTest.Class2. Use XML attributes to specify another XML name or namespace for the element or types.
现在,这些类应该使用相同的根名称,所以我定义了 XmlRootAttribute。我需要做什么才能让 sgen 工作?这些类被序列化并作为 SOAP 请求发送到现有服务,因此如果我添加命名空间值,当服务尝试反序列化请求时,不会弄乱服务,因为最初没有定义命名空间吗?
我是一名优秀的程序员,十分优秀!