This documentation is archived and is not being maintained.

ServiceHostFactory.CreateServiceHost Method (String, Uri[])

Creates a ServiceHost with specific base addresses and initializes it with specified data.

Namespace: System.ServiceModel.Activation
Assembly: System.ServiceModel (in system.servicemodel.dll)

public override ServiceHostBase CreateServiceHost (
	string constructorString,
	Uri[] baseAddresses
public ServiceHostBase CreateServiceHost (
	String constructorString, 
	Uri[] baseAddresses
public override function CreateServiceHost (
	constructorString : String, 
	baseAddresses : Uri[]
) : ServiceHostBase
Not applicable.



The initialization data passed to the ServiceHostBase instance being constructed by the factory.


The Array of type Uri that contains the base addresses for the service hosted.

Return Value

A ServiceHost with specific base addresses.

Exception typeCondition


baseAddress is a null reference (Nothing in Visual Basic).


There is no hosting context provided or constructorString is a null reference (Nothing in Visual Basic) or empty.

This example shows how to use the CreateServiceHost(String,Uri[]) method:

public override ServiceHostBase CreateServiceHost
        (string service, Uri[] baseAddresses)


    // The service parameter is ignored here because we know our service.
    ServiceHost serviceHost = new ServiceHost(typeof(HelloService),
    return serviceHost;


Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0