BizTalk Utilities CV ,   Jobs ,   Code library
Go to the front page to continue learning about XML or select below:


ReBlogger Contents

Previous posts in WSCF/WCF

Page 12386 of 21350

Start ServiceHosts for all configured Services

Blogger : Thinktecture Blog
All posts : All posts by Thinktecture Blog
Category : WSCF/WCF
Blogged date : 2006 Sep 05

As WCF has reached RC1 stage, I find myself cleaning up a few bits of older WCF code. While playing around with it, I always found myself having to start more and more ServiceHosts for different configurations. The following snippet iterates over all <service> entries in configuration/system.serviceModel and opens a ServiceHost for each of them.

using System;
using System.Collections.Generic;
using System.Reflection;
using System.Configuration;
using System.ServiceModel.Configuration;
using System.ServiceModel;

public class ServiceHostGroup
    static List<ServiceHost> _hosts = new List<ServiceHost>();

    private static void OpenHost(Type t)
        ServiceHost hst = new ServiceHost(t);

    public static void StartAllConfiguredServices()
        Configuration conf =

        ServiceModelSectionGroup svcmod =
        foreach (ServiceElement el in svcmod.Services.Services)
            Type svcType = Type.GetType(el.Name);
            if (svcType == null)
              throw new Exception("Invalid Service Type " + el.Name + " in configuration file.");


Read comments or post a reply to : Start ServiceHosts for all configured Services
Page 12386 of 21350

Newest posts

    Email TopXML