简体   繁体   English

使用WCF进行Windows服务设计

[英]Windows service design with WCF

Currently I'm working on a design for a Windows Service application to fetch reports from an Oracle database, aggregate them to a message and send it to an external WCF SOAP service. 目前,我正在开发一个Windows服务应用程序的设计,用于从Oracle数据库获取报告,将它们聚合为一条消息并将其发送到外部WCF SOAP服务。 I would be grateful for some design suggestions concerning Windows services. 对于有关Windows服务的一些设计建议,我将不胜感激。

Should Windows Services use eg dedicated WAS/self-hosted WCF service (net.pipe/net.tcp) that provides data to achieve better separation / reusability? Windows服务是否应使用例如专用WAS /自托管WCF服务(net.pipe / net.tcp)来提供数据以实现更好的分离/可重用性?

So I would add a WCF service (net.pipe) that provides data (eg a GetReport method). 所以我会添加一个提供数据的WCF服务(net.pipe)(例如GetReport方法)。 The Windows Service application would call GetReport and call the remote SOAP service to forward the aggregated message. Windows服务应用程序将调用GetReport并调用远程SOAP服务以转发聚合消息。 The remote service and its client code are likely to change. 远程服务及其客户端代码可能会发生变化。 It might be adapted for different customer projects. 它可能适用于不同的客户项目。

If I understand correctly, your windows service will periodically fetch some data from the database and upload that data to a remote web service. 如果我理解正确,您的Windows服务将定期从数据库中获取一些数据并将该数据上载到远程Web服务。

This means that your windows service is a client in terms of WCF communication and you won't need to implement any WCF server code inside it. 这意味着您的Windows服务是WCF通信方面的客户端,您不需要在其中实现任何WCF服务器代码。

All you'll have to do is to connect to the remove web service and upload the data, eg using a client proxy generated for this remove service. 您所要做的就是连接到删除Web服务并上传数据,例如使用为此删除服务生成的客户端代理。

I don't think that it is required to add another WCF service that provides the data instead of querying the database directly as long as you don't have the requirement that another application will use the same WCF service. 我认为只要您没有要求另一个应用程序使用相同的WCF服务,就不需要添加另一个提供数据的WCF服务而不是直接查询数据库。 Until then I wouldn't add the service for the following reasons: 在此之前,我不会出于以下原因添加服务:

  • Another WCF service increases the complexity of the deployment and makes it harder to install and configure. 另一种WCF服务增加了部署的复杂性 ,使安装和配置变得更加困难。
  • The connection to the new WCF service is another point that can break . 与新WCF服务的连接是另一个可以破解的点
  • If you handle lots of data, getting them from the database directly is much more efficient instead of transferring them over a service protocol. 如果处理大量数据,直接从数据库获取数据会更有效,而不是通过服务协议传输它们。 As I understand your question, you aggregate the data in the windows service not in the database. 据我了解你的问题,你聚合Windows服务中的数据而不是数据库中的数据。 Therefore you'd have to move the aggregation code to the new service also. 因此,您还必须将聚合代码移动到新服务。

As said before, this recommendation will change once you have another potential client to the new service. 如前所述,一旦您有另一个潜在客户到新服务,此建议将会改变。 In order to prepare for that, you should of course choose a design in your windows service that separates concerns well and is a good starting point to move some components later. 为了做好准备,您当然应该在Windows服务中选择一种能够很好地区分关注的设计,并且是稍后移动某些组件的良好起点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM