WCF/SOA 中的接口实现测试

发布于 2024-08-31 18:37:18 字数 1085 浏览 6 评论 0原文

我有一个报告服务,可以实现许多报告。每个报告都需要特定的参数。逻辑相关的参数组被放置在一个接口中,然后报告将实现该接口:

[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; }
}

问题是 WCF DataContractSerializer 没有在我的客户端库中公开这些接口,因此我无法编写我计划的通用报告生成前端到。 WCF 是否可以公开这些接口,或者这是序列化器的限制?如果是后一种情况,那么这种 OO 模式的规范方法是什么?

我研究过 NetDataContractSerializer 但它似乎不是官方支持的实现(这意味着它不是我的项目中的一个选项)。目前,我已经决定将接口包含在服务和客户端应用程序之间通用的库中,但这对我来说似乎是不必要的额外依赖。当然有更直接的方法来做到这一点吗?我的印象是 WCF 应该取代 .NET 远程处理;检查对象是否实现接口似乎是远程接口所需的最基本功能之一?

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 interfaces 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飞烟轻若梦 2024-09-07 18:37:19

我相信您只需要将 ServiceContract 属性也放在接口定义上,如

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

等......

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文