문제

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

도움이 되었습니까?

해결책

You could try:

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

    [DataMember]
    public RequestTypeEnum RequestType { get; set; }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top