11.07.2015 Views

y - Net Developer

y - Net Developer

y - Net Developer

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

amrameshreddy.blog.com152 CHAPTER 5 ■ HOSTING AND CONSUMING WCF SERVICESramrameshreddy.blog.comnamespace QuickReturns.StockTrading.ExchangeService.Hosts{public partial class ExchangeWindowsService : ServiceBase{ServiceHost host;}}public ExchangeWindowsService(){InitializeComponent();}protected override void OnStart(string[] args){Type serviceType = typeof(TradeService);host = new ServiceHost(serviceType);host.Open();}protected override void OnStop(){if(host != null)host.Close();}■Tip If you want to debug your start-up (or shutdown) code, just insert the following line in your code:System.Diagnostics.Debugger.Break(); (potentially surrounded by some logic to do this only in debugbuilds).So, writing a Windows service that hosts your WCF service is pretty easy and comes withseveral benefits when compared to the self-hosting scenario from earlier in this chapter. Onthe other hand, writing a Windows service that hosts your WCF service also comes with somedisadvantages that you need to understand.The following are the advantages:ramrameshreddyramrameshreddyAutomatic starting: The Windows Service Control Manager allows you to set the start-uptype to automatic so that as soon as Windows boots, the service will be started, without aninteractive login on the machine.Recovery: The Windows Service Control Manager has built-in support to restart serviceswhen failures occur.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!