Download presentation
Presentation is loading. Please wait.
Published byClinton Copeland Modified over 9 years ago
1
1 IIS and Windows Communication Foundation: Hosting Services Steve Maine COM 413 Program Manager Microsoft Corporation smaine@microsoft.com http://hyperthink.net/blog
2
2 ServiceHost ServiceHost host = new ServiceHost( typeof( MyService ) ); host.AddEndpoint( typeof( IService ), someBinding, someBinding, someUri ); someUri );host.Open();
3
3 Hosting Environment Basic features Process and AppDomain Configuration Default security context Sophisticated features Process recycling, auto-restart GUI management
4
4 Why You Care About Hosting Non-functional requirements AvailabilityReliabilityManageability Deployment model Choose the host that meets your needs WCF programming model won’t change
5
5 WCF Hosting Options Self-hosting Any managed application Managed Windows Services All WCF platforms IIS 5.1 and 6.0 Windows XP and Windows Server 2003 Windows Activation Service (WAS) Windows Vista / “Longhorn” Server
6
6 Self-hosting
7
7 Self-hosting Requires only WinFX Most flexible, fewest hosting features Common scenario: Connected rich client ServiceHost host = new ServiceHost( typeof( MyService ) ); host.AddEndpoint( typeof( IService ), someBinding, someBinding, someUri ); someUri );host.Open();
8
8 Managed Windows Services
9
9 Self-host API’s + System.ServiceProcess using System.ServiceModel; using System.ServiceProcess; public class MyWindowsService : ServiceBase { ServiceHost serviceHost; ServiceHost serviceHost; public override void OnStart( string[] args ) public override void OnStart( string[] args ) { this.serviceHost = new ServiceHost( typeof( T ) ); this.serviceHost = new ServiceHost( typeof( T ) ); this.serviceHost.AddEndpoint( … ); this.serviceHost.AddEndpoint( … ); this.serviceHost.Open(); } this.serviceHost.Open(); } public override void OnStop() { public override void OnStop() { this.serviceHost.Close(); } this.serviceHost.Close(); }}
10
10 Managed Windows Services Process lifetime controlled by OS Start/Stop on SCM command Managed via SCM tools
11
11 Hosting In Windows Services
12
12 When To Host In Windows Services Service lifetime controlled by OS Need to run as a distinct service identity Alternative to IIS
13
13 IIS 5.1 And 6.0
14
14 What IIS Provides Address Model Sites, Applications, Virtual Directories Process Model Application is AppDomain boundary AppPool is process boundary Health monitoring and recycling Activation On-demand service activation via HTTP
15
15 WCF Services In IIS “.svc” files Code inline or in App_Code Configuration in web.config
16
16 Code-behind.svc Files <% @Service language=“CS” Class=“MyService” CodeBehind=“~/App_Code/MyService.cs” %> CodeBehind=“~/App_Code/MyService.cs” %> <endpoint address=“” <endpoint address=“” binding=“basicHttpBinding” contract=“MyContract” > binding=“basicHttpBinding” contract=“MyContract” >
17
17 using System.ServiceModel; [ServiceContract] public class MyService { [OperationContract] [OperationContract] public string Echo( string message ){ … } } public string Echo( string message ){ … } } Code-inline.svc Files Configuration in web.config Changes to service implementation compiled dynamically
18
18 using System.ServiceModel; public class CustomHost : ServiceHost { public CustomHost : base( typeof( MyService ) ) {} public CustomHost : base( typeof( MyService ) ) {} public override void OnInitialize() public override void OnInitialize() { this.OnOpen += OnOpenHandler; this.OnOpen += OnOpenHandler; this.OnClose += OnCloseHandler; } } this.OnClose += OnCloseHandler; } } ServiceHost In.svc Files
19
19 WAS And IIS 7.0
20
20 IIS 5 HTTP Listener Process / Config Manager w3svc Worker(AppDomain) Worker(AppDomain) Worker(AppDomain) ASPNET_ISAPI.dll aspnet_wp.exe
21
21 IIS 6 HTTP Listener Adapter Process / Config Manager W3SVC Worker(AppDomain) Worker(AppDomain) Worker(AppDomain) ASPNET_ISAPI.dll AppPools (w3wp.exe) HTTP.SYS User Mode Kernel Mode Worker(AppDomain) Worker(AppDomain) Worker(AppDomain) ASPNET_ISAPI.dll Worker(AppDomain) Worker(AppDomain) Worker(AppDomain) ASPNET_ISAPI.dll
22
22 IIS 7 And WAS Process Manager Configuration WAS AppPools (w3wp.exe) http net.tcp net.pipe net.msmq Protocol-specific Listener Adapters w3svcitcppss inpas imsmqas Worker(AppDomain) Worker(AppDomain) Worker(AppDomain) Process Host Worker(AppDomain) Worker(AppDomain) Worker(AppDomain) Worker(AppDomain) Worker(AppDomain) Worker(AppDomain)
23
23 WAS Activation WAS Config App Pool App
24
24 WAS Activation WAS Config App Pool App Listener Adapter Config
25
25 WAS Activation WAS Config App Pool App Listener Adapter Activate
26
26 WAS Activation WAS Config Worker Process AppDomain Listener Adapter
27
27 New Architectural Pieces Windows Activation Service (WAS) Listener Adapters Protocol Handlers
28
28 WAS In Depth
29
29 WCF Activation Architecture Process Manager Configuration Request WAS Response AppPools (w3wp.exe) http net.tcp net.pipe net.msmq Protocol-specific Listener Adapters w3svcitcppss inpas imsmqas Worker(AppDomain) Worker(AppDomain) Worker(AppDomain) Process Host Worker(AppDomain) Worker(AppDomain) Worker(AppDomain) Worker(AppDomain) Worker(AppDomain) Worker(AppDomain)
30
30 Summary Self-hosting Managed NT Services IIS 5.1 and 6.0 WAS and IIS 7.0
31
31 Community Resources After PDC MSDN dev center: http://msdn.microsoft.com/webservices/ http://msdn.microsoft.com/webservices/ MSDN Forums Windows Communication Foundation (“Indigo”) Windows Communication Foundation (“Indigo”)Windows Communication Foundation (“Indigo”)Windows Communication Foundation (“Indigo”) Channel 9 tag: http://channel9.msdn.com/tags/Indigo http://channel9.msdn.com/tags/Indigo http://hyperthink.net/blog
32
32 © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. Thanks for coming to PDC!
33
33 Listener Adapter Internals Network Interface WAS Interface DispatchTable Listener Channels Network Traffic Configuration + Control ApplicationMessages
34
34 Worker Process Internals w3wp.exe (AppPool) Default AppDomain WAS Interface Process Host net.tcp PPH AppManager User AppDomain Application Code net.tcp ADPH User AppDomain Application Code net.tcp ADPH User AppDomain Application Code net.tcp ADPH User AppDomain Application Code net.tcp ADPH
35
35 User AppDomain Default AppDomain Service Startup w3wp.exe (Default AppPool) net.tcp ADPH Hosting Manager Application Manager EnsureServiceAvailable() Service ListenerFactory ChannelFactory new ServiceHost( … ) serviceHost.Open()
36
36 EnsureServiceAvailable() 1) /app/Service.svc - > class MyService {…} class MyService {…} BuildProvider + = Compiled Type T 2) 3) ServiceHost host = new ServiceHost( T, baseAddresses ); host.Open(); AddToCache( host );
37
37 int main(void) int main(void) { int sockfd, new_fd; // listen on sock_fd, new connection on new_fd int sockfd, new_fd; // listen on sock_fd, new connection on new_fd struct sockaddr_in my_addr; // my address information struct sockaddr_in my_addr; // my address information struct sockaddr_in their_addr; // connector's address information struct sockaddr_in their_addr; // connector's address information int sin_size; int sin_size; struct sigaction sa; struct sigaction sa; /* Create socket */ /* Create socket */ sockfd = socket(AF_INET, SOCK_STREAM, 0); sockfd = socket(AF_INET, SOCK_STREAM, 0); initAddr(&my_addr); initAddr(&my_addr); bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr); bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr); /* Listen for incoming connections */ /* Listen for incoming connections */ listen(sockfd, BACKLOG); listen(sockfd, BACKLOG); while(1) { while(1) { sin_size = sizeof(struct sockaddr_in); sin_size = sizeof(struct sockaddr_in); new_fd = accept(sockfd, (struct sockaddr *)&their_addr, new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size) &sin_size) /* Dispatch connection to worker */ /* Dispatch connection to worker */ if (!fork()) { if (!fork()) { doWork( new_fd ); doWork( new_fd ); } close(new_fd); close(new_fd); } return 0; return 0; }
38
38 Simple Socket Server ListenerSocket.Accept() DispatcherQueueUserWorkItem() Worker(Thread) Worker(Thread) Worker(Thread) Worker(Thread) Worker(Thread) Worker(Thread) Worker(Thread) Request server.exe Response
39
39 Opening Sockets applictionHost.config WAS net.tcp Listener SiteId: /w3svc/1 Binding: *:2323 SiteId: /w3svc/2 Binding: *:8888 RegisterProtocol( “net.tcp”, pfnCallbacks ) foreach( SiteBinding b in returnedBindings ) { CreateSocket( b ); } CreateSocket( b ); }
40
40 Populating The Dispatch Table applictionHost.config WAS net.tcp Listener SiteId: /w3svc/1 AppPool: Default AppId: 1 Path: /Finance ListenerChannelId: 1 SiteId: /w3svc/2 AppPool: Default AppId: 2 Path: /HR ListenerChannelId: 2 OnApplicationCreated() net.tcp://*:2323/Finance -> (1) Default::App1 net.tcp://*:8888/HR -> (2) Default::App2
41
41 Address Lookup Network Interface DispatchTable Request arrives Address Lookup Worker Process + AppDomain Determined Protocol Listener
42
42 Longest-Prefix Matching net.tcp://*:2323/Finance net.tcp://*:2323/Finance/Payroll net.tcp://*:8888/HR net.tcp://host1:2323/Finance/Payable net.tcp://host1:2323/Payroll/History net.tcp://host2:2323/Finance/Receivable net.tcp://machine:8888/HR/Reviews
43
43 Dispatch Table Details //Pseudocode UriPrefixTable dispatchTable; internal class ListenerChannel { //WAS knows about this ID too //WAS knows about this ID too string listenerChannelId; string listenerChannelId; //Pulled from applicationHost.config, used for housekeeping //Pulled from applicationHost.config, used for housekeeping string SiteId; string SiteId; string AppPoolId; string AppPoolId; string AppId; string AppId; //Some information about the worker process //Some information about the worker process //associated with this Listener Channel //associated with this Listener Channel WorkerProcess wp; WorkerProcess wp; //Messages waiting to be picked up by the worker //Messages waiting to be picked up by the worker RequestQueue pendingMessages; RequestQueue pendingMessages;}
44
44 “I have” “I want” Request Queues
45
45 Standard Transports ListenerFactory ChannelFactory Service ListenerFactory ChannelFactory Service ListenerFactory ChannelFactory Service To Network User Code Per-Channel Infrastructure Network Infrastructure Socket/HandleSocket/HandleSocket/Handle
46
46 Hosted Transports AppDomain Protocol Handler ListenerFactory ChannelFactory Service ListenerFactory ChannelFactory Service ListenerFactory ChannelFactory Service To Protocol Listener User Code Channel Infrastructure Network Infrastructure
47
47 TCP ADPH Listener Worker Listener Channel Raw Data (NT Named Pipe) Control (WCF Duplex over Named Pipe) itcppss w3wp.exe
48
48 TCP ADPH Listener Worker Listener Channel Raw Data (NT Named Pipe) Control (WCF Duplex over Named Pipe) itcppss w3wp.exe
49
49 WCF Activation Architecture Activator/ Dispatcher Request WAS Response Worker(AppDomain) Worker(AppDomain) Worker(AppDomain) ASPNET_ISAPI.dll AppPools (w3wp.exe) Worker(AppDomain) Worker(AppDomain) Worker(AppDomain) ASPNET_ISAPI.dll Worker(AppDomain) Worker(AppDomain) Worker(AppDomain) ASPNET_ISAPI.dll http net.tcp net.pipe net.msmq Protocol-specific Listeners w3svcitcppss inpas imsmqas
50
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.