WCF 服务契约设计。用例控制器合适吗?

发布于 2024-09-16 20:26:07 字数 665 浏览 10 评论 0原文

首先,如果之前有人问过这个问题,我深表歉意,但我找不到任何可以直接回答这个问题的内容。

这是我的问题。我继承了一个产品,它的设计非常灵活,填充(silverlight)表单上的几乎每个组合框和文本块都需要服务请求。有些屏幕需要多达 15 个单独的请求才能填充!

现在,我已经在很多场合使用 WCF Web 服务,并且将服务合同拆分为小的离散操作从来没有太大的打击,..遗憾的是,这个项目的情况并非如此。所以这让我想知道......

没有计划将服务暴露在我们自己的墙外。 没有计划为该特定服务编写另一个客户端。那么我不能在服务端编写一个“用例控制器”吗?因此,在“创建投诉”屏幕中,不是使用诸如...

  1. GetComplaintTypes
  2. GetCustomerTypes
  3. GetAreaDetails
  4. 等等之类

的请求列表来填充表单,而是只有一个名为“GetCreateComplaintData”的操作合约。当只有一个客户端必须将所有这些请求聚合和同步为有意义的内容时,以如此粒度公开如此多的操作似乎很疯狂。为什么不首先揭露一些有意义的事情呢?

更重要的是,如果您不打算向第三方公开服务 API,这不是比公开数据库中表的 CRUD 操作更好的策略吗?

感谢所有帮助和意见。 提前致谢。

First off, apologies if this question has been asked before but I couldn't find anything that answers this directly.

Here's my problem. I've inherited a product which has been designed to be so flexible that populating pretty much every combobox and textblock on the (silverlight) form requires a service request. Some of the screens take upward of 15 separate requests just to populate!

Now I've worked with WCF web services on a number of occasions and having service contracts split into small discrete operations has never been too much of a hit,..sadly this is not the case for this project. So it left me wondering...

There are no plans to expose the service outside of our own walls. There are no plans to write another client for this particular service. So couldn't I just write a 'use case controller' at the service end? So, in a 'create complaint' screen, instead of having a list of requests like...

  1. GetComplaintTypes
  2. GetCustomerTypes
  3. GetAreaDetails
  4. And so on...

to populate the form I would just have a single operation contract called 'GetCreateComplaintData'. It seems crazy to have so many operations exposed in such granularity when there's only one client which then has to aggregate and synchronise all these requests into something meaningful. Why not expose something meaningful in the first place?

More to the point, if you don't intend on exposing the service API to third parties isn't this a better strategy than exposing CRUD ops for tables in the DB?

All help and opinions are appreciated.
Thanks in advance.

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

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

发布评论

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

评论(5

凹づ凸ル 2024-09-23 20:26:07

我觉得你的想法还是蛮OK的。

作为一种中间方式,您还可以考虑将多个 WCF 请求批处理为一个的方法。 此处描述了这种方法以及如何对其进行编程。

I think your idea is quite OK.

As an in-between way, you may also think about an approach where you batch several WCF requests into one. This approach and how to program it is described over here.

辞取 2024-09-23 20:26:07

我认为你首先必须确定性能问题到底出在哪里。 IIS 真的无法处理您发送给它的请求量吗?或者是每个单独的请求花费的时间太长,因为数据库无法提供您的数据,并且看起来 IIS 无法因此处理压力。

我不确定以下两个场景之间是否存在真正的区别:

  • 每个执行数据库选择语句的小请求。
  • 执行大量数据库选择语句的一个大型请求。

当然,我不确定您的具体情况,但就性能而言,事先确切地了解为什么要优化总是明智的。

I think you first have to determine where exactly the performance problem is. Is it really true that IIS can't handle the amount of requests you are sending to it? Or is each individual request taking too long because the database can't serve up your data and does it just look like IIS can't handle the pressure because of this.

I'm not sure there's a real difference between the two following scenario's:

  • Small requests that each execute a database select statement.
  • One large request that executes a lot of database select statements.

Of course I'm not sure about your specific situation but where performance is concerned, it's always wise to know beforehand exactly why you're optimizing.

带上头具痛哭 2024-09-23 20:26:07

业务逻辑之上的 WCF 服务应该公开高级业务操作的外观,而不是低级 CRUD 操作。 CRUD操作服务用于公开数据(如WCF数据服务)。

WCF service on the top of business logic should expose facade of high level business operations not low level CRUD operations. CRUD operation services are for exposing data (like WCF data services).

为你拒绝所有暧昧 2024-09-23 20:26:07

这是我对这一切的看法。答案一如既往,这取决于情况。

以下是如何使用 WCF 构建 SOA 的一些实际示例。

我建议您阅读 Thomas Erl 和 Roger Sessions 撰写的文章,这将使您牢牢掌握 SOA 的含义。

构建 SOA

SOA 设计模式

在 SOA 中实现完整性

为什么您的 SOA 应该像大众甲壳虫一样

为你的老板解释 SOA

Here is my take on it all. The answer is as always, it depends.

Here are some practical examples of how to build a SOA using WCF.

I would suggest you read articles by Thomas Erl and Roger Sessions, this will give you a firm handle on what SOA is all about.

Building a SOA

SOA Design Pattern

Achieving integrity in a SOA

Why your SOA should be like a VW Beetle

SOA explained for your boss

时光沙漏 2024-09-23 20:26:07

通过 WCF 使用 CRUD 模式从数据库公开数据的最简单方法是使用 WCF 数据服务。实际上,除了您想要公开的模型之外,您无需在服务器端开发任何其他内容,如果您使用 EF 模型来访问数据库,则也可以从 EF 模型自动推断出该模型。

巴勃罗.

The simplest approach for exposing data from the DB using a CRUD pattern with WCF is to use WCF Data Services. You don't actually do not develop anything on the server side more than the model you want to expose, which it could be also automatically inferred from an EF model if you are using that for getting access to the database.

Pablo.

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