Hi everyone,
I'm trying to build a WCF service that implements the following interface.
[ServiceContract]
public interface IWebService
{
[OperationContract]
void DoWork(BaseClass argument);
}
I also have the following classes:
public class BaseClass
{
private string[] elements;
}
public class SuperClass : BaseClass
{
public string Name
{
get{return elements[0];}
set{elements[0]=value;}
}
}
But when I consume the WCF service with the following client, it results in an error:
static void Main()
{
WebserviceClient _client = new WebserviceClient();
_client.Open();
SuperClass argument = new SuperClass();
argument.Name = "Joe";
_client.DoWork((BaseClass)argument);
}
There was an error while trying to serialize parameter http://tempuri.org/:argument. The InnerException message was 'Type 'SuperClass' with data contract name 'SuperClass:http://schemas.datacontract.org/2004/07/SharedTypes' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.
I know I could add the type 'SuperClass' to the list of knowntypes. But that is not my intention. I want to build a lot of wrapper classes around this baseClass that are easy to use for me/other users. But these wrapper classes are nothing more than BaseClasses.
The above example code is a simplified version of my real project.
Does anyone know what I have to do to make this work?
Kind regards,