ServiceHostFactory.CreateServiceHost Method

Definition

Creates a ServiceHost.

Overloads

CreateServiceHost(String, Uri[])

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

CreateServiceHost(Type, Uri[])

Creates a ServiceHost for a specified type of service with a specific base address.

CreateServiceHost(String, Uri[])

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

C#
public override System.ServiceModel.ServiceHostBase CreateServiceHost(string constructorString, Uri[] baseAddresses);

Parameters

constructorString
String

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

baseAddresses
Uri[]

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

Returns

A ServiceHost with specific base addresses.

Exceptions

baseAddress is null.

There is no hosting context provided or constructorString is null or empty.

Examples

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

C#
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),
        baseAddresses);
    return serviceHost;
}

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

CreateServiceHost(Type, Uri[])

Creates a ServiceHost for a specified type of service with a specific base address.

C#
protected virtual System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses);

Parameters

serviceType
Type

Specifies the type of service to host.

baseAddresses
Uri[]

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

Returns

A ServiceHost for the type of service specified with a specific base address.

Examples

This example shows how to create an override implementation of the CreateServiceHost(Type, Uri[]) method:

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1