c# - inheritance : asmx webservice alway return subclass -


i have problem asmx webservices. have object

public class animal {     public string id = null;     public string name = null; }  public class dog: animals {     public string surname = null;     public string color = null; } 

and webservice

public animal getanimal() {   animal result = new dog();   return result; } 

the problem webservice alway return dog. there easy way can return animal? (i see 2 solutions don't like:

animal result = new animal(); 

or

animal resultdog = new dog(); animal result = new animal(); result.id = resultdog.id result.color = resultdog.color  

)

the problem webservice alway return dog

it returns dog type because ... thats returns

public animal getanimal() {   animal result = **new dog();**   return result; } 

your consuming code should able refernce animal type without problems:

animal = getanimal(); a.id="id"; a.name="name"; 

can more specific on error or problem having?


Comments