Question

I have a WCF service with method:

[OperationContract]
public bool TestCustomRequest(RequestBase request)
{
    return true;
}

In referenced Class Library project I have 2 classes:

[DataContract]
public abstract class RequestBase
{
    [DataMember]
    public string Id { get; set; }

    [DataMember]
    public RequestTypeEnum RequestType { get; set; }
}

And inherited class:

[DataContract]
public class CustomRequest : RequestBase
{
    [DataMember]
    public string CompanyId { get; set; }
}

When on client side I'm adding service reference, I can see only RequestBase class. Is it possible, to add all classes that inherits RequestBase into service reference and initialize them on client side?

Or I have to overload TestCustomRequest method for each possible incoming parameter type ?

Thank you

Was it helpful?

Solution

You could try:

[DataContract]
[KnownType(typeof(CustomRequest))]
public abstract class RequestBase
{
    [DataMember]
    public string Id { get; set; }

    [DataMember]
    public RequestTypeEnum RequestType { get; set; }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top