11.07.2015 Views

y - Net Developer

y - Net Developer

y - Net Developer

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

amrameshreddy.blog.com162 CHAPTER 5 ■ HOSTING AND CONSUMING WCF SERVICESramrameshreddy.blog.comTo support custom ServiceHost activation, you should implement your own Factory thatinherits from ServiceHostFactory, which is a factory class that can instantiate your customhost. That class is provided in order to hook up the events for ServiceHost; you can use thisclass and put the type as the Factory attribute in the .svc file, as shown in Listing 5-6. By overridingthe CreateServiceHost method of the ServiceHostFactory class, you can performsimilar tasks as you do in self-hosting scenarios, as you learned in Chapter 3. This enables you,among other things, to abstract the logic to build up the description from the external configurationor create a more suitable base class for your base library, project, department, orcompany to use.Listing 5-7 shows the code of TradeServiceCustomHost and TradeServiceCustomHostFactorythat creates the host.Listing 5-6. .svc File with a CustomServiceHostFactoryListing 5-7. TradeServiceCustomHostFactory and TradeServiceCustomHostusing System;using System.ServiceModel;using System.ServiceModel.Activation;namespace QuickReturns.StockTrading.ExchangeService{public class TradeServiceCustomHostFactory : ServiceHostFactory{protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses){TradeServiceCustomHost customServiceHost =new TradeServiceCustomHost(serviceType, baseAddresses);return customServiceHost;}}public class TradeServiceCustomHost : ServiceHost{public TradeServiceCustomHost(Type serviceType, params Uri[] baseAddresses): base(serviceType, baseAddresses){}ramrameshreddyramrameshreddy

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

Saved successfully!

Ooh no, something went wrong!