Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

ServiceHost Constructor (Object, Uri[])

Initializes a new instance of the ServiceHost class with the instance of the service and its base addresses specified.

Namespace:  System.ServiceModel
Assembly:  System.ServiceModel (in System.ServiceModel.dll)
public ServiceHost(
	Object singletonInstance,
	params Uri[] baseAddresses
)

Parameters

singletonInstance
Type: System.Object

The instance of the hosted service.

baseAddresses
Type: System.Uri[]

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

ExceptionCondition
ArgumentNullException

singletonInstance is null.

Use this constructor as an alternative to implementing a custom System.ServiceModel.Dispatcher.IInstanceContextInitializer when you want to provide a specific object instance for use by a singleton service. You may want to use this overload when your service implementation type is difficult to construct (for example, if it does not implement a default public constructor that has no parameters).

Note that when an object is provided to this overload, some features related to the Windows Communication Foundation (WCF) instancing behavior work differently. For example, calling InstanceContext.ReleaseServiceInstance have no effect when a well-known object instance is provided using this constructor overload. Similarly, any other instance release mechanism is ignored. The ServiceHost always behaves as if the OperationBehaviorAttribute.ReleaseInstanceMode property is set to ReleaseInstanceMode.None for all operations.

CalculatorService service = new CalculatorService();
ServiceHost serviceHost = new ServiceHost(service, baseAddress);

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.