128 Part II Message Endpoints
Taking It Further
How can you extend this base functionality in a way that’s useful in an EI scenario?
If you use this approach in conjunction with the FileSystemWatcher service, you
can cause code to execute on the server whenever the file is updated. Perhaps
that code will send e-mail to the customer, notifying him that some data had
been changed by one of your organization’s partners.
Countless applications exist for Web services as file endpoints. The strong-
est argument for using this technique is the ability of file endpoints to grant file
system access to external users and systems, without completely compromising
security on that file system. Combining Web services with the file system allows
you to strictly control the actions of the user and isolate those actions from
other parts of the system. You can also perform any number of validations or
security checks before writing the content to the file, providing significant
advantages over using the file system alone.
You have seen how simple .NET makes exposing existing code as Web services
and the advantages Web service facades offer over other methods, such as FTP.
You have also seen how using Web services to expose file system operations is
more secure than using conventional methods, such as directory sharing. The
FileSystemWatcher class also allows you to create a file endpoint that can
respond to an update and operate in an event-driven manner, unlike polling or
other nonevent methods. In the next section, we will discuss how to use
Microsoft Windows Scheduled Tasks to schedule messages and events.
Using Windows Scheduled Tasks
Although scheduled tasks can be used many different ways in EI, they are most
commonly used as a method for executing an .exe, script, or batch file. Thus, we
will describe them in this file endpoints chapter. The new Windows Scheduled
Tasks in Microsoft Windows 2000 and Microsoft Windows XP offer more capa-
bilities than Win At (the scheduling utility from Microsoft Windows NT) and are
much easier to create and manage.
Often you will need to have a specified file, script, or executable run on a
time basis rather than an event basis. For example, you might want a simple
application to gather all the orders from one corporate office at 11:59:59 and
send them to corporate headquarters on a daily basis. In addition, you might
want to write code that wakes up every 10 minutes to check whether one of
Chapter 6 File Endpoints 129
the pollers is running and starts if no poller is running. You likely will need
to accomplish a host of tasks at specified time intervals. Of course, you can
write code to do this, but why not utilize the Scheduled Tasks capability
instead? Doing so frees you not only from writing this code, but also from
Start by creating a simple scheduled task, as follows:
1. In Windows XP Professional, click Start/Settings/ControlPanel
2. Double-click Add Scheduled Task to start the wizard. You should see
3. Click Next. The following dialog box will appear:
130 Part II Message Endpoints
4. Select the program from the list, or browse and select the program
you want to schedule. For this example, select Internet Explorer and
click Next, as shown here:
5. By default, the task is named after the program you selected. Option-
ally, you can rename the task. This dialog box is also where you
select the frequency to perform the task. Select Daily and click Next.
You should now see a dialog box resembling this one:
Chapter 6 File Endpoints 131
6. Enter the time and date to execute this task, and click Next. A new
dialog box will appear:
7. Enter the user name and password this task will run as, and click
Next. The following appears:
8. Check the check box for selecting advanced properties. You can
then set advanced properties such as command-line options on the
132 Part II Message Endpoints
9. Click Finish. Notice that the Title bar displays the name of the task.
The check box labeled Enabled allows you to turn this task on and off:
10. In the Run text box, add a space and then add www.microsoft.com
after the .exe file. This will send the browser to this URL upon launching.
11. Click the Settings tab. You should see something similar to the following: