Help! Web service can't be accessed!

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.
 
M

Manohar Kamath

How about:


XmlElement[DataType="string[]", ElementName="Class2Name"]

or

XmlAttribute [DataType="string[]", AttributeName="Class2Name"]

(I think you have the DataType and ElementName reversed in your code)

Hope that helps.
 
J

James

Thanks for your kindly reply Manohar.

Unfortunetely it didn't work. I wrote in that way 'cause there is a
constructor of the XmlElementAttribute class accepting the ElementName and
Type parameters in the exactly sequence as I wrote.

Any other suggestions?

Thanks again.

Manohar Kamath said:
How about:


XmlElement[DataType="string[]", ElementName="Class2Name"]

or

XmlAttribute [DataType="string[]", AttributeName="Class2Name"]

(I think you have the DataType and ElementName reversed in your code)

Hope that helps.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com


James said:
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.
 
D

Dan Rogers

Try not to design classes like this. What are you trying to accomplish?
Have two fields with one accessor? Or have one override the definition of
the other? Or is this just a mistake on your part?

Try to put a specific XmlElementAttribute on each name property - don't
just change the one. Do both, to remove the ambiguity.
--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top