ServiceDescription.GetService Method (Object)

Returns a service description initialized with a specified service object.

Namespace:  System.ServiceModel.Description
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public static ServiceDescription GetService(
	Object serviceImplementation
)

Parameters

serviceImplementation
Type: System.Object

The Object that implements the service.

Return Value

Type: System.ServiceModel.Description.ServiceDescription
The ServiceDescription for the service object provided.

ExceptionCondition
ArgumentNullException

serviceImplementation is null.

Use this method to reflect on behaviors using the Windows Communication Foundation (WCF) programming model when replacing ServiceHostBase with you own hosting mechanism.

GetService(Object) initializes the Name, Namespace, and ConfigurationName properties, and ensures that the ServiceBehaviorAttribute is attached to the service and adds any relevant service behaviors to Behaviors.

The following sample shows how to iterate through the service behaviors contained in the service description.

// Instantiate a service description specifying a service object 
// Note: Endpoints collection and other properties will be null since  
// we have not specified them
CalculatorService svcObj = new CalculatorService();
ServiceDescription sd3 = ServiceDescription.GetService(svcObj);
String serviceName = sd3.Name;
Console.WriteLine("Service name: {0}", serviceName);

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5, 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft