我正在设计一个资源访问层,该层将位于由 5 个工作站和 7 个服务器组成的 LAN 上的数据库服务器上。 我对资源访问层的意图是向 LAN 上的任何 C# (.Net 3.5) 客户端公开一组定义良好的 C# 方法,并允许客户端访问存储在 DBMS 中的数据,而无需了解数据的存储方式正在被访问。 这基本上是一个简单抽象的练习。
到目前为止,我已经配置了一个对象关系映射器来从 DBMS (MS SQL Server 2008) 中检索数据作为实体。 然后,我编写了一个简单的数据访问类,它使用这些实体来检索和插入数据。 示例方法包括 GetUser(Int ID) 和 SetUser(Int ID, String 用户名, String 密码)。 所有方法都采用并返回本机类型,而不是实体对象或类似的包装器。
我想让这个类可以在 LAN 上远程访问,以便任何 C# 客户端代码都可以使用相同的单例类以简单的格式访问数据。 在 .Net 2.0 时代,显而易见的选择是使用 .Net 远程处理并声明该类继承 MarshalByRefObject。 然而,随着 .Net 3.5 和 WCF 的到来,还有更多的选择。
到目前为止我一直不愿意使用WCF作为资源访问层。 据我了解,所有数据都作为 SOAP 消息传递,如果数据要遍历 Internet 并由多个平台访问,这正是您想要的,但这对于我的需求来说可能有点过头了。 局域网上的所有平台都是windows vista或windows server 2008,都安装了.net 3.5。 没有真正需要将数据序列化为 XML,因为所有数据都是可能需要访问它的平台本机的。 我关心的另一个问题是速度。 该层需要尽可能快,如果需要将数据转码为 XML,则会产生开销。
我正在寻找有关在这种情况下使用的最佳 .Net 技术的任何建议。 我可能忽略了 WCF 可以为我提供的重大好处,或者可能有一种方法可以配置 WCF 以使用非常基本的有效负载。 然而,如果我的担忧是有根据的,那么我将使用 .Net 远程处理来代替它。
对于这个长问题表示歉意,欢迎任何建议。
感谢您抽出时间,
詹姆斯
I am designing a resource access layer that will sit on a database server on a LAN consisting of 5 workstations and 7 servers. My intention for the resource access layer is to expose a set of well defined C# methods to any C# (.Net 3.5) client on the LAN, and allow the client to access data stored in the DBMS without having any knowledge of how the data is being accessed. This is basically an exercise in simple abstraction.
So far I have configured an object relational mapper to retrieve data as entities from the DBMS (MS SQL Server 2008). I have then written a simple data access class that uses those entities to retrieve and insert data. Example methods include GetUser(Int ID) and SetUser(Int ID, String username, String password). All the methods take and return native types and not entity objects or similar wrappers.
I want to make this class remotely accessible on the LAN, so that any C# client code can use the same singleton class to access data in an simple format. In the days of .Net 2.0 the obvious choice would be to use .Net remoting and declare the class to inherit MarshalByRefObject. However with the arrival of .Net 3.5 and WCF there are many more options.
So far I have been reluctant to use WCF for the resource access layer. As I understand it all data is passed as SOAP messages, which is exactly what you want if the data is to traverse the internet and be accessed by multiple platforms but this may be a bit over kill for my needs. All platforms on the LAN are either windows vista or windows server 2008, all have .net 3.5 installed. There is no real need to serialize the data as XML since the all the data is native to the platforms who may need to access it. Another concern I have is speed. This layer needs to be as quick as possible, if the data needs to be transcoded to XML an overhead will be created.
I am looking for any advice on the best .Net technology to use in this situation. I may overlooked a significant benefit WCF can offer me or there may be a way to configure WCF to use very basic payloads. If however my concerns are well founded then I will use .Net remoting in its place.
Apologies for the long question, any advice would be welcome.
Thanks for your time,
James
发布评论
评论(3)
WCF 非常快,并且对于正确设计的使用,它通常比 .NET 远程处理更快。 Adinochestva 发布的第一篇文章讨论了序列化 .NET 数据集的性能,这是最坏的情况。
为了帮助您决定根据您的目的与 WCF 一起使用哪种绑定,请查看 CoDe 杂志上的这篇文章。 顶部的流程图非常有用:
http://www.code-magazine.com/article。 aspx?quickid=0605051&page=3
接近结尾处有对各种绑定及其使用的序列化方法的描述。
使用 .NET 远程处理,您还需要在客户端和服务上共享二进制依赖项,而 WCF 则不要求这样做。 通过这种方式,您可以获得远程处理无法获得的版本控制支持。 远程处理也是 Microsoft 不再投资的一项技术...但是,他们正在大力投资 WCF。
希望您会发现 WCF 的好处超过其局限性。
WCF is very fast and for properly-designed usage it is often faster than .NET remoting. The first article Adinochestva posted dealt with the performance of serializing .NET DataSets, which is the worst-case scenario.
To help you decide which binding to use with WCF for your purposes, take a look at this article from CoDe magazine. The flowchart at the top is very helpful:
http://www.code-magazine.com/article.aspx?quickid=0605051&page=3
Near the end there is a description of the various bindings and the serialization method they use.
With .NET remoting you are also requiring a binary dependency be shared on both the client and service, which is not a requirement with WCF. This way you get versioning support you wouldn't get with remoting. Remoting is also a technology that Microsoft is no-longer investing in... they are investing heavily in WCF, however.
Hopefully you will find that the benefits of WCF outweigh its limitations.
使用 WCF,您可以使用 TCP/IP 绑定,速度非常快,但只能在 Windows 平台上工作(这在您的情况下是可以的)。 它的工作方式与任何 Web 服务一样,只不过它使用 net.tcp:// 而不是绑定到 http://
With WCF you can use TCP/IP binding which is very fast but will only work on windows platforms (which is OK in your case). It works just like any web service except instead of binding to http:// it uses net.tcp://
您可以看到比较 此处或微软所做的比较这里
但如果选择使用 wcf ,请确保不要为每个请求创建 ChannelFactory
you can see a comparison here or a comparison which microsoft made here
But if choosed to use wcf , make sure that you dont Create ChannelFactory for each request