• Feeds

    Subscribe in a reader

  • Ads

ServiceHostFactory vs ServiceHostFactoryBase

Last time around I talked about how the ServiceHostFactory API allows you to use custom derivatives of System.ServiceModel.ServiceHost with the WCF hosting infrastructure that runs in IIS/WAS.

If you've been poking around the System.ServiceModel.Activation OM, you might have noticed that we actually have two service-host-factory-ish classes. Specifically, we have System.ServiceModel.Activation.ServiceHostFactory (which was that subject of my last post), as well as its more mysterious abstract base class System.ServiceModel.Activation.ServiceHostFactoryBase (which has yet to be mentioned at all).

You might have also noticed that the ServiceHost API follows a parallel class structure -- we have System.ServiceModel.ServiceHost that derives from the abstract System.ServiceModel.ServiceHostBase parent class. The similarity in names between ServiceHostBase and ServiceHostFactoryBase is intentional.

The model is that you derive from ServiceHostFactoryBase directly if you're trying to use a custom host that derives directly from ServiceHostBase. If your custom service host instead derives from ServiceHost, you write a factory that derives from ServiceHostFactory.

The spit between ServiceHost and ServiceHostBase is somewhat beyond the scope of this post, although I will say that you can think of ServiceHostBase as an abstract version of ServiceHost that has all the major pieces defined on it but the logic for constructing those pieces is intended to be supplied by derivative classes (i.e. ServiceHostBase builds its runtime via a GOF TemplateMethod pattern). For example, ServiceHostBase has a ServiceDescription, but the logic for building that description is left undefined. This allows something like ServiceHost to come along and implement logic that builds a ServiceDescription by reflecting over a CLR type looking for [ServiceContract]/[OperationContract] attirbutes. People who want to build other programming models on top of our core runtime functionality can implement different ways of building a ServiceDescription based on whatever metadata store they want. This feature is very handy for people who are building more dynamic programming models that aren't completely centered around modeling services as CLR types that wear special metadata.

Deriving your own ServiceHostBase is a pretty advanced scenario and we expect that the number of people who do this on a regular basis will be relatively small. But it's one of those things where it's nice to know that the possibility exists even if you don't use it on a regular basis.

Since the major purpose of ServiceHostBase is to decouple the runtime from CLR types as the metadata source for telling us how to construct that runtime, it follows that the API for ServiceHostFactoryBase would not be defined in terms of System.Type. And, if you look at the API projection of ServiceHostFactoryBase you'll see that it's not:

namespace System.ServiceModel.Activation
{
   public abstract class ServiceHostFactoryBase
   {
      public abstract ServiceHostBase CreateServiceHost( string constructorString,
                                                         Uri[] baseAddresses );
 
   }
}

ServiceHostFactoryBase takes two parameters:

  • string constructorString, which is an opaque string that provides initialization data to the Factory/Host. The semantics of constructorString are similar in spirit to the IObjectConstruct pattern from COM+.
  • Uri[] baseAddresses. These URI's are provided by the hosting environment (IIS/WAS/ASP.NET) based on the hosting application's configuration. When WCF is hosted in IIS, the base addresses of the services we host there are constrained by the hosting environment. Those base addresses get passed from the hosting environment to the service via this Uri[].

The contents of constructorString are provided via the Service attribute in the .svc file. There are no restrictions on the contents or format of this string -- it's up to the individual factory implementation to define the semantics of this string as it relates to that specific Factory/Host implementation. For example, ServiceHostFactory (the default) treats this string as the CLR type name of the service implementation type. Here's a simplified implementation of the logic in SerivceHostFactory that illustrates how this ties together:

namespace System.ServiceModel.Activation
{
   public class ServiceHostFactory : ServiceHostFactoryBase
   {
      public override sealed ServiceHostBase CreateServiceHost( string constructorString,
                                                                Uri[] baseAddresses )
      {

          Type serviceType = Type.GetType( constructorString );
          return CreateServiceHost( serviceType, baseAddresses );
   
      }

      protected virtual ServiceHost CreateServiceHost( Type serviceType, Uri[] baseAddresses )
      {
          return new ServiceHost( serviceType, baseAddresses );
      }

   }
}

So in summary:

  • ServiceHostBase is a ServiceHost that doesn't depend on having a CLR type around in order to build a ServiceDescription.
  • ServiceHostFactoryBase creates ServiceHostBases from an opaque string passed in through the Service attribute in the @ServiceHost directive.
  • We ship a default factory called ServiceHostFactory that interprets the constructor string as a CLR type name and uses that to create new instances of ServiceHost.
  • If you want to use a different subtype of ServiceHost, write your own factory that derives from ServiceHostFactory.
  • If you want to interpret that contents of the Service directive as something other than a CLR type name, you can derive from ServiceHostFactoryBase and parse that string in whatever way you want.

The last bullet opens up some really interesting possibilities :)

#1 fdsaf on 5.20.2007 at 3:01 AM

