Upload
brian-ritchie
View
4.560
Download
1
Tags:
Embed Size (px)
DESCRIPTION
Simplify your enterprise by standardizing on the IIS application server for both Web & Windows Services. Learn more about the IIS hosting model & how to take advantage of the new Always-On service capabilities.Given at JAXDUG on 10/5/2011.http://www.jaxdug.com/
Citation preview
Hosting Windows Services in IIS
Brian RitchieChief ArchitectPayformance Corporation
Email: [email protected]: http://weblog.asp.net/britchieWeb: http://www.dotnetpowered.com
Take advantage of the IIS platform for hosting your Always-On services.
Who am I?
» Chief Architect at Payformance Corporation» Nearly 20 years of development experience» Developing on .NET since 1.0 Beta 1» Contributed to Mono and other
open source projects
Brian Ritchie
Why build Windows Services?
» When you need always-on functionality
» Examples:˃ File Watching & Processing
˃ Scheduled tasks
˃ Long-running tasks
˃ Queued processing
Windows Services have been around forever, why
change now?
Why build Windows Services?
Sometimes change is good
Reasons for change
» Windows Services have no User Interface
making them hard to monitor, manage, and
debug.
» Windows Services are harder to deploy & can’t
use Web Deploy.
Who can save us from these problems?
I’m IIS & I’m here to help!
Did you say IIS?
» More than just a web server, IIS is an application server platform.˃ Web Applications: ASP.NET, PHP, and more˃ Web Services: ASMX, WCF˃ Multiple Protocols: HTTP, HTTPS, TCP, Named PipesAnd now…˃ Always-On Services: Auto-start & Always Running
What makes IIS better?
Single hosting framework for all application components. Web sites, services, and long running services can be hosted using the same framework & management tools.
Improved deployment capabilities. XCOPY deployment is now possible or use the new Web Deploy functionality. Web Deploy is enough of a reason by itself!
Provide self-hosted management or monitoring web pages. You can easily add web pages to services to provide status on their work load.
Utilize IIS automatic management features. Optionally configure your service to recycle on a given interval or based on memory usage, just like any other IIS hosted service.
IIS7: Your Single Hosting Framework
IIS7
Windows Activation Service (WAS)
Protocol Adapters
WWW Service(W3WC)
HTTP
HTTPS
NET PIPE
TCP
App Pools
Worker Process (W3WP)
ASP.NET
ASP
PHP
WCF
Always-On
Management Service
Admin Service
Monitoring via the IIS Manager
» Since all services will be hosted under the w3wp.exe process name, you can see the Worker Process associated with your application pool within the IIS manager:
Monitoring via Process Explorer
» Another approach is to use the SysInternals Process Explorer free from Microsoft. Add the “Command Line” column to the grid, and the application pool name will be listed after the –ap switch.
Deployments…made easy
Build/Deploy Server
Deploy
IISServer
IIS MMC – Import Application
Package
Build Server(using MSBuild)
DeploymentPackage
IIS MMC – Export Application
» Web Deploy 2.1
Look Mom…I have a UI now!
» No longer “invisible”, your service can publish its own monitoring & management capability
OK…I’m sold!
How can I take this beauty home today?
Getting Started
» First off…Install the pre-reqs:˃ IIS 7.5 (Windows 2008 R2 or Windows 7)˃ Windows Server AppFabric˃ .NET Framework 4.0
» Next…Configure IIS:˃ Set Application Pool to “Always Running”˃ Configure Site with Net.Pipe Binding˃ Set Application to “Auto Start”
Walk Thru: Configuring IIS
Building a service
Building a service
» What are some fundamental differences between a standard Web Service and a Windows Service?A. Request-Response vs. Event-based B. State-less vs. State-fullC. Transparent threading vs. Thread ManagementD. DLL vs. EXEE. All of the Above
Building a Service:Differences in Process
Models
» Windows Service Process Model Service
(EXE)Service
ControllerMMC
Building a Service:Differences in Process
Models
» Windows Service Process Model
» IIS Worker Process Model
Service(EXE)
Service Controller
W3WP
WWW Publishing
Service
svchost.exe -k iissvcs
MMC
IIS Manager
AppDomain
AppDomain
Service(DLL)
Building a service
» Where does the service perform it’s startup?A. Application_Start in Global.asaxB. AppInitialize in AppStart.csC. AppStartup in the session controller
Building a service
» What is the scope of a static variables?A. ClassB. ThreadC. AppDomainD. ProcessE. Machine
Visualizing the stack
Machine
Process
AppDomain
Thre
ad
Thre
ad
StaticScope
Your service runs here
Either you manage threads directly or use a Thread Pool or TPL
Walk Thru: Building a service
Thanks for coming!» Twitter: @brian_ritchie» Blog: http://weblogs.asp.net/britchie