将 .NET 类库(主要定义 CRUD 操作)公开为服务

发布于 2024-09-10 07:18:12 字数 249 浏览 5 评论 0原文

将现有(类)库(主要定义 CRUD 操作)公开为服务WCF 服务 > 或 WCF 数据服务),以便它可以与 SilverlightAjax 一起使用。是否有可以支持此功能的工具(代码生成器、RAD 工具)? 预先感谢您的帮助和提示。

What is the best, efficient and fastest way to expose an existing (class) library (which primarily defines CRUD operations ) as a service (WCF Service or WCF Data Service), so that it can be used with Silverlight or Ajax. Are there tools (code generators, RAD tools), which can support this ?
Thanks in advance for your help and hints.

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

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

发布评论

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

评论(3

坏尐絯 2024-09-17 07:18:12

最好的方法是使用 WCF 自己创建一个包装器。

您应该这样做,而不是使用一些自动化来直接公开库,因为:

  • 安全性,您是否希望任何人随时调用库上的任何内容?
  • 大多数库假设它们是直接调用的,而不是通过服务调用的(请参阅
  • WCF 默认情况下是无状态的:您需要弄清楚如何管理库假定的任何状态(您将不再拥有单个客户端)。
  • 我有提到安全吗?

The best approach is to use WCF to create a wrapper yourself.

You should do this, rather than using some automation to just expose the library directly because:

  • Security, do you want anyone to call anything on the library anytime?
  • Most libraries assume they are called directly rather than over a service (see fallacies of enterprise development).
  • WCF is by default stateless: you need to work out how to manage any state the library assumes (you will no longer have a single client).
  • Did I mention security?
飘落散花 2024-09-17 07:18:12

如果您的类只是一个愚蠢的数据集合,只需在其上添加一个 DataContract 即可。 (不要忘记名称空间,否则稍后您会自责。)然后您可以使用 Web 项目公开它。

如果你的课堂上有真正的逻辑,那么你就有麻烦了。没有与 Silverlight 应用程序共享业务逻辑的好方法。他们尝试使用 RIA 服务,但效果并不理想。

If you class is just a dumb collection of data, just throw a DataContract on it. (Don't forget the namespace, otherwise you will kick yourself later.) You can then expose it using a web project.

If you have actual logic in your class then you are in trouble. There is no good way to share business logic with Silverlight apps. They try with RIA Services, but it just doesn't make the grade.

枕头说它不想醒 2024-09-17 07:18:12

您应该看看 WCF 数据服务,尤其是在 .NET 4 中。虽然您必须创建一个或多个数据上下文类来公开您的实体以及公开 IQueryable 和实现 IUpdatable,但您可以利用支持框架WCF 数据服务为您的数据负载提供标准化协议 (OData)。

在 .NET 4 和 Visual Studio 2010 中,WCF 数据服务越来越被接受,并被 Microsoft 推为 Silverlight 应用程序的良好数据访问工具。

我认为它至少值得一看。 MSDN 上有很多关于它的信息,尽管我认为有些地方组织得不是很好。这是 MSDN 中有关滚动您自己的 WCF 数据部分的链接使用内置反射提供程序的服务。 (该示例仅显示数据检索,因为它比数据更新/插入/删除简单得多,但文章中有一个有关如何实现 IUpdatable 的链接。)

通过 WCF 数据服务公开 IQueryable 应该非常快。 IUpdatable 将花费更多时间(因为您需要为每个实体实现插入/更新/删除)。但是,一旦您启动并运行它(这不会花费太长时间),您就可以轻松调整安全设置、添加自定义服务方法以及添加其他功能和/或实体。对于您所描述的内容来说,这是一个很好的框架。

我希望这有帮助。

You should take a look at WCF Data Services, especially in .NET 4. While you'll have to create the data context class or classes to expose your entities along with exposing IQueryable and implementing IUpdatable, you then can take advantage of the supporting framework that WCF Data Services provides along with a standardized protocol (OData) for your data payloads.

In .NET 4 and Visual Studio 2010, WCF Data Services are becoming more accepted, and are being pushed by Microsoft as a good data access vehicle for Silverlight applications.

I think it's at least worth checking out. There's a lot of information about it on MSDN, although I don't think it's organized very well in places. Here's a link to the section in MSDN on rolling your own WCF Data Service using the built-in reflection provider. (The example only shows data retrieval because it's much simpler than data updates/inserts/deletes, but there's a link in the article on how to implement IUpdatable.)

Getting an IQueryable exposed through WCF Data Services should be pretty quick. IUpdatable will take a little more time (since you need to implement Insert/Update/Delete for each entity). But once you get it up and running (which shouldn't take too long), you can then tweak the security settings, add custom service methods, and add additional functionality and/or entities pretty easily. It's a nice framework for what you're describing.

I hope this helps.

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