[url=http://beseive.topcities.com/36528938.html]asp语音聊天室 下载[/url][url=http://beseive.topcities.com/liuyifeixinji.html]刘亦菲 心悸[/url][url=http://beseive.topcities.com/lijiachengshengri.html]李嘉诚生日[/url][url=http://beseive.topcities.com/qijiechuanqi.html]七界传奇[/url][url=http://beseive.topcities.com/36528938.html]asp语音聊天室 下载[/url][url=http://beseive.topcities.com/guaijijinzita.html]古埃及金字塔[/url][url=http://beseive.topcities.com/zhengtuzhuye.html]征途主页[/url][url=http://beseive.topcities.com/zhoujielundetupian.html]周杰伦的图片[/url][url=http://beseive.topcities.com/xiaonei.html]xiao nei[/url][url=http://beseive.topcities.com/cyuyanshiyongshouce.html]c语言使用手册[/url][url=http://beseive.topcities.com/bentianqicheguanggao.html]本田汽车广告[/url][url=http://beseive.topcities.com/xiaoqiongdeboke.html]肖琼的博客[/url][url=http://beseive.topcities.com/65117124.html]蒸汽幻想 利厄兰多[/url][url=http://beseive.topcities.com/houmatieba.html]侯马贴吧[/url][url=http://beseive.topcities.com/aduodexiong.html]阿朵的胸[/url][url=http://beseive.topcities.com/yumaoqiubisaiguize.html]羽毛球比赛规则[/url][url=http://beseive.topcities.com/27243660.html]圣斗士星矢银河篇[/url][url=http://beseive.topcities.com/cunaizibing.html]濮存昕 艾滋病[/url][url=http://beseive.topcities.com/peiyongjunzuixinxiaoxi.html]裴勇俊最新消息[/url][url=http://beseive.topcities.com/qiruiqqguzhang.html]奇瑞qq故障[/url][url=http://beseive.topcities.com/caoyangnianhuanvshengban.html]草样年华女生版[/url][url=http://beseive.topcities.com/hunanaiguozhemp3zhuanmai.html]湖南爱国者mp3专卖[/url][url=http://beseive.topcities.com/haimingweidegerenboke.html]海鸣威的个人博客[/url][url=http://beseive.topcities.com/wendaoba.html]问道吧[/url][url=http://beseive.topcities.com/rou.html]柔妃[/url][url=http://beseive.topcities.com/tianmoshentanmulu.html]天魔神谭目录[/url][url=http://beseive.topcities.com/psplongzhuz.html]psp龙珠z[/url][url=http://beseive.topcities.com/gaoda0083.html]高达0083[/url][url=http://beseive.topcities.com/xinxiao77luntan.html]新小77论坛[/url][url=http://beseive.topcities.com/qiruiqqlaogong.html]奇瑞qq老公[/url][url=http://beseive.topcities.com/woweigekuangdonghuapian.html]我为歌狂动画片[/url][url=http://beseive.topcities.com/dahuaxiyou2shaofawaigua.html]大话西游2烧法外挂[/url][url=http://beseive.topcities.com/badalingsuidaoshiyitu.html]八达岭隧道示意图[/url][url=http://beseive.topcities.com/shuifeiteng.html]水沸腾[/url][url=http://beseive.topcities.com/jiaxianbaiyunshan.html]佳县白云山[/url][url=http://beseive.topcities.com/suzhoudaxuedangweishuji.html]苏州大学党委书记[/url][url=http://beseive.topcities.com/xianggangmingxingbaxinwen.html]香港明星八卦新闻[/url][url=http://beseive.topcities.com/liudehuajiehun.html]刘德华结婚[/url][url=http://beseive.topcities.com/chaojijieba94zhucema.html]超级解霸94注册码[/url][url=http://beseive.topcities.com/94546704.html]魔界传说私服登录器[/url][url=http://beseive.topcities.com/31164426.html]大熊猫团团圆圆[/url][url=http://beseive.topcities.com/chenguanxiqq.html]陈冠希qq[/url][url=http://beseive.topcities.com/jietoulanqiudianka.html]街头篮球点卡[/url][url=http://beseive.topcities.com/haerbinfangwuchuzu.html]哈尔滨房屋出租[/url]

#2 fdsaf on 5.20.2007 at 3:34 AM

[url=http://beseive.topcities.com/liuyifeixinji.html]刘亦菲 心悸[/url][url=http://beseive.topcities.com/caidelianggeren.html]蔡妍的两个人[/url][url=http://beseive.topcities.com/yangzhoujiaoyouwang.html]扬州交友网[/url][url=http://beseive.topcities.com/zhengfaxiefeng.html]蒸发谢霆锋[/url][url=http://beseive.topcities.com/liyuchunhehejie.html]李宇春和何洁[/url][url=http://beseive.topcities.com/zhejianggongshangdaxue.html]浙江工商大学[/url][url=http://beseive.topcities.com/kugelameiliangxianghao.html]酷哥辣妹两相好[/url][url=http://beseive.topcities.com/siqiudehui.html]死囚的忏悔[/url][url=http://beseive.topcities.com/yaomingjiguan.html]姚明 籍贯[/url][url=http://beseive.topcities.com/mayaa6.html]玛雅a6[/url][url=http://beseive.topcities.com/wuyanzudenvpengyou.html]吴彦祖的女朋友[/url][url=http://beseive.topcities.com/mp3lianchangbofangqi.html]mp3连唱播放器[/url][url=http://beseive.topcities.com/qqkongjianzhanghanyun.html]qq空间张含韵[/url][url=http://beseive.topcities.com/rexuechuanqiwangzhan.html]热血传奇网站[/url][url=http://beseive.topcities.com/shouhuifengjing.html]手绘风景[/url][url=http://beseive.topcities.com/chulianpeiyongjun.html]初恋 裴勇俊[/url][url=http://beseive.topcities.com/langtutengzaixian.html]狼图腾 在线[/url][url=http://beseive.topcities.com/gaoerfujulebu.html]高尔夫俱乐部[/url][url=http://beseive.topcities.com/mp3jianji.html]mp3剪辑[/url][url=http://beseive.topcities.com/06218598.html]数码相机美能达minoltatz1[/url][url=http://beseive.topcities.com/zhengzhoujiaoyouxinxi.html]郑州交友信息[/url][url=http://beseive.topcities.com/huashi.html]画室[/url][url=http://beseive.topcities.com/fushidanfanxiangji.html]富士单反相机[/url][url=http://beseive.topcities.com/wodefengliurenshen.html]我的风流人身[/url][url=http://beseive.topcities.com/jianxia2jingling.html]剑侠2精灵[/url][url=http://beseive.topcities.com/jinyongyunuzhe.html]金庸驭奴者[/url][url=http://beseive.topcities.com/diannaoqidongguocheng.html]电脑启动过程[/url][url=http://beseive.topcities.com/sifuxiaobingchuanqi.html]私服小兵传奇[/url][url=http://beseive.topcities.com/qingaiyisheng.html]情爱一生[/url][url=http://beseive.topcities.com/yijianlian.html]易建联[/url][url=http://beseive.topcities.com/nikangshumaxiangjis5.html]尼康数码相机s5[/url][url=http://beseive.topcities.com/yiyeqingjiaoyou.html]一夜 情交友[/url][url=http://beseive.topcities.com/yuanxingshancun.html]源兴闪存[/url][url=http://beseive.topcities.com/ruheshenqingmsn.html]如何申请msn[/url][url=http://beseive.topcities.com/juhuaxiangmp3.html]菊花香mp3[/url][url=http://beseive.topcities.com/wushuxueyuan.html]武术学院[/url][url=http://beseive.topcities.com/chenxiaochunguhuozitupian.html]陈小春古惑仔图片[/url][url=http://beseive.topcities.com/zhejiangtianqiyubao.html]浙江天气预报[/url][url=http://beseive.topcities.com/shanpanguanggao.html]闪盘广告[/url][url=http://beseive.topcities.com/33677603.html]找龙与地下城:龙晶[/url][url=http://beseive.topcities.com/qijiechuanqi.html]七界传奇[/url][url=http://beseive.topcities.com/balishengmuyuantu.html]巴黎圣母院图[/url][url=http://beseive.topcities.com/guizhoujiaoyouzhongxin.html]贵州交友中心[/url][url=http://beseive.topcities.com/quanyechamanhuadajieju.html]犬夜叉漫画大结局[/url][url=http://beseive.topcities.com/shumajiguangchongyin.html]数码激光冲印[/url][url=http://beseive.topcities.com/meideyinle.html]暧昧的音乐[/url][url=http://beseive.topcities.com/zhaopianhechengruanjian.html]照片合成软件[/url][url=http://beseive.topcities.com/haiyanggongyuanxianlu.html]海洋公园线路[/url][url=http://beseive.topcities.com/shimerenzuipaxizao.html]什么人最怕洗澡[/url][url=http://beseive.topcities.com/hanmah2jiage.html]悍马h2价格[/url][url=http://beseive.topcities.com/44452348.html]梦想中国海明威照片[/url][url=http://beseive.topcities.com/liyapengzhouxun.html]李亚鹏周迅[/url][url=http://beseive.topcities.com/shanghaitaipingyangshuma.html]上海太平洋数码[/url][url=http://beseive.topcities.com/taiyangnengeva.html]太阳能eva[/url][url=http://beseive.topcities.com/emulezhongwenban.html]emule中文版[/url][url=http://beseive.topcities.com/nbalive2007.html]nba live 2007[/url][url=http://beseive.topcities.com/haerbinyemu.html]哈尔滨夜幕[/url][url=http://beseive.topcities.com/zhouyumindexiaoxi.html]周渝民的消息[/url][url=http://beseive.topcities.com/rongjiejietiaowuji.html]芙

#3 dfsaf on 6.24.2007 at 9:52 PM

beseive.topcities.com/yangzhoufangwuchuzu.html