编写WCF服务是一个好主意吗? [英] Is it a good idea to write WCF sevice?

查看:73
本文介绍了编写WCF服务是一个好主意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要专家的大或是。



1.我想写一个代码库。该库包含与硬件接口的一组功能。它是一个不断增长的图书馆。

2.第三方应用程序与图书馆交谈以访问硬件资源。



我打算写一个WCF通过IIS托管的服务库。第三方应用程序通过http与libarary交谈。





这是一个好主意吗?



谢谢

Jis

I need a big YES or NO from experts.

1. I want to write a code library. THe library contain set of functions interfacing with hardware. Its a growing library.
2. The third party applications talk to library to access hardware resources.

I am planning to write a WCF services library hosted over IIS. The third party appliations talk to libarary over http.


is this a good idea to go ahead?

thanks
Jis

推荐答案

很多人会说WCF与您正在使用的硬件无关。那是真的。



与此同时,我会说:如果你考虑到发展战略,这是一个很好的主意。如果你有大计划,那么规模更大。我可以说我过去常常提出并积极开发类似的想法。



更确切地说,你应该独立于WCF开发硬件控制。这个硬件尽可能地与编程的任何其他方面隔离是非常重要的。基本上,有两个编程领域需要彻底隔离:硬件控制和UI。隔离它们。



现在,如何确保您的硬件控制单元与其他所有设备完全隔离,然后与系统没有任何耦合,甚至偶尔会引入?可能的解决方案之一是:代表每个集成硬件单元,将控制软件打包为单独的WCF服务。



当然,这个架构决策到目前为止并不是最简单的。 (最简单的方法是以临时方式控制硬件,为方便起见。但是你可以将它作为开发每个硬件控制单元的第一步,并且当它经过良好调试后,迁移到WCF服务。)但是让我们考虑好处。



首先,回到隔离的重要要求。您始终可以将WCF服务放在LAN上的全新系统上,并确保没有依赖关系或与运行主应用程序的计算机上的任何内容耦合。现在,让我们看看当您最终通过WCF服务实现硬件单元的独立功能时会发生什么。现在,您可以用无人的双手开发不同的架构。如果是硬件,则硬件单元的控制权将从连接到此部件的主机的位置抽象出来。即使您现在在同一台计算机上完成所有工作,您仍然可以确保,您可以随时将此服务移动到任何其他计算机,甚至不需要对软件进行任何更改,只能在某些配置文件中使用。此外,您的服务的客户可以是异构的,在许多不同的平台上使用您的硬件单元。



即使是现在,您可以拥有一个基于WCF的精简客户端小型平板电脑,随身携带,比如在一些半拆机下的黑暗处爬行,并从那个地方进行故障排除。与此同时,您可以将一些机器部署到一些大客户手中,如果您设法使用多台机器,那么他们只需使用一台或两台前端计算机来控制您机器的整个工厂。他们。 :-)



总的来说,这就是它的外观。您需要付出额外的努力来实施此体系结构决策。但是当它完成后,它将获得巨大回报,但前提是你开发的大系统可以从自由和灵活性中获益。而且你可以获得的灵活性是惊人的。我只能补充说,在我的情况下,这个决定的好处已得到充分证明。







是的,PIEBALDconsult提出了一个很好的观点。如果您自行托管服务,则只能享受这些优惠。永远不要使用IIS。适当的形式是Windows服务。它会给你一些调试问题。所以,看看我解决这个问题的方法:使用UI配置Windows服务 [ ^ ]。



-SA
Many would say that WCF is unrelated to the hardware you are working with. That would be true.

At the same time, I'll say: in certain way, this is an excellent idea, if you take into consideration the strategy of development in larger scale, if you have big plans. I can tell that I used to put forward and actively develop a similar idea.

More exactly, you should develop the hardware control independently from WCF. It's very important that this hardware is isolated from any other aspects of programming as much as possible. Basically, there are two fields of programming which require thorough isolation: hardware control and UI. Isolate them.

Now, how to make sure that your hardware control units are really isolated from everything else, then there is no any coupling with the system, even occasionally introduced? One of possible solutions is: represent every integrated hardware unit with the control software packaged as a separate WCF service.

Of course, this architectural decision is by far not the simplest. (The simplest would be having some application controlling hardware in ad hoc manner, for the same of convenience. But you can do it as a first step of your development of each hardware control unit, and, when it is well debugged, migrate to a WCF service.) But let's consider the benefits.

First, get back to the important requirement of isolation. You can always put the WCF service on a brand new system on the LAN and make sure that there are no dependencies or coupling with whatever you have on the computer running your main application. Now, let's see what happens when you finally achieve the independent functionality of the hardware unit through a WCF service. Now you can develop different architectures with untied hands. The control of your hardware units became abstracted from the location of the host connected to this piece if hardware. Even though you do all the work on the same computer now, you will be sure, that at any time you can move this service to any other computer, without even any changes in software, only in some configuration files. Moreover, the clients of your service can be heterogeneous, use your hardware unit on many different platforms.

Even now, you could have a lean WCF-based client on a tiny tablet computer, take it anywhere with your, say, crawl in the dark place under some semi-disassembled machine, and perform your troubleshooting from that place. At the same time, you can come to deployment of a number of machines to some big customer, who will enjoy using just one or two front-end computers for controlling of the whole factory of your machines, if you manage to cell so many of them. :-)

Overall, this is how it looks. You pay extra effort on implementation of this architectural decision. But when it's done, it will pay off in large, but only if you developing big system where you can benefit from freedom and flexibility. And the flexibility you can get can be amazing. I can only add that in my case the benefits of this decision were well-proven.



And yes, PIEBALDconsult made a good point. You only can have these benefits if you self-host the service. Never use IIS. The adequate form would be the Windows Service. It will give you some debugging problems. So, also look at my method of solving this problem: Configure Windows Service with UI[^].

—SA


您打算将这些服务公开给内部应用程序,甚至是外部世界?

然后是 - 转到WCF。
Do you intend to expose these services to an internal application or even to the outside world?
Then yes - go for WCF.


Jishnu - 如果您的IIS服务器和您的硬件设备连接的机器是同一台机器,那么WCF不是一个糟糕的选择。



但是,你可能不得不考虑并发 - 通过使用HTTP,多个用户可以同时发送WCF请求,我不要我认为您的硬件设备可以为多个请求提供服务。



我建议2种方法

1.将WCF与队列结合使用(MSMQ),所有用户请求将逐一处理

2.或从WCF服务掩盖您的硬件设备,我的意思是WCF服务不会直接与您的硬件设备通信,而是与数据库或XML文件或临时存储。您可以考虑创建一个监视硬件并与临时存储进行交互的Windows服务。
Jishnu - If your IIS server and the machine your are connecting your hardware device is same machine, then WCF is not a bad option.

However, you may have to think about Concurrency - by using HTTP, multiple users may send WCF requests at the same time, i don't think that your hardware device can service multiple requests.

I would recommend 2 approaches
1. Use WCF in conjunction with a Queue (MSMQ), where all user requests will be processed one by one
2. or Mask your hardware device from WCF service, i mean WCF service will not talk to your hardware device directly but with a database or XML file or a temp storage. You can think about creating a Windows service which monitor your hardware and interact with your temporary storage.


这篇关于编写WCF服务是一个好主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