使用 Windows 和 Web 服务控制您的分布式应用程序





4.00/5 (1投票)
使用 Windows 和 Web 服务控制您的分布式应用程序

引言
我正在做一个项目,该项目使用 Windows 和 Web 服务连接客户端 PC 和服务器。
背景
这个想法来源于我不得不通过电话呼叫中心从餐厅订餐,使用 XML 文件,避免网络问题并支持并行请求。
使用的技术
- (Windows 服务,Web 服务) 作为核心操作
- Windows 应用程序作为 (用户界面,监控和通知)
- 系统经过测试并运行良好,使用了
- Microsoft
- WindowsXP
- XMLnWebService
- 所有部分的 C#
- Microsoft CLR1.1
- Visual studio.NET 2003
系统结构
"发送"
代码在执行完操作后开始,并在 Server1 的 [Send 文件夹] 中释放一个文件,然后 server1 尝试通过 Web 服务将其发送到所需服务器。如果发送失败,则将数据发送到与基本系统并行工作的 "Retry" 系统。
"重试系统"
- * 重试系统,尝试重试发送数据 n 次,然后(如果重试系统发送失败)将数据发送到传真系统,
- * 传真系统尝试发送数据
如果传真重试 n 次失败,则将数据转储到失败文件夹并创建报告
--------- - 如果成功发送,则客户端计算机上的 Web 服务将数据转储到客户端的 [received 文件夹] 或 server2 的 [received 文件夹]。
- 完成此操作后,客户端计算机上的文件观察器会获取 [received 文件夹] 中收到的文件并执行任何操作
--------
... 然后反向流程开始 - Server2 或客户端计算机将文件发送到 [send 文件夹]
- Windows 服务文件观察器会捕获它并尝试调用位于 server1 上的 Web 服务,就像在 server1 上所做的那样。
- 当 server1 的 Windows 服务接收到 server2 通过 Web 服务发送的文件时,它会根据接收到的数据执行任何操作。
监控和通知系统
系统分为 2 个部分
- 核心系统 (Windows 服务和 Web 服务)
- 接口系统 (Windows 应用程序 "
Monitor
"、"Notification
")
1. 监控
这是附加项目中“Windows 服务和 Windows 接口”的名称。
此应用程序用于控制 Windows 服务(停止/运行),并监控客户端连接(通过尝试调用目标 PC 上 Web 服务上的函数 "Is Connected" 来返回 true
)。
以及定义配置接口
- 重试系统值
- 发送和接收文件夹的路径
- 注册的服务器(名称和 IP)
以及其他任何值,如重试到期、间隔、传真重试等。
2. 通知
该系统位于监控系统内部,但它抽象为一个在文件夹(通知)上具有文件观察器的系统。
当 Windows 服务需要向用户发出事件警报时,它会将包含警报信息的放置在通知文件夹中的文件。
然后文件观察器会捕获它并通知用户。
它还可以通过附加的 INI 文件进行自定义,以放置任何图像/延迟/等。
我想感谢 John O'Byrne 的文章: Taskbar Notify。
它在这一部分帮助了我很多,但我增加了一些额外的选项,比如动态皮肤。
我还附带了 SQL 服务器数据库来控制通知,并记住错过的通知和警报,以便以后可以恢复它们。
Using the Code
"如果您想更改配置文件位置 c:\Server1\settings,可以在 Monitor 和 Windows Service 应用程序的结构类(config structure)中进行更改"。
下面将简要介绍如何使用代码
//1) in the winServiceAndWindowsInterface application I overloaded Notify for
easy use But it takes structure contains all properties that event can have for example :
//Creating structure object to fill with event's info
StructDisplayInfo inInfo = new StructDisplayInfo();
inInfo.initilize();
//Set some of it's properties
inInfo.popupTitle = title; inInfo.popupPrifeInfo = prifeInfo;
//select type (notify/alert/Error)
inInfo.TypeInt =(int) StructDisplayInfo.Typeenum.Notify;
//Real Display it
NotifyMe myNotify = new NotifyMe(inInfo);
==================================
(other example)
this one I think have Full properties
StructDisplayInfo inInfo = new StructDisplayInfo();
inInfo.initilize();
inInfo.TypeInt = (int)type;
//popup Settings inInfo.popupTitle = title;
inInfo.popupPrifeInfo = prifeInfo;
//form settings inInfo.frmText = title;
inInfo.Maintitle = formMainText;
inInfo.lblDetails = lblDetails;
inInfo.details = Details;
inInfo.DateTimeOfEvent = EventDateTime;
inInfo.ServerIP = ServerIP;
inInfo.ServerName = ServerName;
inInfo.Info1 = info1;
inInfo.lblInfo1_title = lblInfo1;
inInfo.Info2 = info2; inInfo.lblInfo2_title = lblInfo2;
inInfo.fileName= fileName;
inInfo.Footer = footer;
//system Settings inInfo.ShowForm = true;
inInfo.AddtoDatabase = AddtoDatabase;
//realize popup NotifyMe myNotify = new NotifyMe(inInfo);
项目设置步骤
要设置此项目,您需要
- 将文件夹 Server1 放在 c:\ (稍后可以配置)。
- 从 c:\Server1\Settings\,您可以通过 2 个 INF 文件配置与系统相关的所有路径和设置
- "MonitorConfigrations.ini" 用于监控系统和通知,以及监控数据库连接字符串(数据库附加在:Server1\Database\myDatabase_Data.MDF)
- "inf.ini" 用于服务器、重试和其他核心设置
- 在您的 SQL 服务器中设置数据库(用于记住错过的事件)一个表,这样您就可以将其与您已有的数据库连接并将其连接字符串设置在 "MonitorConfigrations.ini" 中。
- 设置 Windows 服务:"Server1WindowsSevice.exe"
使用 .NET Tools 支持的 Installutil.exe。 - 在您的 IIS 或另一台计算机上设置 XML Web 服务(并记住将其发送到 inf.ini)。
示例
[RegisteredServers]
IP1=http://10.0.0.3/Server1WebService/Service1.asmx
IP2=...... (have to be the full address of the target web service)
[RegisteredServersNames]
Server1=Server1
Server2=myPC(just a Nike name )
然后运行 Windows 服务……它应该能正常工作。
然后关于用户界面,它在文件 "winServiceAndWindowsInterface.exe" 中。
您可以轻松运行它。它将出现在任务栏中,并将控制和监控工作。
关注点
该项目是完全动态的,使用多线程,特别是在它每隔一段时间检查所有服务器的状态时,它们都同时检查(而不是顺序检查)。还可以处理服务器和 Windows/Web 服务并控制它们,并在连接失败时重试等。
未来工作
我正在寻找
- 增强用户界面 Windows 应用程序
- 包括客户端 PC 的用户界面
- 增强事件通知系统
- 当然,欢迎您对任何升级想法提出评论:)
历史
- 2010年8月15日:首次发布