26
Hosting Windows Services in IIS Brian Ritchie Chief Architect Payformance Corporation Email: [email protected] Blog: http://weblog.asp.net/britchie Web: http://www.dotnetpowered.com Take advantage of the IIS platform for hosting your Always-On services.

IIS Always-On Services

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

Page 1: IIS Always-On Services

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.

Page 2: IIS 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

Page 3: IIS Always-On Services

Why build Windows Services?

» When you need always-on functionality

» Examples:˃ File Watching & Processing

˃ Scheduled tasks

˃ Long-running tasks

˃ Queued processing

Page 4: IIS Always-On Services

Windows Services have been around forever, why

change now?

Why build Windows Services?

Page 5: IIS Always-On Services

Sometimes change is good

Page 6: IIS Always-On Services

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.

Page 7: IIS Always-On Services

Who can save us from these problems?

I’m IIS & I’m here to help!

Page 8: IIS Always-On Services

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

Page 9: IIS Always-On Services

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.

Page 10: IIS Always-On Services

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

Page 11: IIS Always-On Services

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:

Page 12: IIS Always-On Services

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.

Page 13: IIS Always-On Services

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

Page 14: IIS Always-On Services

Look Mom…I have a UI now!

» No longer “invisible”, your service can publish its own monitoring & management capability

Page 15: IIS Always-On Services

OK…I’m sold!

How can I take this beauty home today?

Page 16: IIS Always-On Services

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”

Page 17: IIS Always-On Services

Walk Thru: Configuring IIS

Page 18: IIS Always-On Services

Building a service

Page 19: IIS Always-On Services

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

Page 20: IIS Always-On Services

Building a Service:Differences in Process

Models

» Windows Service Process Model Service

(EXE)Service

ControllerMMC

Page 21: IIS Always-On Services

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)

Page 22: IIS Always-On Services

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

Page 23: IIS Always-On Services

Building a service

» What is the scope of a static variables?A. ClassB. ThreadC. AppDomainD. ProcessE. Machine

Page 24: IIS Always-On Services

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

Page 25: IIS Always-On Services

Walk Thru: Building a service

Page 26: IIS Always-On Services

Thanks for coming!» Twitter: @brian_ritchie» Blog: http://weblogs.asp.net/britchie