将 .NET 类库(主要定义 CRUD 操作)公开为服务
将现有(类)库(主要定义 CRUD 操作)公开为服务(WCF 服务 > 或 WCF 数据服务),以便它可以与 Silverlight 或 Ajax 一起使用。是否有可以支持此功能的工具(代码生成器、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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最好的方法是使用 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:
如果您的类只是一个愚蠢的数据集合,只需在其上添加一个 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.
您应该看看 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.