J
James
I encountered a problem caused by calling a web method and returning a
derived class one of whose property overrides its base property.
Definitions of the two classes are as follows:
public class Class1
{
public Class1()
{
}
public string Name;
}
public class Class2 : Class1
{
public Class2()
{
}
public new string[] Name;
}
the web method is as follows:
[WebMethod]
public Class2 Test()
{
return new Class2();
}
I can compile it correctly, however, an exception was thrown when referring
the web service:
Member Class2.Name of type System.String[] hides base class member
Class1.Name of type System.String. Use XmlElementAttribute or
XmlAttributeAttribute to specify a new name.
I don't know how to use XmlAttributeAttribute or
XmlElementAttributeAttribute class to solve the problem, but I tried the
following style and failed:
[XmlElement("Class2Name", typeof(string[])),
XmlElement("Class1Name", typeof(string))]
public new string[] Name;
Any ideas will be greatly appreciately and thanks in advance.
derived class one of whose property overrides its base property.
Definitions of the two classes are as follows:
public class Class1
{
public Class1()
{
}
public string Name;
}
public class Class2 : Class1
{
public Class2()
{
}
public new string[] Name;
}
the web method is as follows:
[WebMethod]
public Class2 Test()
{
return new Class2();
}
I can compile it correctly, however, an exception was thrown when referring
the web service:
Member Class2.Name of type System.String[] hides base class member
Class1.Name of type System.String. Use XmlElementAttribute or
XmlAttributeAttribute to specify a new name.
I don't know how to use XmlAttributeAttribute or
XmlElementAttributeAttribute class to solve the problem, but I tried the
following style and failed:
[XmlElement("Class2Name", typeof(string[])),
XmlElement("Class1Name", typeof(string))]
public new string[] Name;
Any ideas will be greatly appreciately and thanks in advance.