开发者

Testing for interface implementation in WCF/SOA

开发者 https://www.devze.com 2022-12-29 06:44 出处:网络
I have a reporting service that implements a number of reports.Each report requires certain parameters.Groups of logically related parameters are placed in an interface, which the report then implemen

I have a reporting service that implements a number of reports. Each report requires certain parameters. Groups of logically related parameters are placed in an interface, which the report then implements:

[ServiceContract]
[ServiceKnownType(typeof(ExampleReport))]
public interface IService1
{
    [OperationContract]
    void Process(IReport report);
}

public interface IReport
{
    string PrintedBy { get; set; }
}

public interface IApplicableDateRangeParameter
{
    DateTime StartDate { get; set; }

    DateTime EndDate { get; set; }
}

[DataContract]
public abstract class Report : IReport
{
    [DataMember]
    public string PrintedBy { get; set; }
}

[DataContract]
public class ExampleReport : Report, IApplicableDateRangeParameter
{
    [DataMember]
    public DateTime StartDate { get; set; }

    [DataMember]
    public DateTime EndDate { get; set; }
}

The problem is that the WCF DataContractSerializer does not expose these interfaces in my client library, thus I can't write the generic report generating front-end that I plan to. Can WCF expose these interfaces, or is this a limitation of the serializer? If the latter case, then what is the canonical approach to this OO pattern?

I've looked into NetDataContractSerializer but it doesn't seem to be an officially supported implementation (which means it's not an option in my project). Currently I've resigned myself to including the interfa开发者_StackOverflow社区ces in a library that is common between the service and the client application, but this seems like an unnecessary extra dependency to me. Surely there is a more straightforward way to do this? I was under the impression that WCF was supposed to replace .NET remoting; checking if an object implements an interface seems to be one of the most basic features required of a remoting interface?


I believe you just need to put the ServiceContract attribute on the interface defintions, too, as in

[ServiceContract]
public interface IReport
{
    [OperationContract]
    string PrintedBy { get; set; }
}

etc...

0

精彩评论

暂无评论...
验证码 换一张
取 消